def __init__(self, host, login_account, login_password): self.rest_client = rest_client(base_url=host, \ username=login_account, password=login_password, \ default_prefix="/rest/v1") self.rest_client.login(auth=AuthMethod.SESSION) self.SYSTEMS_RESOURCES = self.ex1_get_resource_directory() self.MESSAGE_REGISTRIES = self.ex2_get_base_registry()
def __init__(self, module, host, login_account, login_password): self.check_hpe_ilorest(module) self.rest_client = rest_client(base_url=host, username=login_account, password=login_password, default_prefix="/rest/v1") self.rest_client.login(auth=AuthMethod.SESSION) self.SYSTEMS_RESOURCES = self.get_resource_directory(module) self.MESSAGE_REGISTRIES = self.get_base_registry(module)
def getgen(self, gen=None, url=None, username=None, password=None, logger=None): """Function designed to verify the servers platform :param url: The URL to perform the request on. :type url: str. :param logger: The logger handler. :type logger: str. """ self.url = url if not gen: try: redfishclient = redfish_client(base_url=self.url, \ username=username, password=password, \ default_prefix="/redfish/v1/", is_redfish=True,\ cache=False) rootresp = redfishclient.root redfishclient.logout() except SecurityStateError as excp: raise excp except InvalidCredentialsError: raise except Exception: excep = None try: restclient = rest_client(base_url=self.url, username=username, \ password=password, default_prefix="/rest/v1") rootresp = restclient.root restclient.logout() except Exception as excep: logger = logger if not logger else LOGGER logger.error("Gen get rest error:"+str(excep)+"\n") if excep: raise self.ilogen = None try: self.ilogen = rootresp["Oem"]["Hp"]["Manager"][0]["ManagerType"] except: self.ilogen = rootresp["Oem"]["Hpe"]["Manager"][0]["ManagerType"] else: self.ilogen = int(gen) try: if not isinstance(self.ilogen, int): self.ilogen = self.ilogen.split(' ')[-1] self.flagiften = False if int(self.ilogen) >= 5: self.flagiften = True except: raise UnableToObtainIloVersionError("Unable to find the iloversion") if self.flagiften: self.defs = Definevalstenplus() else: self.defs = DefinevalsNine()
def login(self): '''Login to iLO. Call this method right after iLO() and before any iLO.get_xxx(). ''' self.rest_obj = redfish.rest_client( \ base_url = self.ilo_host, \ username = self.ilo_user, \ password = self.ilo_password, \ default_prefix = '/rest/v1') self.rest_obj.login(auth='session')
def get_ilorest_client(self, server_hardware): """Generate an instance of the iLORest library client. :param: server_hardware: a dict representing the server hardware :returns: an instance of the iLORest client """ remote_console = ( self.hponeview_client.server_hardware.get_remote_console_url( server_hardware.get('uri'))) host_ip, ilo_token = common.get_ilo_access(remote_console) base_url = "https://%s:%s" % (host_ip, ILOREST_BASE_PORT) return redfish.rest_client(base_url=base_url, sessionkey=ilo_token)
def getgen(self, url=None, logger=None): """Function designed to verify the servers platform :param url: The URL to perform the request on. :type url: str. :param logger: The logger handler. :type logger: str. """ self.url = url try: redfishclient = redfish_client(base_url=self.url, \ username=None, password=None, \ default_prefix="/redfish/v1/", is_redfish=True) response = redfishclient.get(path="/redfish/v1/") except SecurityStateError as excp: raise excp except Exception as excp: try: restclient = rest_client(base_url=self.url, username=None, \ password=None, default_prefix="/rest/v1") response = restclient.get(path="/rest/v1") except Exception as excep: logger = logger if not logger else LOGGER if type(excep) != type(excp): logger.error("Gen get rest error:" + str(excep) + "\n") raise excp self.ilogen = None try: self.ilogen = response.dict["Oem"]["Hp"]["Manager"][0]\ ["ManagerType"] except: self.ilogen = response.dict["Oem"]["Hpe"]["Manager"][0]\ ["ManagerType"] try: self.ilogen = self.ilogen.split(' ')[-1] self.flagiften = False if int(self.ilogen) >= 5: self.flagiften = True except: raise UnableToObtainIloVersionError( "Unable to find the iloversion") if self.flagiften: self.defs = Definevalstenplus() else: self.defs = DefinevalsNine()
import sys import redfish # When running on the server locally use the following commented values # iLO_host = "blobstore://." # iLO_account = "None" # iLO_password = "******" # When running remotely connect using the iLO address, iLO account name, # and password to send https requests iLO_host = "https://10.0.0.100" login_account = "admin" login_password = "******" # Create a REST object REST_OBJ = redfish.rest_client(base_url=iLO_host,username=login_account, \ password=login_password, default_prefix='/rest/v1') # Login into the server and create a session REST_OBJ.login(auth="session") # Do a GET on a given path response = REST_OBJ.get("/rest/v1/systems/1", None) # Print out the response sys.stdout.write("%s\n" % response) # Logout of the current session REST_OBJ.logout()
def __init__(self, host, login_account, login_password): self.rest_client = rest_client(base_url=host, \ username=login_account, password=login_password, \ default_prefix="/redfish/v1") self.rest_client.login(auth=AuthMethod.SESSION)
import sys import redfish # When running on the server locally use the following commented values # iLO_host = "blobstore://." # iLO_account = "None" # iLO_password = "******" # When running remotely connect using the iLO address, iLO account name, # and password to send https requests iLO_host = "https://10.0.0.100" login_account = "admin" login_password = "******" # Create a REST object REST_OBJ = redfish.rest_client(base_url=iLO_host,username=login_account, \ password=login_password) # Login into the server and create a session REST_OBJ.login(auth="session") # Do a GET on a given path response = REST_OBJ.get("/rest/v1/systems/1", None) # Print out the response sys.stdout.write("%s\n" % response) # Logout of the current session REST_OBJ.logout()