コード例 #1
0
    def print_out_iscsi_configuration(self,
                                      iscsiinitiatorname,
                                      devicealloc,
                                      pcideviceslist,
                                      disabled=False):
        """ Convert content to human readable and print out to std.out

        :param iscsiinitiatorname: iscsi initiator name
        :type iscsiinitiatorname: str.
        :param devicealloc: list of devices allocated
        :type devicealloc: list.
        :param pcideviceslist: current pci device list
        :type pcideviceslist: list.
        :param disabled: command line options
        :type disabled: boolean.
        """
        try:
            if iscsiinitiatorname is None:
                BootOrderMissingEntriesError(
                    'No entry found for the iscsi initiator name.\n\n')
            elif disabled:
                pass
            else:
                self.print_iscsi_config_helper(
                    iscsiinitiatorname["iSCSIInitiatorName"],
                    "\nIscsi Initiator Name: ")
        except Exception as excp:
            raise excp

        try:
            if devicealloc and pcideviceslist:
                if disabled:
                    self.rdmc.ui.printer(
                        "\nDisabled iSCSI Boot Network Interfaces: \n")
                    count = 'Disabled'
                else:
                    self.rdmc.ui.printer(
                        "Available iSCSI Boot Network Interfaces: \n")
                    count = 1

                for item in devicealloc:
                    for pcidevice in pcideviceslist:
                        if item["CorrelatableID"] == pcidevice[
                                "UEFIDevicePath"]:
                            self.rdmc.ui.printer("[%s] %s %s Port %s : %s\n" % \
                                (count, pcidevice["DeviceType"], pcidevice["DeviceInstance"],
                                 pcidevice["DeviceSubInstance"], pcidevice["Name"]))

                            if not disabled:
                                count += 1
            else:
                raise BootOrderMissingEntriesError(
                    'No entries found for'
                    ' iscsi configurations devices.\n')
        except Exception as excp:
            raise excp
コード例 #2
0
    def print_out_boot_order(self, content, onetimecontent, uefionetimecontent,\
                              bootmode, bootsources, bootstatus, targetstatus):
        """ Convert content to human readable and print out to std.out

        :param content: current content
        :type content: string.
        :param onetimecontent: list of one time boot entries
        :type onetimecontent: list.
        :param uefionetimecontent: list of uefi one time boot entries
        :type uefionetimecontent: list.
        :param bootmode: current system boot mode
        :type bootmode: string.
        :param bootsources: current systems boot sources
        :type bootsources: list.
        """
        if content is None:
            raise BootOrderMissingEntriesError("No entries found in " \
                                                "current boot order.\n\n")
        else:
            self.print_boot_helper(content, "\nCurrent Persistent Boot "\
                                   "Order:", bootsources=bootsources)

        bootstatusval = bootstatus['Boot']['BootSourceOverrideEnabled']
        boottoval = targetstatus['Boot']['BootSourceOverrideTarget']
        if bootstatusval == 'Continuous':
            sys.stdout.write(
                'Current continuous boot: {0}\n\n'.format(boottoval))
        elif bootstatusval == 'Once':
            sys.stdout.write(
                'Current one time boot: {0}\n\n'.format(boottoval))

        if onetimecontent is None:
            raise BootOrderMissingEntriesError(
                "No entries found for one time boot options.\n\n")
        else:
            self.print_boot_helper(onetimecontent["Boot"], \
                                   "Continuous and one time boot options:")

        if bootmode and any(
            [boot.get("BootMode", None) == "Uefi" for boot in bootmode]):
            if uefionetimecontent is None:
                sys.stdout.write(
                    "Continuous and one time boot uefi options:\n")
                sys.stdout.write("No entries found for one-time UEFI options or boot source mode "\
                                 "is not set to UEFI.")
            else:
                self.print_boot_helper(uefionetimecontent["Boot"], \
                           "Continuous and one time boot uefi options:", bootsources=bootsources)
コード例 #3
0
    def print_out_iscsi_configuration(self, iscsiinitiatorname, devicealloc, \
                                                pcideviceslist, disabled=False):
        """ Convert content to human readable and print out to std.out

        :param iscsiinitiatorname: iscsi initiator name
        :type iscsiinitiatorname: str.
        :param devicealloc: list of devices allocated
        :type devicealloc: list.
        :param pcideviceslist: current pci device list
        :type pcideviceslist: list.
        :param disabled: command line options
        :type disabled: boolean.
        """
        try:
            if iscsiinitiatorname is None:
                BootOrderMissingEntriesError(u'No entry found for the iscsi' \
                                                        ' initiator name.\n\n')
            elif disabled:
                pass
            else:
                self.print_iscsi_config_helper(\
                                   iscsiinitiatorname["iSCSIInitiatorName"], \
                                                    "\nIscsi Initiator Name: ")
        except Exception, excp:
            raise excp
コード例 #4
0
    def print_out_boot_order(self, content, onetimecontent, uefionetimecontent,\
                              bootmode, bootsources):
        """ Convert content to human readable and print out to std.out

        :param content: current content
        :type content: string.
        :param onetimecontent: list of one time boot entries
        :type onetimecontent: list.
        :param uefionetimecontent: list of uefi one time boot entries
        :type uefionetimecontent: list.
        :param bootmode: current system boot mode
        :type bootmode: string.
        :param bootsources: current systems boot sources
        :type bootsources: list.
        """
        try:
            if content is None:
                raise BootOrderMissingEntriesError(u"No entries found in " \
                                                    "current boot order.\n\n")
            else:
                self.print_boot_helper(content, "\nCurrent Persistent Boot "\
                                       "Order:", bootsources=bootsources)

            if onetimecontent is None:
                raise BootOrderMissingEntriesError(u"No entries found for one" \
                                                    " time boot options.\n\n")
            else:
                self.print_boot_helper(onetimecontent["Boot"], \
                                       "Continuous and one time boot options:")

            if bootmode and bootmode["BootMode"] == "Uefi":
                if uefionetimecontent is None:
                    raise BootOrderMissingEntriesError(u"No entries found for" \
                                                   " one-time UEFI options.")
                else:
                    self.print_boot_helper(uefionetimecontent["Boot"], \
                               "Continuous and one time boot uefi options:",\
                               bootsources=bootsources)
        except Exception, excp:
            raise excp
コード例 #5
0
    def listoptionhelper(self, options, iscsipath, iscsisettingspath, bootpath):
        """ Helper function to list options for iscsi

        :param options: command line options
        :type options: list.
        :param iscsipath: current iscsi path
        :type iscsipath: str.
        :param iscsisettingspath: current iscsi settings path
        :type iscsisettingspath: str.
        :param bootpath: current boot path
        :type bootpath: str.
        """
        self.selobj.selectfunction("HpBiosMapping.")
        pcisettingsmap = self.getobj.getworkerfunction(\
                                    "BiosPciSettingsMappings", options, \
                                    "BiosPciSettingsMappings", results=True,\
                                    uselist=True)

        devicealloc = list()
        for item in pcisettingsmap["BiosPciSettingsMappings"]:
            if "Associations" in item:
                if "EmbNicEnable" in item["Associations"] or \
                                        "EmbNicConfig" in item["Associations"]:
                    _ = [devicealloc.append(x) for x in item["Subinstances"]]

                for assoc in item["Associations"]:
                    if re.match("FlexLom[0-9]Enable", str(assoc)) or \
                                    re.match("PciSlot[0-9]Enable", str(assoc)):
                        _ = [devicealloc.append(x) for x in item["Subinstances"]]

        if self.typepath.defs.isgen10:
            newpcilist = []

            self.selobj.selectfunction("HpeServerPciDeviceCollection")
            pcideviceslist = self.getobj.getworkerfunction("Members", options, \
                                   "Members", results=True, uselist=False)

            for device in pcideviceslist["Members"]:
                newpcilist.append(self._rdmc.app.get_handler(\
                                         device['@odata.id'], silent=True).dict)

            pcideviceslist = newpcilist
        else:
            self.selobj.selectfunction(["Collection.", "--filter", \
                                            "MemberType=HpServerPciDevice."])
            pcideviceslist = self.getobj.getworkerfunction("Items", options, \
                            "Items", results=True, uselist=False)["Items"]

        self.selobj.selectfunction("HpiSCSISoftwareInitiator.")
        iscsibootsources = self.rawdatahandler(action="GET", silent=True, \
                        verbose=False, jsonflag=True, path=iscsisettingspath)
        structeredlist = list()

        self.pcidevicehelper(devicealloc, iscsipath, bootpath, pcideviceslist)

        for item in iscsibootsources[self.typepath.defs.iscsisource]:
            if item["iSCSINicSource"]:
                for device in devicealloc:
                    listval = 1 if isinstance(device["Associations"][0], dict) \
                                                                        else 0
                    if item["iSCSINicSource"] == \
                                                device["Associations"][listval]:
                        for pcidevice in pcideviceslist:
                            if device["CorrelatableID"] == \
                                                    pcidevice["UEFIDevicePath"]:
                                inputstring = pcidevice["DeviceType"] + " " + \
                                            str(pcidevice["DeviceInstance"]) + \
                                            " Port " + \
                                            str(pcidevice["DeviceSubInstance"])\
                                            + " : " + pcidevice["Name"]
                                structeredlist.append({inputstring: \
                                   {str("Attempt " + \
                                    str(item[self.typepath.defs.\
                                                    iscsiattemptinstance])): \
                                                    item}})
            else:
                structeredlist.append({"Not Added": {}})
        try:
            if iscsibootsources is None:
                raise BootOrderMissingEntriesError(u'No entries found for" \
                                                    " iscsi boot sources.\n\n')
            elif not options.filename:
                self.print_iscsi_config_helper(structeredlist, \
                                               "Current iSCSI Attempts: \n")
        except Exception, excp:
            raise excp
コード例 #6
0
                    count = 1

                for item in devicealloc:
                    for pcidevice in pcideviceslist:
                        if item["CorrelatableID"] == \
                                                    pcidevice["UEFIDevicePath"]:
                            sys.stdout.write("[%s] %s %s Port %s : %s\n" % \
                                         (count, pcidevice["DeviceType"], \
                                          pcidevice["DeviceInstance"], \
                                          pcidevice["DeviceSubInstance"], \
                                          pcidevice["Name"]))

                            if not disabled:
                                count += 1
            else:
                raise BootOrderMissingEntriesError(u'No entries found for' \
                                           ' iscsi configurations devices.\n')
        except Exception, excp:
            raise excp

    def print_iscsi_config_helper(self, content, outstring, indent=0):
        """ Print iscsi configuration helper

        :param content: current content to be output
        :type content: string.
        :param outstring: current output string
        :type outstring: str.
        :param indent: current iscsi settings path
        :type indent: str.
        """
        sys.stdout.write('\t' * indent + outstring)
コード例 #7
0
    def listoptionhelper(self, options, iscsipath, iscsisettingspath,
                         bootpath):
        """ Helper function to list options for iscsi

        :param options: command line options
        :type options: list.
        :param iscsipath: current iscsi path
        :type iscsipath: str.
        :param iscsisettingspath: current iscsi settings path
        :type iscsisettingspath: str.
        :param bootpath: current boot path
        :type bootpath: str.
        """
        self.auxcommands['select'].selectfunction("HpBiosMapping.")
        pcisettingsmap = next(
            iter(self.auxcommands['get'].getworkerfunction(
                "BiosPciSettingsMappings", options, results=True,
                uselist=True)), None)

        devicealloc = list()
        for item in pcisettingsmap["BiosPciSettingsMappings"]:
            if "Associations" in item:
                if "EmbNicEnable" in item[
                        "Associations"] or "EmbNicConfig" in item[
                            "Associations"]:
                    _ = [devicealloc.append(x) for x in item["Subinstances"]]

                if (re.match("FlexLom[0-9]+Enable", item["Associations"][0])
                        or re.match("PciSlot[0-9]+Enable",
                                    item["Associations"][0])
                        or re.match("Slot[0-9]+NicBoot[0-9]+",
                                    item["Associations"][0])):
                    _ = [devicealloc.append(x) for x in item["Subinstances"]]

        if self.rdmc.app.typepath.defs.isgen10:
            newpcilist = []

            self.auxcommands['select'].selectfunction(
                "HpeServerPciDeviceCollection")
            pcideviceslist = next(
                iter(self.auxcommands['get'].getworkerfunction("Members",
                                                               options,
                                                               results=True,
                                                               uselist=False)),
                None)

            for device in pcideviceslist["Members"]:
                newpcilist.append(
                    self.rdmc.app.get_handler(device['@odata.id'],
                                              silent=True).dict)

            pcideviceslist = newpcilist
        else:
            self.auxcommands['select'].selectfunction(["Collection."])
            pcideviceslist = next(
                iter(self.auxcommands['get'].getworkerfunction(
                    "Items",
                    options,
                    results=True,
                    uselist=False,
                    filtervals=("MemberType", "HpServerPciDevice.*"))),
                None)["Items"]

        self.auxcommands['select'].selectfunction("HpiSCSISoftwareInitiator.")
        iscsibootsources = self.rawdatahandler(action="GET",
                                               silent=True,
                                               jsonflag=True,
                                               path=iscsisettingspath)
        structeredlist = list()

        self.pcidevicehelper(devicealloc, iscsipath, bootpath, pcideviceslist)

        for item in iscsibootsources[self.rdmc.app.typepath.defs.iscsisource]:
            if item["iSCSINicSource"]:
                for device in devicealloc:
                    listval = 1 if isinstance(device["Associations"][0],
                                              dict) else 0
                    #self.rdmc.ui.printer("Compare1 '%s: %s'\n" % (item["iSCSINicSource"], device["Associations"][listval]))
                    if item["iSCSINicSource"] == device["Associations"][
                            listval]:
                        for pcidevice in pcideviceslist:
                            #self.rdmc.ui.printer("Compare2 '%s: %s'\n" % (device["CorrelatableID"],pcidevice["UEFIDevicePath"]))
                            #self.rdmc.ui.printer("Modified '%s'\n" % (str(pcidevice["UEFIDevicePath"])[: -2] + str('1)')))
                            if device["CorrelatableID"] == pcidevice[
                                    "UEFIDevicePath"]:
                                #self.rdmc.ui.printer("Match!!")
                                inputstring = pcidevice["DeviceType"] + " " + \
                                            str(pcidevice["DeviceInstance"]) + " Port " + \
                                            str(pcidevice["DeviceSubInstance"])\
                                            + " : " + pcidevice["Name"]
                                structeredlist.append({inputstring: {str("Attempt " + \
                                                str(item[self.rdmc.app.typepath.defs.iscsiattemptinstance])): item}})

            else:
                structeredlist.append({"Not Added": {}})
        try:
            if iscsibootsources is None:
                raise BootOrderMissingEntriesError(
                    'No entries found for iscsi boot sources.\n\n')
            elif not options.filename:
                self.print_iscsi_config_helper(structeredlist,
                                               "Current iSCSI Attempts: \n")
        except Exception as excp:
            raise excp

        if structeredlist is None:
            self.rdmc.ui.error('No entries found for iscsi boot sources.\n\n')
        elif options.filename:
            output = json.dumps(structeredlist,
                                indent=2,
                                cls=redfish.ris.JSONEncoder,
                                sort_keys=True)
            filehndl = open(options.filename[0], "w")
            filehndl.write(output)
            filehndl.close()

            self.rdmc.ui.printer("Results written out to '%s'\n" %
                                 options.filename[0])