def _validate_key(key): if not key: raise exception.InvalidParameterValue( err='Invalid parameter: empty') if key.find('..') != -1: raise exception.InvalidParameterValue( err='Invalid parameter: must not contain ".."')
def _validate_section(cls, section): if not section: raise exception.InvalidParameterValue(err=_('Empty section')) if not cls._SECTION_VALIDATION.match(section): raise exception.InvalidParameterValue( err=_('Invalid section. Must begin and end with a slash, ' 'and contain valid characters')) if cls._SECTION_DOT_VALIDATION.match(section): raise exception.InvalidParameterValue( err=_('Invalid parameter: must not contain "." or ".." parts'))
def _validate_key(cls, key): if not isinstance(key, six.string_types): raise exception.InvalidParameterValue( err=_('Key must be a string')) if not cls._KEY_VALIDATION.match(key): raise exception.InvalidParameterValue( err=_('Only alphanumeric, underscore, dash, dots, at signs, ' 'and slashes are allowed. Key: "%s"') % key) if cls._KEY_DOT_VALIDATION.match(key): raise exception.InvalidParameterValue( err=_('Invalid parameter: must not contain "." or ".." parts'))
def get_bool_param(param_string, params): param = params.get(param_string, False) if not is_valid_boolstr(param): msg = _('Value %(param)s for %(param_string)s is not a ' 'boolean.') % {'param': param, 'param_string': param_string} raise exception.InvalidParameterValue(err=msg) return strutils.bool_from_string(param, strict=True)
def _trigger_execution_delete(cls, execution_id=None, trigger_id=None): if execution_id is None and trigger_id is None: raise exception.InvalidParameterValue('supply at least one id') ctxt = karbor_context.get_admin_context() num_deleted = db.trigger_execution_delete(ctxt, execution_id, trigger_id) return num_deleted > 0
def _normalize_marker_with_prefix(marker, prefix): if not isinstance(marker, six.string_types): raise exception.InvalidParameterValue( err=_('marker must be a string')) marker = prefix + marker res = os.path.normpath(marker) if marker.endswith('/'): res += '/' return res
def _prepend_prefix(self, key): if not isinstance(key, six.string_types): raise exception.InvalidParameterValue( err=_('Key must be a string')) full_key = self._prefix + key res = os.path.normpath(full_key) if full_key.endswith('/'): res += '/' return res
def get_flow(self, context, operation_type, checkpoint, provider, **kwargs): if operation_type == constants.OPERATION_PROTECT: plan = kwargs.get('plan', None) protectable_registry = kwargs.get('protectable_registry', None) flow = flow_protect.get_flow( context, protectable_registry, self.workflow_engine, plan, provider, checkpoint, ) elif operation_type == constants.OPERATION_RESTORE: restore = kwargs.get('restore') restore_auth = kwargs.get('restore_auth') flow = flow_restore.get_flow( context, self.workflow_engine, checkpoint, provider, restore, restore_auth, ) elif operation_type == constants.OPERATION_VERIFY: verify = kwargs.get('verify') flow = flow_verify.get_flow(context, self.workflow_engine, checkpoint, provider, verify) elif operation_type == constants.OPERATION_DELETE: flow = flow_delete.get_flow( context, self.workflow_engine, checkpoint, provider, ) elif operation_type == constants.OPERATION_COPY: plan = kwargs.get('plan', None) protectable_registry = kwargs.get('protectable_registry', None) checkpoint_collection = kwargs.get('checkpoint_collection', None) flow, checkpoint_copy = flow_copy.get_flows( context, protectable_registry, self.workflow_engine, plan, provider, checkpoint, checkpoint_collection, ) return flow, checkpoint_copy else: raise exception.InvalidParameterValue( err='unknown operation type %s' % operation_type) return flow
def __init__(self, config=None): super(GlanceProtectionPlugin, self).__init__(config) self._config.register_opts(image_backup_opts, 'image_backup_plugin') self._plugin_config = self._config.image_backup_plugin self._data_block_size_bytes = ( self._plugin_config.backup_image_object_size) self._poll_interval = self._plugin_config.poll_interval if self._data_block_size_bytes % 65536 != 0 or ( self._data_block_size_bytes <= 0): raise exception.InvalidParameterValue( err="The value of CONF.backup_image_object_size " "is invalid!")
def create(context, conf, **kwargs): conf.register_opts(nova_client_opts, group=CONFIG_GROUP) client_config = conf[CONFIG_GROUP] url = utils.get_url(SERVICE, context, client_config, append_project_fmt='%(url)s/%(project)s', **kwargs) LOG.debug('Creating nova client with url %s.', url) extensions = nc.discover_extensions(NOVACLIENT_VERSION) session = kwargs.get('session') if session is None: LOG.error('Creating nova client failed with url %s.', url) raise exception.InvalidParameterValue( err="The parameter session is None.") return nc.Client(NOVACLIENT_VERSION, extensions=extensions, session=kwargs.get('session'), endpoint_override=url)