def _get_capsules_collection(self, **kwargs): context = pecan.request.context if utils.is_all_projects(kwargs): context.all_projects = True limit = api_utils.validate_limit(kwargs.get('limit')) sort_dir = api_utils.validate_sort_dir(kwargs.get('sort_dir', 'asc')) sort_key = kwargs.get('sort_key', 'id') resource_url = kwargs.get('resource_url') expand = kwargs.get('expand') filters = None marker_obj = None marker = kwargs.get('marker') if marker: marker_obj = objects.Capsule.get_by_uuid(context, marker) capsules = objects.Capsule.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) return CapsuleCollection.convert_with_links(capsules, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_containers_collection(self, **kwargs): context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "container:get_all_all_projects", action="container:get_all_all_projects") context.all_projects = True limit = api_utils.validate_limit(kwargs.get('limit')) sort_dir = api_utils.validate_sort_dir(kwargs.get('sort_dir', 'asc')) sort_key = kwargs.get('sort_key', 'id') resource_url = kwargs.get('resource_url') expand = kwargs.get('expand') filters = None marker_obj = None marker = kwargs.get('marker') if marker: marker_obj = objects.Container.get_by_uuid(context, marker) containers = objects.Container.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) if not context.is_admin: for container in containers: del container.host return ContainerCollection.convert_with_links(containers, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _do_get_all(self, legacy_api_version=False, **kwargs): context = pecan.request.context policy.enforce(context, "capsule:get_all", action="capsule:get_all") if utils.is_all_projects(kwargs): context.all_projects = True limit = api_utils.validate_limit(kwargs.get('limit')) sort_dir = api_utils.validate_sort_dir(kwargs.get('sort_dir', 'asc')) sort_key = kwargs.get('sort_key', 'id') resource_url = kwargs.get('resource_url') expand = kwargs.get('expand') filters = None marker_obj = None marker = kwargs.get('marker') if marker: marker_obj = objects.Capsule.get_by_uuid(context, marker) capsules = objects.Capsule.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) return CapsuleCollection.convert_with_links( capsules, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir, legacy_api_version=legacy_api_version)
def delete(self, container_ident, force=False, **kwargs): """Delete a container. :param container_ident: UUID or Name of a container. :param force: If True, allow to force delete the container. """ context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "container:delete_all_projects", action="container:delete_all_projects") context.all_projects = True container = utils.get_container(container_ident) check_policy_on_container(container.as_dict(), "container:delete") try: force = strutils.bool_from_string(force, strict=True) except ValueError: bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS) raise exception.InvalidValue(_('Valid force values are: %s') % bools) stop = kwargs.pop('stop', False) try: stop = strutils.bool_from_string(stop, strict=True) except ValueError: bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS) raise exception.InvalidValue(_('Valid stop values are: %s') % bools) compute_api = pecan.request.compute_api if not force and not stop: utils.validate_container_state(container, 'delete') elif force and not stop: api_utils.version_check('force', '1.7') policy.enforce(context, "container:delete_force", action="container:delete_force") utils.validate_container_state(container, 'delete_force') elif stop: api_utils.version_check('stop', '1.12') check_policy_on_container(container.as_dict(), "container:stop") utils.validate_container_state(container, 'delete_after_stop') if container.status == consts.RUNNING: LOG.debug('Calling compute.container_stop with %s ' 'before delete', container.uuid) compute_api.container_stop(context, container, 10) container.status = consts.DELETING if container.host: compute_api.container_delete(context, container, force) else: container.destroy(context) pecan.response.status = 204
def delete(self, capsule_ident, **kwargs): """Delete a capsule. :param capsule_ident: UUID or Name of a capsule. """ context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "capsule:delete_all_projects", action="capsule:delete_all_projects") context.all_projects = True capsule = _get_capsule(capsule_ident) check_policy_on_capsule(capsule.as_dict(), "capsule:delete") compute_api = pecan.request.compute_api capsule.task_state = consts.CONTAINER_DELETING capsule.save(context) compute_api.capsule_delete(context, capsule) pecan.response.status = 204
def delete(self, capsule_ident, **kwargs): """Delete a capsule. :param capsule_ident: UUID or Name of a capsule. """ context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "capsule:delete_all_projects", action="capsule:delete_all_projects") context.all_projects = True capsule = _get_capsule(capsule_ident) check_policy_on_capsule(capsule.as_dict(), "capsule:delete") compute_api = pecan.request.compute_api capsule.task_state = consts.CONTAINER_DELETING capsule.save(context) compute_api.container_stop(context, capsule, 10) compute_api.container_delete(context, capsule) pecan.response.status = 204
def _get_containers_collection(self, **kwargs): context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "container:get_all_all_projects", action="container:get_all_all_projects") context.all_projects = True kwargs.pop('all_projects', None) limit = api_utils.validate_limit(kwargs.pop('limit', None)) sort_dir = api_utils.validate_sort_dir(kwargs.pop('sort_dir', 'asc')) sort_key = kwargs.pop('sort_key', 'id') resource_url = kwargs.pop('resource_url', None) expand = kwargs.pop('expand', None) container_allowed_filters = ['name', 'image', 'project_id', 'user_id', 'memory', 'host', 'task_state', 'status', 'auto_remove'] filters = {} for filter_key in container_allowed_filters: if filter_key in kwargs: policy_action = policies.CONTAINER % ('get_one:' + filter_key) context.can(policy_action, might_not_exist=True) filter_value = kwargs.pop(filter_key) filters[filter_key] = filter_value marker_obj = None marker = kwargs.pop('marker', None) if marker: marker_obj = objects.Container.get_by_uuid(context, marker) if kwargs: unknown_params = [str(k) for k in kwargs] msg = _("Unknown parameters: %s") % ", ".join(unknown_params) raise exception.InvalidValue(msg) containers = objects.Container.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) return ContainerCollection.convert_with_links(containers, limit, url=resource_url, expand=expand, sort_key=sort_key, sort_dir=sort_dir)
def _get_registries_collection(self, **kwargs): context = pecan.request.context if utils.is_all_projects(kwargs): policy_action = policies.REGISTRY % 'get_all_all_projects' policy.enforce(context, policy_action, action=policy_action) context.all_projects = True kwargs.pop('all_projects', None) limit = api_utils.validate_limit(kwargs.pop('limit', None)) sort_dir = api_utils.validate_sort_dir(kwargs.pop('sort_dir', 'asc')) sort_key = kwargs.pop('sort_key', 'id') resource_url = kwargs.pop('resource_url', None) registry_allowed_filters = [ 'name', 'domain', 'username', 'project_id', 'user_id' ] filters = {} for filter_key in registry_allowed_filters: if filter_key in kwargs: policy_action = policies.REGISTRY % ('get_one:' + filter_key) context.can(policy_action, might_not_exist=True) filter_value = kwargs.pop(filter_key) filters[filter_key] = filter_value marker_obj = None marker = kwargs.pop('marker', None) if marker: marker_obj = objects.Registry.get_by_uuid(context, marker) if kwargs: unknown_params = [str(k) for k in kwargs] msg = _("Unknown parameters: %s") % ", ".join(unknown_params) raise exception.InvalidValue(msg) registries = objects.Registry.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) return RegistryCollection.convert_with_links(registries, limit, url=resource_url, sort_key=sort_key, sort_dir=sort_dir)
def get_one(self, container_ident, **kwargs): """Retrieve information about the given container. :param container_ident: UUID or name of a container. """ context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "container:get_one_all_projects", action="container:get_one_all_projects") context.all_projects = True container = utils.get_container(container_ident) check_policy_on_container(container.as_dict(), "container:get_one") if container.host: compute_api = pecan.request.compute_api try: container = compute_api.container_show(context, container) except exception.ContainerHostNotUp: raise exception.ServerNotUsable return view.format_container(context, pecan.request.host_url, container)
def _get_registries_collection(self, **kwargs): context = pecan.request.context if utils.is_all_projects(kwargs): policy_action = policies.REGISTRY % 'get_all_all_projects' policy.enforce(context, policy_action, action=policy_action) context.all_projects = True kwargs.pop('all_projects', None) limit = api_utils.validate_limit(kwargs.pop('limit', None)) sort_dir = api_utils.validate_sort_dir(kwargs.pop('sort_dir', 'asc')) sort_key = kwargs.pop('sort_key', 'id') resource_url = kwargs.pop('resource_url', None) registry_allowed_filters = ['name', 'domain', 'username', 'project_id', 'user_id'] filters = {} for filter_key in registry_allowed_filters: if filter_key in kwargs: policy_action = policies.REGISTRY % ('get_one:' + filter_key) context.can(policy_action, might_not_exist=True) filter_value = kwargs.pop(filter_key) filters[filter_key] = filter_value marker_obj = None marker = kwargs.pop('marker', None) if marker: marker_obj = objects.Registry.get_by_uuid(context, marker) if kwargs: unknown_params = [str(k) for k in kwargs] msg = _("Unknown parameters: %s") % ", ".join(unknown_params) raise exception.InvalidValue(msg) registries = objects.Registry.list(context, limit, marker_obj, sort_key, sort_dir, filters=filters) return RegistryCollection.convert_with_links(registries, limit, url=resource_url, sort_key=sort_key, sort_dir=sort_dir)
def delete(self, capsule_ident, **kwargs): """Delete a capsule. :param capsule_ident: UUID or Name of a capsule. """ context = pecan.request.context if utils.is_all_projects(kwargs): policy.enforce(context, "capsule:delete_all_projects", action="capsule:delete_all_projects") context.all_projects = True capsule = api_utils.get_resource('Capsule', capsule_ident) check_policy_on_capsule(capsule.as_dict(), "capsule:delete") compute_api = pecan.request.compute_api capsule.task_state = consts.CONTAINER_DELETING capsule.save(context) if capsule.host: compute_api.container_delete(context, capsule) else: merged_containers = capsule.containers + capsule.init_containers for container in merged_containers: container.destroy(context) capsule.destroy(context) pecan.response.status = 204