Example #1
0
    def pcidevicehelper(self,
                        devicealloc,
                        iscsipath,
                        bootpath,
                        pcideviceslist=None,
                        options=None):
        """ Helper function to check for extra pci devices / identify disabled devices

        :param devicealloc: list of devices allocated
        :type devicealloc: list.
        :param iscsipath: current iscsi path
        :type iscsipath: str.
        :param bootpath: current boot path
        :type bootpath: str.
        :param pcideviceslist: current pci device list
        :type pcideviceslist: list.
        :param options: command line options
        :type options: list.
        """
        if not pcideviceslist:
            if self.typepath.defs.isgen10:
                newpcilist = []
                self.selobj.selectfunction("HpeServerPciDeviceCollection")
                pcideviceslist = next(iter(self.getobj.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.selobj.selectfunction(["Collection."])
                pcideviceslist = next(iter(self.getobj.getworkerfunction("Items", \
                       options, results=True, uselist=False, filtervals=("MemberType", \
                                                            "HpServerPciDevice.*"))), None)["Items"]
        try:
            self.rawdatahandler(action="GET", silent=True, \
                            jsonflag=True, path=iscsipath)['iSCSINicSources']
        except:
            raise NicMissingOrConfigurationError(
                'No iSCSI nic sources available.')

        _ = [x['UEFIDevicePath'] for x in pcideviceslist]
        removal = list()

        bios = self.rawdatahandler(action="GET",
                                   silent=True,
                                   jsonflag=True,
                                   path=bootpath)

        for item in devicealloc:
            if item['Associations'] and item['Associations'][0] in bios.keys():
                if bios[item['Associations'][0]] == 'Disabled':
                    removal.append(item)

        _ = [devicealloc.remove(x) for x in removal]

        return removal
    def addoptionhelper(self, options, iscsipath, iscsisettingspath, bootpath):
        """ Helper function to add option 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.
        """
        devicealloc = list()
        self.selobj.selectfunction("HpBiosMapping.")
        pcisettingsmap = self.getobj.getworkerfunction(\
                        "BiosPciSettingsMappings", options, \
                        "BiosPciSettingsMappings", results=True, uselist=True)

        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"]]

        self.selobj.selectfunction("HpiSCSISoftwareInitiator.")
        self.validateinput(deviceallocsize=len(devicealloc), options=options)

        foundlocation = False
        iscsibootsources = self.rawdatahandler(action="GET", silent=True, \
                           verbose=False, jsonflag=True, path=iscsisettingspath)

        count = 0
        attemptinstancenumber = self.bootattemptcounter(iscsibootsources\
                                            [self.typepath.defs.iscsisource])
        self.pcidevicehelper(devicealloc, iscsipath, bootpath, options=options)

        for item in iscsibootsources[self.typepath.defs.iscsisource]:
            try:
                if not item[self.typepath.defs.iscsiattemptinstance]:
                    nicsourcedata = devicealloc[int(options.add[1:-1])-1]\
                                                                ["Associations"]
                    iscsibootsources[self.typepath.defs.iscsisource][count]\
                    ["iSCSINicSource"] = nicsourcedata[1] if \
                        isinstance(nicsourcedata[0], dict) else nicsourcedata[0]
                    iscsibootsources[self.typepath.defs.iscsisource][count]\
                            [self.typepath.defs.iscsiattemptinstance] = \
                                                        attemptinstancenumber
                    iscsibootsources[self.typepath.defs.iscsisource][count]\
                        [self.typepath.defs.iscsiattemptname] = \
                                                    str(attemptinstancenumber)
                    foundlocation = True
                    break
            except Exception:
                raise NicMissingOrConfigurationError("Invalid input value for "\
                                                            "configuring NIC.")
            count += 1

        if foundlocation:
            self._rdmc.app.patch_handler(iscsisettingspath, iscsibootsources, \
                                         optionalpassword=options.biospassword)
        else:
            raise NicMissingOrConfigurationError("Failed to add NIC. All NICs" \
                                             " have already been configured.")
    def addoptionhelper(self, options, iscsipath, iscsisettingspath, bootpath):
        """ Helper function to add option 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.
        """
        devicealloc = list()
        self.auxcommands['select'].selectfunction("HpBiosMapping.")
        pcisettingsmap = next(
            iter(self.auxcommands['get'].getworkerfunction(
                "BiosPciSettingsMappings", options, results=True,
                uselist=True)), None)

        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"]]

        foundlocation = False
        iscsibootsources = self.rawdatahandler(action="GET", silent=True, \
                                               jsonflag=True, path=iscsisettingspath)
        count = 0
        attemptinstancenumber = self.bootattemptcounter(iscsibootsources \
                                                            [self.rdmc.app.typepath.defs.iscsisource])
        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"]

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

        devicealloc_final = self.make_final_list(devicealloc, pcideviceslist)

        for item in iscsibootsources[self.rdmc.app.typepath.defs.iscsisource]:
            try:
                if not item[self.rdmc.app.typepath.defs.iscsiattemptinstance]:
                    nicsourcedata = devicealloc_final[int(options.add) -
                                                      1]["Associations"]

                    iscsibootsources[self.rdmc.app.typepath.defs.iscsisource][count]\
                    ["iSCSINicSource"] = nicsourcedata[1] if \
                        isinstance(nicsourcedata[0], dict) else nicsourcedata[0]

                    iscsibootsources[self.rdmc.app.typepath.defs.iscsisource][count]\
                            [self.rdmc.app.typepath.defs.iscsiattemptinstance] = attemptinstancenumber
                    iscsibootsources[self.rdmc.app.typepath.defs.iscsisource][count]\
                        [self.rdmc.app.typepath.defs.iscsiattemptname] = str(attemptinstancenumber)
                    foundlocation = True
                    break
            except Exception:
                raise NicMissingOrConfigurationError(
                    "Invalid input value for configuring NIC.")
            count += 1

        if foundlocation:
            self.rdmc.app.patch_handler(iscsisettingspath,
                                        iscsibootsources,
                                        optionalpassword=options.biospassword)
        else:
            raise NicMissingOrConfigurationError(
                "Failed to add NIC. All NICs"
                " have already been configured.")