class RevertScalablePmemConfigurationCommand(RdmcCommandBase): """ Main revertscalablepmemconfig command class """ def __init__(self, rdmcObj): RdmcCommandBase.__init__(self, \ name='revertscalablepmemconfig', \ usage='revertscalablepmemconfig\n\n'\ '\tDiscards any pending Scalable Persistent Memory configuration '\ 'changes.\n\n\texample: revertscalablepmemconfig', \ summary='Discard pending Scalable Persistent Memory configuration changes.',\ aliases=['spmem-revertcfg', 'spmem-undocfg', 'spmemrc'], \ optparser=OptionParser()) self._rdmc = rdmcObj self._helpers = Helpers() self._restHelpers = RestHelpers(self._rdmc) self._validator = LogicalNvdimmValidator() self._chif_lib = self._helpers.gethprestchifhandle() 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") def run(self, line): """ Wrapper function for the revert configuration command :param line: command line input :type line: string. """ LOGGER.info("Scalable PMEM: {}".format(self.name)) try: (options, _) = self._parse_arglist(line) except: if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") LOGGER.info("Options: {}".format(options)) if not self._chif_lib: self._helpers.failNoChifLibrary() self.revertPendingChanges() #Return code return ReturnCodes.SUCCESS
class EnableScalablePmemCommand(RdmcCommandBase): """ Enable Scalable Pmem command """ def __init__(self, rdmcObj): RdmcCommandBase.__init__(self, \ name='enablescalablepmem', \ usage='enablescalablepmem [OPTIONS]\n\n' \ '\tEnables or disables the Scalable Persistent Memory feature.\n'\ '\n\texample: enablescalablepmem', \ summary='Enable or disable the Scalable Persistent Memory feature.', \ aliases=['spmem-enable', 'spmemen'], \ optparser=OptionParser()) self.definearguments(self.parser) self._rdmc = rdmcObj self._helpers = Helpers() self._restHelpers = RestHelpers(self._rdmc) self._chif_lib = self._helpers.gethprestchifhandle() 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 run(self, line): """ Wrapper function for the Remove logical NVDIMM command :param line: command line input :type line: string. """ LOGGER.info("Scalable PMEM: {}".format(self.name)) try: (options, _) = self._parse_arglist(line) except: if ("-h" in line) or ("--help" in line): return ReturnCodes.SUCCESS else: raise InvalidCommandLineErrorOPTS("") if len(args): InvalidCommandLineError("This command takes no parameters.") LOGGER.info("Options: {}".format(options)) if not self._chif_lib: self._helpers.failNoChifLibrary() enable = True if options.enableFeature is False: enable = False self.enableOrDisableFeature(enable) #Return code return ReturnCodes.SUCCESS def definearguments(self, customparser): """ Define arguments for the command :param customparser: command line input :type customparser: parser. """ customparser.add_option( '--disable', action="store_false", dest="enableFeature", help="Disable the Scalable Persistent Memory feature. Warning: "\ "any pending configuration changes will be lost." )