From a2cafc9802458783634d10344ddc6b8752ac57f4 Mon Sep 17 00:00:00 2001 From: Uggla Date: Thu, 11 Feb 2016 22:18:38 +0100 Subject: [PATCH] Change SystemCollection from list to dict - Change systems_list to systems_dict[""] . The systems_dict will contain system objects, is the redfish as reported inside url. --- examples/simple-proliant.py | 46 ++++++++++++++++++------------------ examples/simple-simulator.py | 4 ++-- redfish/main.py | 2 -- redfish/types.py | 9 +++---- 4 files changed, 30 insertions(+), 31 deletions(-) diff --git a/examples/simple-proliant.py b/examples/simple-proliant.py index 468527b..451b7a1 100644 --- a/examples/simple-proliant.py +++ b/examples/simple-proliant.py @@ -43,48 +43,48 @@ except redfish.exception.RedfishException as e: print ("Redfish API version : %s \n" % remote_mgmt.get_api_version()) # Uncomment following line to reset the blade !!! -# remote_mgmt.Systems.systems_list[0].reset_system() +# remote_mgmt.Systems.systems_dict["1"].reset_system() # TODO : create an attribute to link the managed system directly -# and avoid systems_list[0] +# and avoid systems_dict["1"] # --> will be something like : -# remote_mgmt.Systems.systems_list[0] = remote_mgmt.Systems.managed_system +# remote_mgmt.Systems.systems_dict["1"] = remote_mgmt.Systems.managed_system -print("Bios version : {}\n".format(remote_mgmt.Systems.systems_list[0].get_bios_version())) -print("Serial Number : {}\n".format(remote_mgmt.Systems.systems_list[0].get_serial_number())) -print("Power State : {}\n".format(remote_mgmt.Systems.systems_list[0].get_power())) -print("Parameter 'SystemType' : {}\n".format(remote_mgmt.Systems.systems_list[0].get_parameter("SystemType"))) +print("Bios version : {}\n".format(remote_mgmt.Systems.systems_dict["1"].get_bios_version())) +print("Serial Number : {}\n".format(remote_mgmt.Systems.systems_dict["1"].get_serial_number())) +print("Power State : {}\n".format(remote_mgmt.Systems.systems_dict["1"].get_power())) +print("Parameter 'SystemType' : {}\n".format(remote_mgmt.Systems.systems_dict["1"].get_parameter("SystemType"))) -print("Get bios parameters : {}\n".format(remote_mgmt.Systems.systems_list[0].bios.get_parameters())) -print("Get boot parameters : {}\n".format(remote_mgmt.Systems.systems_list[0].bios.boot.get_parameters())) +print("Get bios parameters : {}\n".format(remote_mgmt.Systems.systems_dict["1"].bios.get_parameters())) +print("Get boot parameters : {}\n".format(remote_mgmt.Systems.systems_dict["1"].bios.boot.get_parameters())) -#print("Get bios parameter 'AdminPhone' : {}\n".format(remote_mgmt.Systems.systems_list[0].bios.get_parameter("AdminPhone"))) -#print("Set bios parameter 'AdminPhone' to '' : {}\n".format(remote_mgmt.Systems.systems_list[0].bios.set_parameter("AdminPhone",""))) +#print("Get bios parameter 'AdminPhone' : {}\n".format(remote_mgmt.Systems.systems_dict["1"].bios.get_parameter("AdminPhone"))) +#print("Set bios parameter 'AdminPhone' to '' : {}\n".format(remote_mgmt.Systems.systems_dict["1"].bios.set_parameter("AdminPhone",""))) #Boot server with script -#remote_mgmt.Systems.systems_list[0].bios.set_parameter("Dhcpv4","Enabled") +#remote_mgmt.Systems.systems_dict["1"].bios.set_parameter("Dhcpv4","Enabled") -remote_mgmt.Systems.systems_list[0].bios.set_parameter("PreBootNetwork", "Auto") -remote_mgmt.Systems.systems_list[0].bios.set_parameter("UefiShellStartup", "Enabled") -remote_mgmt.Systems.systems_list[0].bios.set_parameter("UefiShellStartupLocation", "NetworkLocation") -remote_mgmt.Systems.systems_list[0].bios.set_parameter("UefiShellStartupUrl", "http://10.3.222.88/deploy/startup.nsh") +remote_mgmt.Systems.systems_dict["1"].bios.set_parameter("PreBootNetwork", "Auto") +remote_mgmt.Systems.systems_dict["1"].bios.set_parameter("UefiShellStartup", "Enabled") +remote_mgmt.Systems.systems_dict["1"].bios.set_parameter("UefiShellStartupLocation", "NetworkLocation") +remote_mgmt.Systems.systems_dict["1"].bios.set_parameter("UefiShellStartupUrl", "http://10.3.222.88/deploy/startup.nsh") -#remote_mgmt.Systems.systems_list[0].set_parameter_json('{"Boot": {"BootSourceOverrideTarget": "UefiShell"}}') -# remote_mgmt.Systems.systems_list[0].set_parameter_json('{"Boot": {"BootSourceOverrideEnabled" : "Continuous"}}') -#remote_mgmt.Systems.systems_list[0].set_parameter_json('{"Boot": {"BootSourceOverrideEnabled" : "Once"}}') +#remote_mgmt.Systems.systems_dict["1"].set_parameter_json('{"Boot": {"BootSourceOverrideTarget": "UefiShell"}}') +# remote_mgmt.Systems.systems_dict["1"].set_parameter_json('{"Boot": {"BootSourceOverrideEnabled" : "Continuous"}}') +#remote_mgmt.Systems.systems_dict["1"].set_parameter_json('{"Boot": {"BootSourceOverrideEnabled" : "Once"}}') -mySystem = remote_mgmt.Systems.systems_list[0] +mySystem = remote_mgmt.Systems.systems_dict["1"] mySystem.set_boot_source_override("None","Disabled") #Uncomment the next line to reset the server #mySystem.reset_system() -print("Get manager firmware version : {}\n".format(remote_mgmt.Managers.managers_list[0].get_firmware_version())) -print("Get system Bios version : {}\n".format(remote_mgmt.Systems.systems_list[0].get_bios_version())) +print("Get manager firmware version : {}\n".format(remote_mgmt.Managers.managers_dict["1"].get_firmware_version())) +print("Get system Bios version : {}\n".format(remote_mgmt.Systems.systems_dict["1"].get_bios_version())) #Reset of the system is required to apply the changes -#remote_mgmt.Systems.systems_list[0].reset_system() +#remote_mgmt.Systems.systems_dict["1"].reset_system() remote_mgmt.logout() diff --git a/examples/simple-simulator.py b/examples/simple-simulator.py index b9db1af..df44ca5 100644 --- a/examples/simple-simulator.py +++ b/examples/simple-simulator.py @@ -43,7 +43,7 @@ except redfish.exception.RedfishException as e: print("Redfish API version : {} \n".format(remote_mgmt.get_api_version())) print("UUID : {} \n".format(remote_mgmt.Root.get_api_UUID())) print("System 1 :\n") -print("Bios version : {}\n".format(remote_mgmt.Systems.systems_list[0].get_bios_version())) +print("Bios version : {}\n".format(remote_mgmt.Systems.systems_dict["1"].get_bios_version())) print("System 2 :\n") -print("Bios version : {}\n".format(remote_mgmt.Systems.systems_list[1].get_parameter("SerialNumber"))) +print("Bios version : {}\n".format(remote_mgmt.Systems.systems_dict["2"].get_parameter("SerialNumber"))) #print remoteMgmt.get_api_link_to_server() diff --git a/redfish/main.py b/redfish/main.py index 3a28cf0..98c0205 100644 --- a/redfish/main.py +++ b/redfish/main.py @@ -247,8 +247,6 @@ class RedfishConnection(object): self.connection_parameters ) - #for system in self.Systems.systems_list: - #config.logger.debug(system.data.links.ManagedBy) # self.Chassis # self.EventService diff --git a/redfish/types.py b/redfish/types.py index ecdd477..2097454 100644 --- a/redfish/types.py +++ b/redfish/types.py @@ -428,11 +428,12 @@ class SystemsCollection(BaseCollection): '''Class to manage redfish SystemsCollection data.''' def __init__(self, url, connection_parameters): super(SystemsCollection, self).__init__(url, connection_parameters) - - self.systems_list = [] - + + self.systems_dict = {} + for link in self.links: - self.systems_list.append(Systems(link, connection_parameters)) + index = re.search(r'Systems/(\w+)', link) + self.systems_dict[index.group(1)] = Systems(link, connection_parameters) class Bios(Base):