BIGIP: fixes issue with image installation on multiblade platforms (#58176)
* fixes issue with image installation on multiblade platforms * test
This commit is contained in:
parent
30ada17d4f
commit
de03c007bc
2 changed files with 76 additions and 57 deletions
|
@ -111,6 +111,7 @@ file_size:
|
|||
import os
|
||||
import time
|
||||
|
||||
from ansible.module_utils.urls import urlparse
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
try:
|
||||
|
@ -214,6 +215,7 @@ class ModuleManager(object):
|
|||
self.have = ApiParameters()
|
||||
self.changes = UsableChanges()
|
||||
self.image_type = None
|
||||
self.image_url = None
|
||||
|
||||
def _set_changed_options(self):
|
||||
changed = {}
|
||||
|
@ -283,42 +285,56 @@ class ModuleManager(object):
|
|||
return True
|
||||
return False
|
||||
|
||||
def image_exists(self):
|
||||
result = False
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/image/{2}".format(
|
||||
def _set_image_url(self, item):
|
||||
path = urlparse(item['selfLink']).path
|
||||
self.image_url = "https://{0}:{1}{2}".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
path
|
||||
)
|
||||
|
||||
def image_exists(self):
|
||||
result = False
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/image/".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
self.want.filename
|
||||
)
|
||||
resp = self.client.api.get(uri)
|
||||
|
||||
try:
|
||||
response = resp.json()
|
||||
if resp.status == 404 or 'code' in response and response['code'] == 404:
|
||||
result = False
|
||||
else:
|
||||
self.image_type = 'release'
|
||||
result = True
|
||||
except ValueError:
|
||||
pass
|
||||
except ValueError as ex:
|
||||
raise F5ModuleError(str(ex))
|
||||
|
||||
if 'items' in response:
|
||||
for item in response['items']:
|
||||
if item['name'].startswith(self.want.filename):
|
||||
self._set_image_url(item)
|
||||
self.image_type = 'release'
|
||||
result = True
|
||||
break
|
||||
return result
|
||||
|
||||
def hotfix_exists(self):
|
||||
result = False
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/hotfix/{2}".format(
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/hotfix/".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
self.want.filename
|
||||
)
|
||||
resp = self.client.api.get(uri)
|
||||
|
||||
try:
|
||||
response = resp.json()
|
||||
if resp.status == 404 or 'code' in response and response['code'] == 404:
|
||||
result = False
|
||||
else:
|
||||
self.image_type = 'hotfix'
|
||||
result = True
|
||||
except ValueError:
|
||||
pass
|
||||
except ValueError as ex:
|
||||
raise F5ModuleError(str(ex))
|
||||
|
||||
if 'items' in response:
|
||||
for item in response['items']:
|
||||
if item['name'].startswith(self.want.filename):
|
||||
self._set_image_url(item)
|
||||
self.image_type = 'hotfix'
|
||||
result = True
|
||||
break
|
||||
return result
|
||||
|
||||
def update(self):
|
||||
|
@ -384,19 +400,7 @@ class ModuleManager(object):
|
|||
)
|
||||
|
||||
def read_current_from_device(self):
|
||||
if self.image_exists():
|
||||
return self.read_iso_from_device('image')
|
||||
elif self.hotfix_exists():
|
||||
return self.read_iso_from_device('hotfix')
|
||||
|
||||
def read_iso_from_device(self, type):
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/{2}/{3}".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
type,
|
||||
self.want.filename
|
||||
)
|
||||
resp = self.client.api.get(uri)
|
||||
resp = self.client.api.get(self.image_url)
|
||||
try:
|
||||
response = resp.json()
|
||||
except ValueError as ex:
|
||||
|
|
|
@ -75,6 +75,7 @@ RETURN = r'''
|
|||
import time
|
||||
import ssl
|
||||
|
||||
from ansible.module_utils.urls import urlparse
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
||||
try:
|
||||
|
@ -135,7 +136,7 @@ class ApiParameters(Parameters):
|
|||
return []
|
||||
if 'items' not in response:
|
||||
return []
|
||||
return [x['name'] for x in response['items']]
|
||||
return [x['name'].split('/')[0] for x in response['items']]
|
||||
|
||||
|
||||
class ModuleParameters(Parameters):
|
||||
|
@ -187,21 +188,22 @@ class ModuleParameters(Parameters):
|
|||
return None
|
||||
|
||||
def read_image_from_device(self, type):
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/{2}/{3}".format(
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/{2}/".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
type,
|
||||
self.image,
|
||||
)
|
||||
resp = self.client.api.get(uri)
|
||||
|
||||
try:
|
||||
response = resp.json()
|
||||
except ValueError:
|
||||
return None
|
||||
except ValueError as ex:
|
||||
raise F5ModuleError(str(ex))
|
||||
|
||||
if 'code' in response and response['code'] in [400, 404]:
|
||||
return None
|
||||
return response
|
||||
if 'items' in response:
|
||||
for item in response['items']:
|
||||
if item['name'].startswith(self.image):
|
||||
return item
|
||||
|
||||
|
||||
class Changes(Parameters):
|
||||
|
@ -253,6 +255,7 @@ class ModuleManager(object):
|
|||
self.want = ModuleParameters(params=self.module.params, client=self.client)
|
||||
self.have = ApiParameters(client=self.client)
|
||||
self.changes = UsableChanges()
|
||||
self.volume_url = None
|
||||
|
||||
def _set_changed_options(self):
|
||||
changed = {}
|
||||
|
@ -312,17 +315,38 @@ class ModuleManager(object):
|
|||
else:
|
||||
return self.update()
|
||||
|
||||
def exists(self):
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/volume/{2}".format(
|
||||
def _set_volume_url(self, item):
|
||||
path = urlparse(item['selfLink']).path
|
||||
self.volume_url = "https://{0}:{1}{2}".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
self.want.volume
|
||||
path
|
||||
)
|
||||
|
||||
def exists(self):
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/volume/".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port']
|
||||
)
|
||||
resp = self.client.api.get(uri)
|
||||
|
||||
try:
|
||||
collection = resp.json()
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
for item in collection['items']:
|
||||
if item['name'].startswith(self.want.volume):
|
||||
self._set_volume_url(item)
|
||||
break
|
||||
|
||||
resp = self.client.api.get(self.volume_url)
|
||||
|
||||
try:
|
||||
response = resp.json()
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
if resp.status == 404 or 'code' in response and response['code'] == 404:
|
||||
return False
|
||||
|
||||
|
@ -341,12 +365,8 @@ class ModuleManager(object):
|
|||
return False
|
||||
|
||||
def volume_exists(self):
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/volume/{2}".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
self.want.volume
|
||||
)
|
||||
resp = self.client.api.get(uri)
|
||||
resp = self.client.api.get(self.volume_url)
|
||||
|
||||
try:
|
||||
response = resp.json()
|
||||
except ValueError:
|
||||
|
@ -361,7 +381,7 @@ class ModuleManager(object):
|
|||
|
||||
if self.want.image and self.want.image not in self.have.image_names:
|
||||
raise F5ModuleError(
|
||||
"The specified image was not found on the device"
|
||||
"The specified image was not found on the device."
|
||||
)
|
||||
|
||||
options = list()
|
||||
|
@ -441,13 +461,8 @@ class ModuleManager(object):
|
|||
raise F5ModuleError
|
||||
|
||||
def read_volume_from_device(self):
|
||||
uri = "https://{0}:{1}/mgmt/tm/sys/software/volume/{2}".format(
|
||||
self.client.provider['server'],
|
||||
self.client.provider['server_port'],
|
||||
self.want.volume
|
||||
)
|
||||
try:
|
||||
resp = self.client.api.get(uri)
|
||||
resp = self.client.api.get(self.volume_url)
|
||||
response = resp.json()
|
||||
except ValueError as ex:
|
||||
raise F5ModuleError(str(ex))
|
||||
|
|
Loading…
Reference in a new issue