def _get_target(self, context, target): """Processes and validates the CLI given target and adapts it for policy authorization. :returns: None if the given target is None, otherwise returns a proper authorization target. :raises nova.exception.InvalidAttribute: if a key in the given target is not an acceptable. :raises nova.exception.InstanceNotFound: if 'instance_id' is given, and there is no instance match the id. """ if not target: return None new_target = {} for t in target: key, value = t.split('=') if key not in self._ACCEPTABLE_TARGETS: raise exception.InvalidAttribute(attr=key) new_target[key] = value # if the target is an instance_id, return an instance instead. instance_id = new_target.get('instance_id') if instance_id: admin_ctxt = nova_context.get_admin_context() instance = db.instance_get_by_uuid(admin_ctxt, instance_id) new_target = { 'user_id': instance['user_id'], 'project_id': instance['project_id'] } return new_target
def _build_complex_type(self, key, attrs, flavor): """If a key does not directly map, this method derives the right value. Some types are complex, in that the flavor may have one key that maps to several different attributes in the lpar builder. This method handles the complex types. :param key: The flavor's key. :param attrs: The attribute map to put the value into. :param flavor: The Nova instance flavor. :return: The value to put in for the key. """ # Map uncapped to sharing mode if key == self._PVM_UNCAPPED: is_uncapped = self._flavor_bool(flavor.extra_specs[key], key) shar_mode = (pvm_bp.SharingMode.UNCAPPED if is_uncapped else pvm_bp.SharingMode.CAPPED) attrs[lpar_bldr.SHARING_MODE] = shar_mode elif key == self._PVM_DED_SHAR_MODE: # Dedicated sharing modes...map directly mode = self._DED_SHARING_MODES_MAP.get( flavor.extra_specs[key]) if mode is not None: attrs[lpar_bldr.SHARING_MODE] = mode else: attr = key + '=' + flavor.extra_specs[key] exc = exception.InvalidAttribute(attr=attr) LOG.error(exc) raise exc elif key == self._PVM_SHAR_PROC_POOL: pool_name = flavor.extra_specs[key] attrs[lpar_bldr.SPP] = self._spp_pool_id(pool_name) elif key == self._PVM_PROC_COMPAT: # Handle variants of the supported values attrs[lpar_bldr.PROC_COMPAT] = re.sub( r'\+', '_Plus', flavor.extra_specs[key]) elif key == self._PVM_SRR_CAPABILITY: srr_cap = self._flavor_bool(flavor.extra_specs[key], key) attrs[lpar_bldr.SRR_CAPABLE] = srr_cap else: # There was no mapping or we didn't handle it. exc = exception.InvalidAttribute(attr=key) LOG.error(exc) raise exc
def _is_pvm_valid_key(self, key): """Will return if this is a valid PowerVM key. :param key: The powervm key. :return: True if valid key. False if non-powervm key and should be skipped. Raises an InvalidAttribute exception if is an unknown PowerVM key. """ # If not a powervm key, then it is not 'pvm_valid' if not key.startswith('powervm:'): return False # Check if this is a valid attribute if key not in self._ATTRS_MAP.keys(): exc = exception.InvalidAttribute(attr=key) raise exc return True