diff --git a/redfish-client/redfish-client b/redfish-client/redfish-client index d42f2a2..038120f 100755 --- a/redfish-client/redfish-client +++ b/redfish-client/redfish-client @@ -12,6 +12,7 @@ redfish-client :: redfish-client [options] config show redfish-client [options] config showall redfish-client [options] manager getinfo [] + redfish-client [options] chassis getinfo [] redfish-client [options] system getinfo [] redfish-client (-h | --help) redfish-client --version @@ -266,6 +267,10 @@ if __name__ == '__main__': # Display manager information using jinja2 template render_template("manager_info.template") + def display_chassis_info(redfish_data): + # Display system information using jinja2 template + render_template("chassis_info.template") + def display_system_info(redfish_data): # Display system information using jinja2 template render_template("system_info.template") @@ -437,6 +442,7 @@ if __name__ == '__main__': logger.debug("system commands") display_system_info(redfish_data) elif arguments['chassis'] is True: - pass + logger.debug("chassis commands") + display_chassis_info(redfish_data) logger.info("Client session terminated") sys.exit(0) diff --git a/redfish-client/templates/chassis_info.template b/redfish-client/templates/chassis_info.template new file mode 100644 index 0000000..704e70f --- /dev/null +++ b/redfish-client/templates/chassis_info.template @@ -0,0 +1,72 @@ +Redfish API version : {{ r.get_api_version() }} +{{ r.Root.get_name() }} + +Chassis information : +===================== +{% for chassis_index in r.Chassis.chassis_dict | sort %} +{%- set chassis = r.Chassis.chassis_dict[chassis_index] %} +Chassis id {{ chassis_index }}: +Manufacturer : {{ chassis.get_manufacturer() }} +Model : {{ chassis.get_model() }} +Chassis Type : {{ chassis.get_chassis_type() }} +PartNumber : {{ chassis.get_part_number() }} +SKU : {{ chassis.get_sku() }} +Serial : {{ chassis.get_serial_number() }} +AssetTag : {{ chassis.get_asset_tag() }} +Status : State : {{ chassis.get_status().Health }} / Health : {{ chassis.get_status().Health }} +{# +Hostname : {{ system.get_hostname() }} +Bios version : {{ system.get_bios_version() }} +CPU number : {{ system.get_cpucount() }} +CPU model : {{ system.get_cpumodel() }} + +{%- if system.processors_collection %} +CPU details : + {%- for cpu_index in system.processors_collection.processors_dict | sort %} + {%- set cpu = system.processors_collection.processors_dict[cpu_index] %} + Processor id {{ cpu_index }} : + Speed : {{ cpu.get_speed() }} + Cores : {{ cpu.get_cores() }} + Threads : {{ cpu.get_threads() }} + {% endfor %} +{%- endif %} +Available memory : {{ system.get_memory() }} +Status : State : {{ system.get_status().Health }} / Health : {{ system.get_status().Health }} +Power : {{ system.get_power() }} +Description : {{ system.get_description() }} +Chassis : {{ system.get_chassis() | join(', ') }} +Managers : {{ system.get_managers() | join(', ') }} +IndicatorLED : {{ system.get_indicatorled() }} + +Ethernet Interface : +{%- if system.ethernet_interfaces_collection %} +{%- for ethernetinterface_index in system.ethernet_interfaces_collection.ethernet_interfaces_dict | sort %} +{%- set ei = system.ethernet_interfaces_collection.ethernet_interfaces_dict[ethernetinterface_index] %} + Ethernet Interface id {{ ethernetinterface_index }} : + {{ ei.get_name() }} + FQDN : {{ ei.get_fqdn() }} + Mac address : {{ ei.get_mac() }} + Address ipv4 : {{ ei.get_ipv4() | join(', ') }} + Address ipv6 : {{ ei.get_ipv6() | join(', ') }} +{%- endfor %} +{%- else %} + This system has no ethernet interface +{%- endif %} + +Simple Storage : +{%- if system.simple_storage_collection %} +{%- for simplestorage_index in system.simple_storage_collection.simple_storage_dict | sort %} +{%- set ss = system.simple_storage_collection.simple_storage_dict[simplestorage_index] %} + Simple Storage id {{ simplestorage_index }} : + {{ ss.get_name() }} + Status : State : {{ system.get_status().Health }} / Health : {{ system.get_status().Health }} + {%- for dev in ss.get_devices() %} + Device id {{ loop.index }} : {{ dev.Name }} {{ dev.Manufacturer }} {{ dev.Model }} + {%- endfor %} +{%- endfor %} +{%- else %} + This system has no simple storage +{%- endif %} +-------------------------------------------------------------------------------- +#} +{% endfor %} \ No newline at end of file diff --git a/redfish-client/templates/system_info.template b/redfish-client/templates/system_info.template index 3fe739b..6e40a63 100644 --- a/redfish-client/templates/system_info.template +++ b/redfish-client/templates/system_info.template @@ -27,7 +27,7 @@ CPU details : Threads : {{ cpu.get_threads() }} {% endfor %} {%- endif %} -Available memory : {{ system.get_memory() }} +Available memory : {{ system.get_memory() }} GB Status : State : {{ system.get_status().Health }} / Health : {{ system.get_status().Health }} Power : {{ system.get_power() }} Description : {{ system.get_description() }} diff --git a/redfish/main.py b/redfish/main.py index 094d10a..0890567 100644 --- a/redfish/main.py +++ b/redfish/main.py @@ -254,7 +254,9 @@ class RedfishConnection(object): self.connection_parameters ) -# self.Chassis + self.Chassis = types.ChassisCollection(self.Root.get_link_url("Chassis"), + self.connection_parameters + ) # self.EventService # self.AccountService diff --git a/redfish/types.py b/redfish/types.py index e8157a7..54f3023 100644 --- a/redfish/types.py +++ b/redfish/types.py @@ -846,3 +846,42 @@ class SimpleStorage(Base): return self.data.Devices except AttributeError: return "Not available" + + +class ChassisCollection(BaseCollection): + '''Class to manage redfish ChassisCollection data.''' + def __init__(self, url, connection_parameters): + super(ChassisCollection, self).__init__(url, connection_parameters) + + self.chassis_dict = {} + + for link in self.links: + index = re.search(r'Chassis/(\w+)', link) + self.chassis_dict[index.group(1)] = Chassis(link, connection_parameters) + + +class Chassis(Device): + '''Class to manage redfish Chassis data.''' + def __init__(self, url, connection_parameters): + '''Class constructor''' + super(Chassis, self).__init__(url, connection_parameters) + +# try: +# self.ethernet_interfaces_collection = \ +# EthernetInterfacesCollection( +# self.get_link_url('EthernetInterfaces'), +# connection_parameters) +# except AttributeError: +# # This means we don't have EthernetInterfaces +# self.ethernet_interfaces_collection = None + def get_chassis_type(self): + '''Get chassis type + + :returns: chassis type or "Not available" + :rtype: string + + ''' + try: + return self.data.ChassisType + except AttributeError: + return "Not available"