Exemple #1
0
    def getgen(self, gen=None, url=None, username=None, password=None, logger=None,\
                                                    proxy=None, ca_certs=None, isredfish=True):
        """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.
        """

        if self.adminpriv is False and url.startswith("blob"):
            raise UserNotAdminError("")

        self.url = url
        self.is_redfish = isredfish
        self.gencompany = self.rootresp = False
        self.ilogen = 5  # If no iLO or Anonymous data , default to iLO 5 types
        logger = logger if not logger else LOGGER
        client = None
        self.noschemas = False
        self.schemapath = self.regpath = ''

        if not gen:
            try:
                client = RedfishClient(base_url=self.url, username=username, password=password,\
                                    proxy=proxy, ca_certs=ca_certs)
                client._get_root()
            except ServerDownOrUnreachableError as excp:
                if self.is_redfish:
                    raise excp
            if not self.is_redfish:
                try:
                    restclient = LegacyRestClient(base_url=self.url, username=username, \
                                    password=password, proxy=proxy, ca_certs=ca_certs)
                    restclient._get_root()
                    #Check that the response is actually legacy rest and not a redirect
                    _ = restclient.root.Type
                    self.is_redfish = False
                    client = restclient
                except Exception as excep:
                    if not client:
                        logger.info("Gen get rest error:" + str(excep) + "\n")
                        raise excep
                    else:
                        self.is_redfish = True

            rootresp = client.root.obj
            self.rootresp = rootresp
            client.logout()

            self.gencompany = next(iter(self.rootresp.get("Oem", {}).keys()),
                                   None) in ('Hpe', 'Hp')
            comp = 'Hp' if self.gencompany else None
            comp = 'Hpe' if rootresp.get("Oem", {}).get('Hpe', None) else comp
            if comp and next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\
                                                                        get('ManagerType', None):
                self.ilogen = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {})))\
                                                                                .get("ManagerType")
                self.ilover = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\
                                                                      get("ManagerFirmwareVersion")
                if self.ilogen.split(' ')[-1] == "CM":
                    # Assume iLO 4 types in Moonshot
                    self.ilogen = 4
                    self.iloversion = None
                else:
                    self.iloversion = float(self.ilogen.split(' ')[-1] + '.' + \
                                                    ''.join(self.ilover.split('.')))
        else:
            self.ilogen = int(gen)

        try:
            if not isinstance(self.ilogen, int):
                self.ilogen = int(self.ilogen.split(' ')[-1])
            self.flagiften = True if int(self.ilogen) >= 5 else False
        except:
            raise UnableToObtainIloVersionError(
                "Unable to find the iLO generation.")

        self.noschemas = True if self.rootresp and "JsonSchemas" in self.rootresp and not \
                                        self.rootresp.get("JsonSchemas", None) else False
        if self.noschemas:
            self.ilogen = self.ilover = self.iloversion = None
        if self.rootresp and not self.noschemas:
            self.defineregschemapath(self.rootresp)

        if self.flagiften:
            self.defs = Definevalstenplus()
        else:
            self.defs = DefinevalsNine()
Exemple #2
0
                response = restobj.get(entry["href"] + '?page=' + \
                            str(response.dict["links"]['NextPage']['page']))
                print_log_entries(response.dict["Items"])
    sys.stdout.write("%s" % response)

def print_log_entries(log_entries):
    for log_entry in log_entries:
        sys.stdout.write(log_entry["Message"] + "\n")

if __name__ == "__main__":
    # When running on the server locally use the following commented values
    # SYSTEM_URL = None
    # LOGIN_ACCOUNT = None
    # LOGIN_PASSWORD = None

    # When running remotely connect using the iLO secured (https://) address,
    # iLO account name, and password to send https requests
    # SYSTEM_URL acceptable examples:
    # "https://10.0.0.100"
    # "https://ilo.hostname"
    SYSTEM_URL = "https://10.0.0.100"
    LOGIN_ACCOUNT = "admin"
    LOGIN_PASSWORD = "******"

    #Create a REST object
    REST_OBJ = LegacyRestClient(base_url=SYSTEM_URL, username=LOGIN_ACCOUNT, password=LOGIN_PASSWORD)
    REST_OBJ.login()
    sys.stdout.write("\nEXAMPLE 23: Dump iLO Event Log\n")
    dump_ilo_event_log(REST_OBJ)
    REST_OBJ.logout()
Exemple #3
0
    def getgen(self, gen=None, url=None, username=None, password=None, logger=None,\
                proxy=None, ca_cert_data={}, isredfish=True):
        """Function designed to verify the servers platform. Will generate the `Typeandpathdefines`
        variables based on the system type that is detected.

        :param url: The URL to perform the request on.
        :type url: str
        :param username: The username to login with.
        :type username: str
        :param password: The password to login with.
        :type password: str
        :param proxy: The proxy to connect to the system with.
        :type proxy: str
        :param ca_certs: Dictionary including the TLS certificate information of user based
          authentication
        :type ca_certs: dict
        :param isredfish: The flag to force redfish conformance on iLO 4 systems. You will still
          need to call `updatedefinesflag` to update the defines to Redfish.
        :type isredfish: bool
        :param logger: The logger handler to log data too uses the default if none is provided.
        :type logger: str
        """

        if self.adminpriv is False and url.startswith("blob"):
            raise UserNotAdminError("")

        self.url = url
        self.is_redfish = isredfish
        self.gencompany = self.rootresp = False
        self.ilogen = 5  # If no iLO or Anonymous data , default to iLO 5 types
        logger = logger if not logger else LOGGER
        client = None
        self.noschemas = False
        self.schemapath = self.regpath = ''

        if not gen:
            try_count = 0
            try:
                client = RedfishClient(base_url=self.url, username=username, password=password,\
                                    proxy=proxy, ca_cert_data=ca_cert_data)
                client._get_root()
            except ServerDownOrUnreachableError as excp:
                if self.is_redfish:
                    raise excp
                try_count += 1
            if not self.is_redfish:
                try:
                    restclient = LegacyRestClient(base_url=self.url, username=username, \
                                    password=password, proxy=proxy, ca_cert_data=ca_cert_data)
                    restclient._get_root()
                    #Check that the response is actually legacy rest and not a redirect
                    _ = restclient.root.obj.Type
                    self.is_redfish = False
                    client = restclient
                except Exception as excp:
                    try_count += 1
                    if not client:
                        logger.info("Gen get rest error:" + str(excp) + "\n")
                        raise excp
                    else:
                        self.is_redfish = True

            if try_count > 1:
                raise ServerDownOrUnreachableError("Server not reachable or does not support "\
                                                   "HPRest or Redfish: %s\n" % str(excp))

            rootresp = client.root.obj
            self.rootresp = rootresp
            client.logout()

            self.gencompany = next(iter(self.rootresp.get("Oem", {}).keys()),
                                   None) in ('Hpe', 'Hp')
            comp = 'Hp' if self.gencompany else None
            comp = 'Hpe' if rootresp.get("Oem", {}).get('Hpe', None) else comp
            if comp and next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\
                                                                        get('ManagerType', None):
                self.ilogen = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {})))\
                                                                                .get("ManagerType")
                self.ilover = next(iter(rootresp.get("Oem", {}).get(comp, {}).get("Manager", {}))).\
                                                                      get("ManagerFirmwareVersion")
                if self.ilogen.split(' ')[-1] == "CM":
                    # Assume iLO 4 types in Moonshot
                    self.ilogen = 4
                    self.iloversion = None
                else:
                    self.iloversion = float(self.ilogen.split(' ')[-1] + '.' + \
                                                    ''.join(self.ilover.split('.')))
        else:
            self.ilogen = int(gen)

        try:
            if not isinstance(self.ilogen, int):
                self.ilogen = int(self.ilogen.split(' ')[-1])
            self.flagiften = True if int(self.ilogen) >= 5 else False
        except:
            raise UnableToObtainIloVersionError(
                "Unable to find the iLO generation.")

        self.noschemas = True if self.rootresp and "JsonSchemas" in self.rootresp and not \
                                        self.rootresp.get("JsonSchemas", None) else False
        if self.noschemas:
            self.ilogen = self.ilover = self.iloversion = None
        if self.rootresp and not self.noschemas:
            self.defineregschemapath(self.rootresp)

        if self.flagiften:
            self.defs = Definevalstenplus()
        else:
            self.defs = DefinevalsNine()