Skip to content

Commit

Permalink
Merge pull request #393 from xlab-si/redfish-resource-name
Browse files Browse the repository at this point in the history
[RFR] Modify the Redfish resources' name
  • Loading branch information
mshriver authored Jun 28, 2019
2 parents 3fb310d + 1b6f336 commit 5e52f27
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 5e52f27

Please sign in to comment.