Skip to content

Commit

Permalink
Modify the Redfish resources' name
Browse files Browse the repository at this point in the history
The name property of the Redfish resources such as Physical Systems
or Chassis other than Racks now reflect the method of composing the
name in the ManageIQ's GUI: concatenation of Manufacturer, Name
and, if available, Serial Number in parentheses.

The name of Rack instances is unchanged, i.e., it shows the Id of
the resource. To distinguish the representation from other types
of physical chassis in Redfish, we introduced the `RedfishRack`
class.

Related PR:
  * ManageIQ/manageiq-providers-redfish#61
  • Loading branch information
matejart committed Jun 28, 2019
1 parent 3fb310d commit 1b6f336
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions wrapanapi/systems/redfish.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ def refresh(self):
@property
def name(self):
"""Return name from most recent raw data."""
return self.raw.Id
name = "{} {}".format(self.raw.Manufacturer, self.raw.Name)
if "SerialNumber" in self.raw:
name = "{} ({})".format(name, self.raw.SerialNumber)
return name

@property
def description(self):
Expand Down Expand Up @@ -132,6 +135,15 @@ def num_servers(self):
return len(self.raw.Links.raw.get("ComputerSystems", []))


class RedfishRack(RedfishChassis):
"""API handler for this instance of the physical rack."""

@property
def name(self):
"""Return name from most recent raw data."""
return self.raw.Id


class RedfishSystem(System):
"""Client to Redfish API.
Expand Down Expand Up @@ -368,7 +380,7 @@ def get_chassis(self, resource_id, *required_types):

def get_rack(self, resource_id):
"""
Fetch a RedfishChassis instance of the physical rack representing resource_id.
Fetch a RedfishRack instance of the physical rack representing resource_id.
Args:
resource_id: the Redfish @odata.id of the resource representing the
Expand All @@ -377,7 +389,12 @@ def get_rack(self, resource_id):
InvalidValueException if the resource_id represents a Chassis that is
not a rack
"""
return self.get_chassis(resource_id, "Rack")
rack_data = self.find(resource_id)
if rack_data.ChassisType != "Rack":
raise InvalidValueException("Chassis type {} does not match that of a Rack".format(
rack_data.ChassisType))

return RedfishRack(self, raw=rack_data)

@property
def num_servers(self):
Expand Down

0 comments on commit 1b6f336

Please sign in to comment.