Use Jinja2 template system to display manager info
- Use templating system, so user will be able to customize output. - This could be use later to propose output in various format (html, xml, json). - Undefined EthernetInterfacesCollection in case of failure. So it allows to test definition in the template or elsewhere.
This commit is contained in:
parent
6ffbd4aec8
commit
173e7798cf
@ -39,6 +39,7 @@ import docopt
|
|||||||
import logging
|
import logging
|
||||||
import redfish
|
import redfish
|
||||||
import requests.packages.urllib3
|
import requests.packages.urllib3
|
||||||
|
import jinja2
|
||||||
|
|
||||||
|
|
||||||
class ConfigFile(object):
|
class ConfigFile(object):
|
||||||
@ -249,35 +250,9 @@ if __name__ == '__main__':
|
|||||||
sys.stderr.write(str(e.advices))
|
sys.stderr.write(str(e.advices))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Display manager information
|
# Display manager information using jinja2 template
|
||||||
# TODO : Use a templating system
|
template = jinja2_env.get_template("manager_info.template")
|
||||||
print('Redfish API version : %s' % remote_mgmt.get_api_version())
|
print template.render(r=remote_mgmt)
|
||||||
print(remote_mgmt.Root.get_name())
|
|
||||||
print('\n')
|
|
||||||
print('Managers information :')
|
|
||||||
print('----------------------')
|
|
||||||
for manager_index in sorted(remote_mgmt.Managers.managers_dict):
|
|
||||||
manager = remote_mgmt.Managers.managers_dict[manager_index]
|
|
||||||
print('\nManager id {} :').format(manager_index)
|
|
||||||
print('UUID : {}').format(manager.get_uuid())
|
|
||||||
print('Type : {}').format(manager.get_type())
|
|
||||||
print('Firmware version : {}').format(manager.get_firmware_version())
|
|
||||||
print('State : {}').format(manager.get_status())
|
|
||||||
print manager.get_managed_chassis()
|
|
||||||
print manager.get_managed_systems()
|
|
||||||
print('Ethernet interfaces :')
|
|
||||||
try :
|
|
||||||
for ethernetinterface_index in sorted(manager.ethernet_interfaces_collection.ethernet_interfaces_dict):
|
|
||||||
ei = manager.ethernet_interfaces_collection.ethernet_interfaces_dict[ethernetinterface_index]
|
|
||||||
print('\nEthernet Interface id {} :').format(ethernetinterface_index)
|
|
||||||
print(ei.get_name())
|
|
||||||
print(ei.get_parameter('FQDN'))
|
|
||||||
print ei.get_ipv4()
|
|
||||||
print ei.get_ipv6()
|
|
||||||
except AttributeError:
|
|
||||||
# We don't have ethernet interfaces
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Main program
|
# Main program
|
||||||
@ -349,6 +324,11 @@ if __name__ == '__main__':
|
|||||||
arguments['--conf_file'] = arguments['--conf_file'].replace('~', HOME)
|
arguments['--conf_file'] = arguments['--conf_file'].replace('~', HOME)
|
||||||
conf_file = ConfigFile(arguments['--conf_file'])
|
conf_file = ConfigFile(arguments['--conf_file'])
|
||||||
|
|
||||||
|
# Initialize Template system (jinja2)
|
||||||
|
# TODO : set the template file location into cmd line default to /usr/share/python-redfish/templates ?
|
||||||
|
logger.debug("Initialize template system")
|
||||||
|
jinja2_env = jinja2.Environment(loader=jinja2.FileSystemLoader("templates"))
|
||||||
|
|
||||||
if arguments['config'] is True:
|
if arguments['config'] is True:
|
||||||
logger.debug("Config commands")
|
logger.debug("Config commands")
|
||||||
if arguments['show'] is True:
|
if arguments['show'] is True:
|
||||||
|
32
redfish-client/templates/bla.templates
Normal file
32
redfish-client/templates/bla.templates
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#=======================================================================
|
||||||
|
# print('Redfish API version : %s' % remote_mgmt.get_api_version())
|
||||||
|
# print(remote_mgmt.Root.get_name())
|
||||||
|
# print('\n')
|
||||||
|
# print('Managers information :')
|
||||||
|
# print('----------------------')
|
||||||
|
# for manager_index in sorted(remote_mgmt.Managers.managers_dict):
|
||||||
|
# manager = remote_mgmt.Managers.managers_dict[manager_index]
|
||||||
|
# print('\nManager id {} :').format(manager_index)
|
||||||
|
# print('UUID : {}').format(manager.get_uuid())
|
||||||
|
# print('Type : {}').format(manager.get_type())
|
||||||
|
# print('Firmware version : {}').format(manager.get_firmware_version())
|
||||||
|
# print('State : {}').format(manager.get_status())
|
||||||
|
# print manager.get_managed_chassis()
|
||||||
|
# print manager.get_managed_systems()
|
||||||
|
# print('Ethernet interfaces :')
|
||||||
|
# try :
|
||||||
|
# for ethernetinterface_index in sorted(manager.ethernet_interfaces_collection.ethernet_interfaces_dict):
|
||||||
|
# ei = manager.ethernet_interfaces_collection.ethernet_interfaces_dict[ethernetinterface_index]
|
||||||
|
# print('\nEthernet Interface id {} :').format(ethernetinterface_index)
|
||||||
|
# print(ei.get_name())
|
||||||
|
# print(ei.get_parameter('FQDN'))
|
||||||
|
# print ei.get_ipv4()
|
||||||
|
# print ei.get_ipv6()
|
||||||
|
# except AttributeError:
|
||||||
|
# # We don't have ethernet interfaces
|
||||||
|
# pass
|
||||||
|
#=======================================================================
|
||||||
|
|
||||||
|
|
||||||
|
Redfish API version : remote_mgmt.get_api_version()
|
||||||
|
remote_mgmt.Root.get_name()
|
31
redfish-client/templates/manager_info.template
Normal file
31
redfish-client/templates/manager_info.template
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
Redfish API version : {{ r.get_api_version() }}
|
||||||
|
{{ r.Root.get_name() }}
|
||||||
|
|
||||||
|
Managers information :
|
||||||
|
======================
|
||||||
|
{% for manager_index in r.Managers.managers_dict | sort %}
|
||||||
|
{%- set manager = r.Managers.managers_dict[manager_index] %}
|
||||||
|
Manager id {{ manager_index }}:
|
||||||
|
UUID : {{ manager.get_uuid() }}
|
||||||
|
Type : {{ manager.get_type() }}
|
||||||
|
Firmware version : {{ manager.get_firmware_version() }}
|
||||||
|
State : {{ manager.get_status() }}
|
||||||
|
Ethernet Interface :
|
||||||
|
{%- if manager.ethernet_interfaces_collection %}
|
||||||
|
{%- for ethernetinterface_index in manager.ethernet_interfaces_collection.ethernet_interfaces_dict | sort %}
|
||||||
|
{%- set ei = manager.ethernet_interfaces_collection.ethernet_interfaces_dict[ethernetinterface_index] %}
|
||||||
|
Ethernet Interface id {{ ethernetinterface_index }} :
|
||||||
|
{{ ei.get_name() }}
|
||||||
|
FQDN : {{ ei.get_fqdn() }}
|
||||||
|
Address ipv4 : {{ ei.get_ipv4() | join(', ') }}
|
||||||
|
Address ipv6 : {{ ei.get_ipv6() | join(', ') }}
|
||||||
|
{%- endfor %}
|
||||||
|
{%- else %}
|
||||||
|
This manager has no ethernet interface
|
||||||
|
{%- endif %}
|
||||||
|
Managed Chassis :
|
||||||
|
{{ manager.get_managed_chassis() | join(', ') }}
|
||||||
|
Managed System :
|
||||||
|
{{ manager.get_managed_systems() | join(', ') }}
|
||||||
|
----------------------------
|
||||||
|
{% endfor %}
|
@ -218,11 +218,12 @@ class Managers(Base):
|
|||||||
# )
|
# )
|
||||||
except exception.InvalidRedfishContentException:
|
except exception.InvalidRedfishContentException:
|
||||||
# This is to avoid invalid content from the mockup
|
# This is to avoid invalid content from the mockup
|
||||||
pass
|
self.ethernet_interfaces_collection = None
|
||||||
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
# This means we don't have EthernetInterfaces
|
# This means we don't have EthernetInterfaces
|
||||||
pass
|
self.ethernet_interfaces_collection = None
|
||||||
|
|
||||||
|
|
||||||
def get_firmware_version(self):
|
def get_firmware_version(self):
|
||||||
'''Get firmware version of the manager
|
'''Get firmware version of the manager
|
||||||
|
@ -6,3 +6,4 @@ pbr>=0.6,!=0.7,<1.0
|
|||||||
#oslo.log>=1.0,<2.0
|
#oslo.log>=1.0,<2.0
|
||||||
Babel>=1.3
|
Babel>=1.3
|
||||||
tortilla>=0.4.1
|
tortilla>=0.4.1
|
||||||
|
Jinja2>=2.7.3
|
||||||
|
Loading…
x
Reference in New Issue
Block a user