Merge branch 'prototype' of https://github.com/vmisson/python-redfish into prototype.
Quick fix to allow library to run on the mockup. Update the simple-simulator example. Update redfish-client.
This commit is contained in:
parent
065a61442a
commit
e92169956f
@ -62,11 +62,20 @@ remote_mgmt.Systems.systems_list[0].bios.set_parameter("UefiShellStartup", "Enab
|
||||
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_list[0].set_parameter_json('{"Boot": {"BootSourceOverrideTarget": "UefiShell"}}')
|
||||
#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_list[0].set_parameter_json('{"Boot": {"BootSourceOverrideEnabled" : "Once"}}')
|
||||
|
||||
mySystem = remote_mgmt.Systems.systems_list[0]
|
||||
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()))
|
||||
|
||||
#Reset of the system is required to apply the changes
|
||||
remote_mgmt.Systems.systems_list[0].reset_system()
|
||||
#remote_mgmt.Systems.systems_list[0].reset_system()
|
||||
|
||||
remote_mgmt.logout()
|
||||
|
@ -31,8 +31,10 @@ PASSWORD = config["Nodes"]["default"]["password"]
|
||||
remote_mgmt = redfish.connect(URL, USER_NAME, PASSWORD,
|
||||
simulator=True, enforceSSL=False)
|
||||
|
||||
print ("Redfish API version : {} \n".format(remote_mgmt.get_api_version()))
|
||||
print ("UUID : {} \n".format(remote_mgmt.Root.get_api_UUID()))
|
||||
print ("Bios version : {}\n".format(remote_mgmt.Systems.systems_list[0].get_bios_version()))
|
||||
|
||||
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("System 2 :\n")
|
||||
print("Bios version : {}\n".format(remote_mgmt.Systems.systems_list[1].get_parameter("SerialNumber")))
|
||||
#print remoteMgmt.get_api_link_to_server()
|
||||
|
212
redfish/types.py
212
redfish/types.py
@ -13,7 +13,6 @@ import re
|
||||
|
||||
class Base(object):
|
||||
"""Abstract class to manage types (Chassis, Servers etc...)."""
|
||||
|
||||
def __init__(self, url, connection_parameters):
|
||||
"""Class constructor"""
|
||||
global TORTILLADEBUG
|
||||
@ -63,10 +62,52 @@ class Base(object):
|
||||
def url(self, url):
|
||||
self.__url = url
|
||||
|
||||
def get_parameter(self, parameter_name):
|
||||
"""Generic function to get any system parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data[parameter_name]
|
||||
except:
|
||||
return "Parameter does not exist"
|
||||
|
||||
def get_parameters(self):
|
||||
"""Generic function to get all system parameters
|
||||
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data
|
||||
except:
|
||||
return -1
|
||||
|
||||
def set_parameter(self, parameter_name, value):
|
||||
"""Generic function to set any system parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:param value: value to set
|
||||
:returns: string -- http response of PATCH request
|
||||
|
||||
"""
|
||||
# Craft the request
|
||||
action = dict()
|
||||
action[parameter_name] = value
|
||||
print(action)
|
||||
|
||||
# Perform the POST action
|
||||
print self.api_url
|
||||
response = self.api_url.patch(verify=self.connection_parameters.verify_cert,
|
||||
headers={'x-auth-token': self.connection_parameters.auth_token},
|
||||
data=action
|
||||
)
|
||||
return response
|
||||
|
||||
class BaseCollection(Base):
|
||||
"""Abstract class to manage collection (Chassis, Servers etc...)."""
|
||||
|
||||
def __init__(self, url, connection_parameters):
|
||||
super(BaseCollection, self).__init__(url, connection_parameters)
|
||||
|
||||
@ -91,7 +132,6 @@ class BaseCollection(Base):
|
||||
|
||||
class Root(Base):
|
||||
"""Class to manage redfish Root data."""
|
||||
|
||||
def get_api_version(self):
|
||||
"""Return api version.
|
||||
|
||||
@ -116,7 +156,6 @@ class Root(Base):
|
||||
"""
|
||||
return self.data.UUID
|
||||
|
||||
|
||||
def get_api_link_to_server(self):
|
||||
"""Return api link to server.
|
||||
|
||||
@ -135,7 +174,6 @@ class Managers(Base):
|
||||
"""Class to manage redfish Managers."""
|
||||
def __init__(self, url, connection_parameters):
|
||||
super(Managers, self).__init__(url, connection_parameters)
|
||||
|
||||
try:
|
||||
|
||||
# self.ethernet_interfaces_collection = EthernetInterfacesCollection(
|
||||
@ -151,6 +189,19 @@ class Managers(Base):
|
||||
except:
|
||||
pass
|
||||
|
||||
def get_firmware_version(self):
|
||||
"""Get bios version of the system.
|
||||
|
||||
:returns: string -- bios version
|
||||
|
||||
"""
|
||||
try:
|
||||
# Returned by proliant
|
||||
return self.data.FirmwareVersion
|
||||
except:
|
||||
# Returned by mockup.
|
||||
# Hopefully this kind of discrepencies will be fixed with Redfish 1.0 (August)
|
||||
return self.data.FirmwareVersion
|
||||
|
||||
class ManagersCollection(BaseCollection):
|
||||
"""Class to manage redfish ManagersCollection data."""
|
||||
@ -168,7 +219,10 @@ class Systems(Base):
|
||||
def __init__(self, url, connection_parameters):
|
||||
"""Class constructor"""
|
||||
super(Systems, self).__init__(url, connection_parameters)
|
||||
self.bios = Bios(url+"Bios/Settings", connection_parameters)
|
||||
try:
|
||||
self.bios = Bios(url + "Bios/Settings", connection_parameters)
|
||||
except:
|
||||
pass
|
||||
|
||||
def reset_system(self):
|
||||
"""Force reset of the system.
|
||||
@ -229,39 +283,6 @@ class Systems(Base):
|
||||
except:
|
||||
return ""
|
||||
|
||||
def get_parameter(self, parameter_name):
|
||||
"""Generic function to get any system parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data[parameter_name]
|
||||
except:
|
||||
return "Parameter does not exist"
|
||||
|
||||
def set_parameter(self, parameter_name, value):
|
||||
"""Generic function to set any system parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:param value: value to set
|
||||
:returns: string -- http response of PATCH request
|
||||
|
||||
"""
|
||||
# Craft the request
|
||||
action = dict()
|
||||
action[parameter_name] = value
|
||||
print(action)
|
||||
|
||||
# Perform the POST action
|
||||
print self.api_url
|
||||
response = self.api_url.patch(verify=self.connection_parameters.verify_cert,
|
||||
headers={'x-auth-token': self.connection_parameters.auth_token},
|
||||
data=action
|
||||
)
|
||||
return response
|
||||
|
||||
def set_parameter_json(self, value):
|
||||
"""Generic function to set any system parameter using json structure
|
||||
|
||||
@ -270,13 +291,35 @@ class Systems(Base):
|
||||
|
||||
"""
|
||||
# perform the POST action
|
||||
print self.api_url.url()
|
||||
|
||||
#print self.api_url.url()
|
||||
response = requests.patch(self.api_url.url(),
|
||||
verify=self.connection_parameters.verify_cert,
|
||||
headers={'x-auth-token': self.connection_parameters.auth_token, 'Content-type': 'application/json'},
|
||||
data=value)
|
||||
print(response.reason)
|
||||
return response.reason
|
||||
|
||||
def set_boot_source_override(self, target, enabled):
|
||||
"""Shotcut function to set boot source
|
||||
|
||||
:param target: new boot source. Supported values:
|
||||
"None",
|
||||
"Pxe",
|
||||
"Floppy",
|
||||
"Cd",
|
||||
"Usb",
|
||||
"Hdd",
|
||||
"BiosSetup",
|
||||
"Utilities",
|
||||
"Diags",
|
||||
"UefiShell",
|
||||
"UefiTarget"
|
||||
:param enabled: Supported values:
|
||||
"Disabled",
|
||||
"Once",
|
||||
"Continuous"
|
||||
:returns: string -- http response of PATCH request
|
||||
"""
|
||||
return self.set_parameter_json('{"Boot": {"BootSourceOverrideTarget": "'+target+'"},{"BootSourceOverrideEnabled" : "'+enabled+'"}}')
|
||||
|
||||
class SystemsCollection(BaseCollection):
|
||||
"""Class to manage redfish ManagersCollection data."""
|
||||
@ -294,96 +337,11 @@ class Bios(Base):
|
||||
super(Bios, self).__init__(url, connection_parameters)
|
||||
self.boot = Boot(re.findall(".+/Bios",url)[0]+"/Boot/Settings", connection_parameters)
|
||||
|
||||
def get_parameters(self):
|
||||
"""Generic function to get all system parameters
|
||||
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data
|
||||
except:
|
||||
return -1
|
||||
|
||||
def get_parameter(self, parameter_name):
|
||||
"""Generic function to get any system parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data[parameter_name]
|
||||
except:
|
||||
return "Parameter does not exist"
|
||||
|
||||
def set_parameter(self, parameter_name, value):
|
||||
"""Generic function to set any bios parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:param value: value to set
|
||||
:returns: string -- http response of PATCH request
|
||||
|
||||
"""
|
||||
# Craft the request
|
||||
action = dict()
|
||||
action[parameter_name] = value
|
||||
|
||||
# perform the POST action
|
||||
print self.api_url
|
||||
response = self.api_url.patch(verify=self.connection_parameters.verify_cert,
|
||||
headers={'x-auth-token': self.connection_parameters.auth_token},
|
||||
data=action
|
||||
)
|
||||
return response
|
||||
|
||||
class Boot(Base):
|
||||
"""Class to manage redfish Boot data."""
|
||||
def __init__(self, url, connection_parameters):
|
||||
super(Boot, self).__init__(url, connection_parameters)
|
||||
|
||||
def get_parameters(self):
|
||||
"""Generic function to get all system parameters
|
||||
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data
|
||||
except:
|
||||
return -1
|
||||
|
||||
def get_parameter(self, parameter_name):
|
||||
"""Generic function to get any system parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:returns: string -- parameter value
|
||||
|
||||
"""
|
||||
try:
|
||||
return self.data[parameter_name]
|
||||
except:
|
||||
return "Parameter does not exist"
|
||||
|
||||
def set_parameter(self, parameter_name, value):
|
||||
"""Generic function to set any bios parameter
|
||||
|
||||
:param parameter_name: name of the parameter
|
||||
:param value: value to set
|
||||
:returns: string -- http response of PATCH request
|
||||
|
||||
"""
|
||||
# Craft the request
|
||||
action = dict()
|
||||
action[parameter_name] = value
|
||||
|
||||
# perform the POST action
|
||||
response = self.api_url.patch(verify=self.connection_parameters.verify_cert,
|
||||
headers={'x-auth-token': self.connection_parameters.auth_token},
|
||||
data=action
|
||||
)
|
||||
return response
|
||||
|
||||
class EthernetInterfacesCollection(BaseCollection):
|
||||
"""Class to manage redfish EthernetInterfacesColkection data."""
|
||||
def __init__(self, url, connection_parameters):
|
||||
|
Loading…
x
Reference in New Issue
Block a user