def __get_boot_settings_dict_capabilities(sht): if 'capabilities' in sht and 'bootCapabilities' in sht: if 'ManageBootOrder' not in sht['capabilities']: raise HPOneViewInvalidResource('Error, server does not support managed boot order') allowed_boot = sht['bootCapabilities'] return allowed_boot else: raise HPOneViewInvalidResource('Error, can not retrieve server boot capabilities')
def make_boot_settings_dict(srv, sht, disable_manage_boot, boot_order, boot_mode, pxe): """ Create boot settings and boot mode dictionaries for use in defining either a server profile or server profile template. """ gen9 = False # Get the bootCapabilites from the Server Hardware Type allowed_boot = __get_boot_settings_dict_capabilities(sht) model = __get_boot_settings_dict_mode(sht) regx = re.compile('.*Gen9.*', re.IGNORECASE) gen_match = regx.match(model) if gen_match: gen9 = True # Managed Boot Enable with Boot Options specified if boot_order: __validate_allowed_boot(allowed_boot, boot_order) bootmode = __get_boot_settings_dict_boot_mode(gen9, boot_mode, pxe) boot = make_BootSettings(boot_order, manageBoot=True) # Managed Boot Default value WITHOUT Boot Options specified # Setting boot to None uses the default from the appliance which is # boot.manageBoot = True. elif not disable_manage_boot: bootmode = __get_boot_settings_dict_boot_mode(gen9, boot_mode, pxe) boot = None # Managed Boot explicitly disabled elif disable_manage_boot: # For a Gen 9 BL server hardware "boot.manageBoot" cannot be set to # true unless "bootMode" is specified and "bootMode.manageMode" is set # to 'true'. p = re.compile('.*BL\d.*', re.IGNORECASE) match = p.match(model) if match: raise HPOneViewInvalidResource( 'Error: bootMode cannot be disabled on BL servers') else: # bootmode can not be set for Gen 7 & 8 bootmode = None boot = make_BootSettings([], manageBoot=False) else: raise HPOneViewInvalidResource('Error: Unknown boot mode case') return boot, bootmode
def make_firmware_dict(settings, baseline): """ Create a firmware settings dictionary for use in defining either a server profile or server profile template. """ uri = '' if baseline: # The OneView appliance converts '.' in the filename to '_', except for # the final one baseline = baseline.replace('.', '_').replace('_iso', '.iso') spps = settings.get_spps() for spp in spps: if spp['isoFileName'] == baseline: uri = spp['uri'] if not uri: message = 'ERROR: Locating Firmware Baseline SPP\n Baseline: "%s" can not be located' % baseline raise HPOneViewInvalidResource(message) if uri: fw_settings = make_FirmwareSettingsV3(uri, 'FirmwareOnly', True, False) else: fw_settings = None return fw_settings
def __get_boot_settings_dict_mode(sht): if 'model' in sht: model = sht['model'] return model else: raise HPOneViewInvalidResource( 'Error: Can not identify server hardware type model')
def make_task_entity_tuple(self, obj): task = {} entity = {} if obj: if obj['category'] == 'tasks' or obj['category'] == 'backups': # it is an error if type is not in obj, so let the except flow uri = '' if obj['type'] == 'TaskResource': task = obj uri = obj['associatedResourceUri'] elif obj['type'] == 'TaskResourceV2': task = obj uri = obj['associatedResource']['resourceUri'] elif obj['type'] == 'BACKUP': task = self._con.get(obj['taskUri']) uri = obj['uri'] else: raise HPOneViewInvalidResource('Task resource is not a' ' recognized version') if uri: try: entity = self._con.get(uri) except HPOneViewException: raise else: entity = obj else: raise HPOneViewUnknownType('Unknown object type') return task, entity
def test_invalid_resource_exception_inheritance(self): exception = HPOneViewInvalidResource({'message': "A message string"}) self.assertEqual(exception.msg, "A message string") self.assertEqual(exception.oneview_response, {'message': "A message string"}) self.assertEqual(exception.args[0], "A message string") self.assertEqual(exception.args[1], {'message': 'A message string'})
def __validate_allowed_boot(allowed_boot, boot_order): # The FibreChannelHba boot option is not exposed to the user if 'FibreChannelHba' in allowed_boot: allowed_boot.remove('FibreChannelHba') if len(boot_order) != len(allowed_boot): message = 'Error: All supported boot options are required. The supported options are: ' + \ ('; '.join(allowed_boot)) raise HPOneViewInvalidResource(message) # Error if the users submitted and boot option that is # not supported by the server hardware type diff = set(boot_order).difference(set(allowed_boot)) if diff: message = 'Error: "' + ', '.join(diff) + '" are not supported boot options for this server hardware ' \ 'type. The supported options are: ' + '; '.join(allowed_boot) raise HPOneViewInvalidResource(message)
def update_net_ctvalues(self, xnet, bw={}): if not bw: return if not xnet: raise HPOneViewInvalidResource('Missing Network') defaultCT = self._con.get(xnet['connectionTemplateUri']) defaultCT['bandwidth']['maximumBandwidth'] = bw['maximumBandwidth'] defaultCT['bandwidth']['typicalBandwidth'] = bw['typicalBandwidth'] task, body = self._con.put(defaultCT['uri'], defaultCT) return self._activity.make_task_entity_tuple(task)
def make_local_storage_dict(sht, raidlevel, lboot, init_storage, num, drive_name): """ Create a local storage dictionary for use in defining either a server profile or server profile template. """ if 'model' in sht: model = sht['model'] else: raise HPOneViewInvalidResource('Error, can not retrieve server model') if raidlevel or init_storage: p = re.compile('.*DL\d.*', re.IGNORECASE) match = p.match(model) if match: raise HPOneViewInvalidResource( 'Local storage management is not supported on DL servers') # FIXME -- Add a test to verify that the number of physical drives # is consistent with the RAID level and the number of drives in the # server hardware type drives = [] drives.append( make_LogicalDriveV3(bootable=lboot, driveName=drive_name, driveTechnology=None, numPhysicalDrives=num, raidLevel=raidlevel)) controllers = [] controllers.append( make_LocalStorageEmbeddedController(importConfiguration=True, initialize=init_storage, LogicalDrives=drives, managed=True, mode='RAID')) local_storage = make_LocalStorageSettingsV3(controllers) return local_storage return None
def get_task_associated_resource(self, task): if not task: return {} if task['type'] == 'TaskResource': obj = self._con.get(task['associatedResourceUri']) tmp = { 'resourceName': obj['name'], 'associationType': None, 'resourceCategory': None, 'resourceUri': obj['uri']} elif task['type'] == 'TaskResourceV2': tmp = task['associatedResource'] else: raise HPOneViewInvalidResource('Task resource is not a recognized' ' version') return tmp
def get_associated_resource(self, task): """ Retrieve a resource associated with a task. Args: task: task dict Returns: tuple: task (updated), the entity found (dict) """ if not task: raise HPOneViewUnknownType(MSG_INVALID_TASK) if task['category'] != 'tasks' and task['category'] != 'backups': # it is an error if type is not in obj, so let the except flow raise HPOneViewUnknownType(MSG_UNKNOWN_OBJECT_TYPE) if task['type'] == 'TaskResourceV2': resource_uri = task['associatedResource']['resourceUri'] if resource_uri and resource_uri.startswith( "/rest/appliance/support-dumps/"): # Specific for support dumps return task, resource_uri elif task['type'] == 'BACKUP': task = self._connection.get(task['taskUri']) resource_uri = task['uri'] else: raise HPOneViewInvalidResource(MSG_TASK_TYPE_UNRECONIZED % task['type']) entity = {} if resource_uri: entity = self._connection.get(resource_uri) return task, entity