Exemplo n.º 1
0
    def common_setup(self):
        """ function to get the config setup """
        scalable_pmem_config = ScalablePersistentMemoryConfig(self._restHelpers, \
                                                 self._validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # pre-validation
        self._helpers.validateAllConfigurationPolicies(scalable_pmem_config)

        return scalable_pmem_config
Exemplo n.º 2
0
    def showLogicalNvdimmConfig(self, options):
        """ Main showlogicalnvdimmconfig command worker function

        :param options: command options
        :type options: options.
        """

        if self._rdmc.app.config._ac__format.lower() == 'json':
            options.json = True         #pragma: no cover

        validator = LogicalNvdimmValidator()

        scalable_pmem_config = ScalablePersistentMemoryConfig(self._restHelpers,\
                                                     validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # overall config status
        self._helpers.validateAllConfigurationPolicies(scalable_pmem_config, \
                                                    output_as_json=options.json)

        if options.available:
            if not options.json:
                self._helpers.writeHeader2(u"Available Scalable Persistent Memory")
                sys.stdout.write("Available capacity to create logical NVDIMMs "\
                                 "is constrained by the system\n hardware, including"\
                                 " the number of backup storage devices selected.\n")

            self._helpers.displayAvailableCapacity(scalable_pmem_config, \
                                                   output_as_json=options.json)
        else:
            if not options.json:
                # overall config enabled and capacity graph
                self._helpers.writeHeader2(u"Overall Allocated Scalable Persistent Memory")
                sys.stdout.write(u"\n")
                self._helpers.displayOverallCapacityBarGraph(scalable_pmem_config, 60)
                self._helpers.printBackupBootTimeMessage(scalable_pmem_config)
                if len(scalable_pmem_config.drives.selectedDrives) == 0:
                    sys.stdout.write("* No backup storage devices have been selected")
                sys.stdout.write(u"\n")
                # allocated logical nvdimms
                self._helpers.writeHeader2(u"Logical NVDIMMs")
            self._helpers.displayRegionConfiguration(scalable_pmem_config, \
                                                     output_as_json=options.json, \
                                                     print_backup_time_message=False)

        sys.stdout.write(u"\n\n")
    def showDriveData(self):
        """ Main showlogicalnvdimmdrives command worker function

        :param options: command options
        :type options: options.
        """

        helpers = Helpers()
        restHelpers = RestHelpers(self._rdmc)
        validator = LogicalNvdimmValidator()

        scalable_pmem_config = ScalablePersistentMemoryConfig(restHelpers, \
                                                    validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # pre-validation
        self._helpers.validateFeatureIsSupported(scalable_pmem_config)

        helpers.writeHeader2(
            u"Scalable Persistent Memory Backup Storage Devices")
        helpers.displayDrivesConfiguration(scalable_pmem_config)
        sys.stdout.write(u"\n")
    def enableOrDisableFeature(self, enable):
        """ Enables or disables the feature

        :param enable: a flag whether to enable or disable the feature
        :type enable: boolean
        """

        validator = LogicalNvdimmValidator()

        scalable_pmem_config = ScalablePersistentMemoryConfig(self._restHelpers,\
                                                     validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # pre-validation
        self._helpers.validateFeatureIsSupported(scalable_pmem_config)
        self._helpers.validateFunctionalityIsEnabled(scalable_pmem_config)

        if enable is False:
            # If user disables Scalable PMEM, revert any pending changes to
            # prevent data or configuration loss
            if self._rdmc.interactive:
                message = u"Warning: disabling Scalable Persistent Memory will "\
                                    "revert any pending configuration changes.\n"
                self._helpers.confirmChanges(message=message)
            self._restHelpers.revertSettings()

        patchAttributes = {
            "FeatureEnabled" : enable
        }
        _ = self._restHelpers.patchScalablePmemSettingAttributes(patchAttributes)

        sys.stdout.write(u"\nThe Scalable Persistent Memory feature has been "\
                    "set to: {}\n".format("Enabled" if enable else "Disabled"))

        self._helpers.noticeRestartRequired(scalable_pmem_config)

        sys.stdout.write("\n\n")
    def removeRegion(self, options):
        """ Removes the Logical NVDIMM specified

        :param socketIdx: the socket of the NUMA region, or None for Non-NUMA
        :type socketIdx: string or int

        :param regionIdx: the index of the region
        :type regionIdx: string or int
        """

        validator = LogicalNvdimmValidator()

        scalable_pmem_config = ScalablePersistentMemoryConfig(self._restHelpers,\
                                                     validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # pre-validation
        self._helpers.validateAllConfigurationPolicies(scalable_pmem_config)

        matchingRegion = None
        if options.processorPair:
            matchingPair = next((p for _, p in scalable_pmem_config.regions.\
                                 socketPairs.items() if p.labelString == options.\
                                                            processorPair), None)
            if matchingPair:
                matchingRegion = matchingPair.nonNumaRegion
        else:
            matchingSocket = next((s for _, s in scalable_pmem_config.regions.\
                                   sockets.items() if s.labelString == options.\
                                                        processorNumber), None)
            if matchingSocket:
                matchingRegion = matchingSocket.numaRegions.get(options.index)

        if matchingRegion and matchingRegion.isConfigured:
            if self._rdmc.interactive:
                if matchingRegion.isActivelyConfigured:
                    self._helpers.confirmBeforeConfigCausesDataLoss(scalable_pmem_config)

            patchAttributes = {
                matchingRegion.settingName : 0
            }
            _ = self._restHelpers.patchScalablePmemSettingAttributes(patchAttributes)
        else:
            self._helpers.displayRegionConfiguration(scalable_pmem_config)
            raise InvalidCommandLineError(u"Unable to identify an existing logical NVDIMM")

        # display the new state
        scalable_pmem_config.refresh()
        self._helpers.displayRegionConfiguration(scalable_pmem_config)
        sys.stdout.write(u"\n")
Exemplo n.º 6
0
    def revertPendingChanges(self):
        """ Reverts any pending changes """

        scalable_pmem_config = ScalablePersistentMemoryConfig(self._restHelpers,\
                                             self._validator, self._chif_lib)
        scalable_pmem_config.refresh()

        self._restHelpers.revertSettings()

        scalable_pmem_config.refresh()

        self._helpers.writeHeader2(u"Logical NVDIMMs")
        self._helpers.displayRegionConfiguration(scalable_pmem_config)
        self._helpers.writeHeader2(
            u"Scalable Persistent Memory Backup Storage Devices")
        self._helpers.displayDrivesConfiguration(scalable_pmem_config)

        sys.stdout.write("\n\n")
Exemplo n.º 7
0
    def run(self, line):
        """ Runs the command.

        :param line: command line input
        :type line: string
        """
        try:
            (_, args) = self._parse_arglist(line)
        except:
            if ("-h" in line) or ("--help" in line):
                return ReturnCodes.SUCCESS
            else:
                raise InvalidCommandLineErrorOPTS("")

        if not args or len(args) != 2:
            self.print_help()
            sys.stdout.write("\n")
            raise InvalidCommandLineError(u"OLD-ID and NEW-ID must be specified")

        if len(args) != len(set(args)):
            raise InvalidCommandLineError(u"Duplicate device IDs specified")

        if not self._chif_lib:
            self._helpers.failNoChifLibrary()

        scalable_pmem_config = ScalablePersistentMemoryConfig(self._rest_helpers,\
                                                 self._validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # pre-validation
        self._helpers.validateFeatureIsSupported(scalable_pmem_config)
        self._helpers.validateFeatureEnabledByUser(scalable_pmem_config)

        try:
            old_drive, new_drive = scalable_pmem_config.drives.findDrives(args)
        except ValueError as excp:
            raise InvalidCommandLineError(u"Invalid device ID: {}".format(excp))

        self.replace_drive(scalable_pmem_config, old_drive, new_drive)

        scalable_pmem_config.refresh()
        self._helpers.displayDrivesConfiguration(scalable_pmem_config)

        return ReturnCodes.SUCCESS
Exemplo n.º 8
0
    def autoselectdrives(self, pmem_size_GiB, confirm):
        """ function to perform the automatic selection of backup drives

        :param pmem_size_GiB: requested scalable persistent memory size
        :type pmem_size_GiB: int

        :param confirm: whether or not to automatically confirm the selected drives
        :type confirm: Boolean
        """

        scalable_pmem_config = ScalablePersistentMemoryConfig(self._restHelpers,\
                                             self._validator, self._chif_lib)
        scalable_pmem_config.refresh()

        # pre-validation
        self._helpers.validateAllConfigurationPolicies(scalable_pmem_config)

        # make sure this is an un-configured system
        if scalable_pmem_config.isConfiguredSystem:
            raise InvalidCommandLineError(u"This operation is not supported on "\
                                                        "a configured system")

        # get policies
        policies = resolve_pointer(scalable_pmem_config.config_resource, \
                                                    "/Attributes/Policy", None)
        sameModel = False
        sameSize = False
        if policies:
            sameModel = policies.get("SameModelNVMe", False)
            sameSize = policies.get("SameSizeNVMe", False)

        # separate the supported drives into supported groups, based on model or size
        # if same model or size, then order doesn't matter; else the
        # drives should be sorted largest to smallest
        supported_drives_groups = self.sort_drives(sameModel, sameSize, \
                                    scalable_pmem_config.drives.supportedDrives)

        # loop through the group until a valid config is found or all drives
        # have been tested
        isValid = False
        i = 0
        num_groups = len(supported_drives_groups)
        while not isValid and i < num_groups:
            drive_group = supported_drives_groups[i]
            drivesToUse = []
            for drive in drive_group:
                drivesToUse.append(drive)
                # calculate the maximum supported by the new configuration,
                # which may be different from the requested capacity
                max_pmem_supported = self._validator.calculateMaxPmemGiB(\
                        self._chif_lib, scalable_pmem_config.config_resource, \
                        drivesToUse)
                if max_pmem_supported >= pmem_size_GiB:
                    # check drive policies
                    (isValidDrivePolicies, _) = self._validator.\
                            checkLogicalNvdimmDrivePolicies(scalable_pmem_config.\
                            config_resource, drivesToUse)
                    if isValidDrivePolicies:
                        isValid = True
                        break
            i += 1

        if not isValid:
            # TODO: more info? maybe build a list of reasons why certain drives will not work
            raise InvalidCommandLineError(u"Requested size of {} GiB is not "\
                                          "supported by the installed backup "\
                                          "devices".format(pmem_size_GiB))

        # get a list of the drives to show to the user
        summary_drive_list = ["{:15} ({} GB)".format(d.formattedLocation, \
                                                d.sizeGB) for d in drivesToUse]

        # Make sure the user confirms the changes
        sys.stdout.write(u"\nThe following backup devices have been "\
                                "automatically selected for Scalable PMEM:\n")
        self._helpers.printLimitedMessageList(summary_drive_list, 99)
        sys.stdout.write(u"\n")

        if not confirm:
            if self._rdmc.interactive:
                # TODO: timeout
                s = raw_input(
                    u"\nConfirm changes? Y(y) to confirm. N(n) to cancel: ")
                if s == 'y' or s == 'Y':
                    confirm = True
                else:
                    raise NoChangesFoundOrMadeError(
                        u"No changes have been made")
            else:
                raise NoChangesFoundOrMadeError(u"No changes have been made.  "\
                                    "To confirm the changes, specify --confirm")

        if confirm:
            # if all is valid, configure the related BIOS setting
            self._restHelpers.setDrives(new_drives=drivesToUse)
            #self._restHelpers.enableConfiguration()
            scalable_pmem_config.refresh()
            self._helpers.displayDrivesConfiguration(scalable_pmem_config)