Update redfish module for compatibility with VirtualMedia resource location (#5124) (#5180)

* Update redfish module for compatibility with VirtualMedia resource location from Manager to Systems

* Add changelogs fragments for PR 5124

* Update some issue according to the suggestions

* update changelogs fragment to list new features in the minor_changes catagory

Co-authored-by: Tami YY3 Pan <panyy3@lenovo.com>
(cherry picked from commit 766c109d47)

Co-authored-by: jixj5 <66418293+jixj5@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2022-08-24 21:44:44 +02:00 committed by GitHub
parent b099a465c5
commit 3e4aae56bd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 93 additions and 18 deletions

View file

@ -202,6 +202,16 @@ class RedfishUtils(object):
def _init_session(self):
pass
def _get_vendor(self):
response = self.get_request(self.root_uri + self.service_root)
if response['ret'] is False:
return {'ret': False, 'Vendor': ''}
data = response['data']
if 'Vendor' in data:
return {'ret': True, 'Vendor': data["Vendor"]}
else:
return {'ret': True, 'Vendor': ''}
def _find_accountservice_resource(self):
response = self.get_request(self.root_uri + self.service_root)
if response['ret'] is False:
@ -2162,11 +2172,15 @@ class RedfishUtils(object):
result["entries"] = virtualmedia_results
return result
def get_multi_virtualmedia(self):
def get_multi_virtualmedia(self, resource_type='Manager'):
ret = True
entries = []
resource_uris = self.manager_uris
# Given resource_type, use the proper URI
if resource_type == 'Systems':
resource_uris = self.systems_uris
elif resource_type == 'Manager':
resource_uris = self.manager_uris
for resource_uri in resource_uris:
virtualmedia = self.get_virtualmedia(resource_uri)
@ -2178,7 +2192,7 @@ class RedfishUtils(object):
@staticmethod
def _find_empty_virt_media_slot(resources, media_types,
media_match_strict=True):
media_match_strict=True, vendor=''):
for uri, data in resources.items():
# check MediaTypes
if 'MediaTypes' in data and media_types:
@ -2187,8 +2201,12 @@ class RedfishUtils(object):
else:
if media_match_strict:
continue
# if ejected, 'Inserted' should be False
if (not data.get('Inserted', False)):
# Base on current Lenovo server capability, filter out slot RDOC1/2 and Remote1/2/3/4 which are not supported to Insert/Eject.
if vendor == 'Lenovo' and ('RDOC' in uri or 'Remote' in uri):
continue
# if ejected, 'Inserted' should be False and 'ImageName' cleared
if (not data.get('Inserted', False) and
not data.get('ImageName')):
return uri, data
return None, None
@ -2262,7 +2280,7 @@ class RedfishUtils(object):
return response
return {'ret': True, 'changed': True, 'msg': "VirtualMedia inserted"}
def virtual_media_insert(self, options):
def virtual_media_insert(self, options, resource_type='Manager'):
param_map = {
'Inserted': 'inserted',
'WriteProtected': 'write_protected',
@ -2279,7 +2297,12 @@ class RedfishUtils(object):
media_types = options.get('media_types')
# locate and read the VirtualMedia resources
response = self.get_request(self.root_uri + self.manager_uri)
# Given resource_type, use the proper URI
if resource_type == 'Systems':
resource_uri = self.systems_uri
elif resource_type == 'Manager':
resource_uri = self.manager_uri
response = self.get_request(self.root_uri + resource_uri)
if response['ret'] is False:
return response
data = response['data']
@ -2288,7 +2311,7 @@ class RedfishUtils(object):
# Some hardware (such as iLO 4) only supports the Image property on the PATCH operation
# Inserted and WriteProtected are not writable
if data["FirmwareVersion"].startswith("iLO 4"):
if "FirmwareVersion" in data and data["FirmwareVersion"].startswith("iLO 4"):
image_only = True
# Supermicro does also not support Inserted and WriteProtected
@ -2315,12 +2338,13 @@ class RedfishUtils(object):
# find an empty slot to insert the media
# try first with strict media_type matching
vendor = self._get_vendor()['Vendor']
uri, data = self._find_empty_virt_media_slot(
resources, media_types, media_match_strict=True)
resources, media_types, media_match_strict=True, vendor=vendor)
if not uri:
# if not found, try without strict media_type matching
uri, data = self._find_empty_virt_media_slot(
resources, media_types, media_match_strict=False)
resources, media_types, media_match_strict=False, vendor=vendor)
if not uri:
return {'ret': False,
'msg': "Unable to find an available VirtualMedia resource "
@ -2378,14 +2402,19 @@ class RedfishUtils(object):
return {'ret': True, 'changed': True,
'msg': "VirtualMedia ejected"}
def virtual_media_eject(self, options):
def virtual_media_eject(self, options, resource_type='Manager'):
image_url = options.get('image_url')
if not image_url:
return {'ret': False,
'msg': "image_url option required for VirtualMediaEject"}
# locate and read the VirtualMedia resources
response = self.get_request(self.root_uri + self.manager_uri)
# Given resource_type, use the proper URI
if resource_type == 'Systems':
resource_uri = self.systems_uri
elif resource_type == 'Manager':
resource_uri = self.manager_uri
response = self.get_request(self.root_uri + resource_uri)
if response['ret'] is False:
return response
data = response['data']
@ -2395,7 +2424,7 @@ class RedfishUtils(object):
# Some hardware (such as iLO 4) only supports the Image property on the PATCH operation
# Inserted is not writable
image_only = False
if data["FirmwareVersion"].startswith("iLO 4"):
if "FirmwareVersion" in data and data["FirmwareVersion"].startswith("iLO 4"):
image_only = True
if 'Supermicro' in data['Oem']: