Ejemplo n.º 1
0
    def _get_host_collection(self, **kwargs):
        context = pecan.request.context
        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', 'availability_zone')
        expand = kwargs.get('expand')
        marker_obj = None
        resource_url = kwargs.get('resource_url')
        marker = kwargs.get('marker')
        if marker:
            marker_obj = objects.ZunService.get_by_uuid(context, marker)
        services = objects.ZunService.list(context,
                                           limit,
                                           marker_obj,
                                           sort_key,
                                           sort_dir)
        zones = {}
        for service in services:
            zones[service.availability_zone] = service
        return AvailabilityZoneCollection.convert_with_links(zones.values(),
                                                             limit,
                                                             url=resource_url,
                                                             expand=expand,
                                                             sort_key=sort_key,
                                                             sort_dir=sort_dir)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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)
Ejemplo n.º 4
0
    def _get_images_collection(self, **kwargs):
        context = pecan.request.context
        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.Image.get_by_uuid(context, marker)
        images = objects.Image.list(context,
                                    limit,
                                    marker_obj,
                                    sort_key,
                                    sort_dir,
                                    filters=filters)
        for i, c in enumerate(images):
            try:
                images[i] = pecan.request.compute_api.image_show(context, c)
            except Exception as e:
                LOG.exception(
                    _LE("Error while list image %(uuid)s: "
                        "%(e)s."), {
                            'uuid': c.uuid,
                            'e': e
                        })

        return ImageCollection.convert_with_links(images,
                                                  limit,
                                                  url=resource_url,
                                                  expand=expand,
                                                  sort_key=sort_key,
                                                  sort_dir=sort_dir)
Ejemplo n.º 5
0
    def _get_containers_collection(self, **kwargs):
        context = pecan.request.context
        LOG.debug('xxx _get_containers_collection started')
        if is_all_tenants(kwargs):
            LOG.debug('xxx _get_containers_collection true kwargs=%s', kwargs)
            policy.enforce(context, "carrier:get_all_all_tenants",
                           action="carrier:get_all_all_tenants")
            context.all_tenants = True
        compute_api = pecan.request.compute_api
        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.Carrier.list(context,
                                            limit,
                                            marker_obj,
                                            sort_key,
                                            sort_dir,
                                            filters=filters)
        xx=ContainerCollection.convert_with_links(containers, limit,
                                                      url=resource_url,
                                                      expand=expand,
                                                      sort_key=sort_key,
                                                      sort_dir=sort_dir)
        #LOG.debug('container post xxx containers=%s, xx=%s', containers, xx.__dict__)
        return xx
Ejemplo n.º 6
0
    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)
Ejemplo n.º 7
0
 def test_validate_sort_dir(self):
     self.assertEqual('asc', utils.validate_sort_dir('asc'))
     self.assertEqual('desc', utils.validate_sort_dir('desc'))
     with self.assertRaisesRegexp(wsme.exc.ClientSideError,
                                  "Invalid sort direction"):
         utils.validate_sort_dir(None)
     with self.assertRaisesRegexp(wsme.exc.ClientSideError,
                                  "Invalid sort direction"):
         utils.validate_sort_dir('abc')
Ejemplo n.º 8
0
 def test_validate_sort_dir(self):
     self.assertEqual('asc', utils.validate_sort_dir('asc'))
     self.assertEqual('desc', utils.validate_sort_dir('desc'))
     with self.assertRaisesRegex(exception.InvalidValue,
                                 "Invalid sort direction"):
         utils.validate_sort_dir(None)
     with self.assertRaisesRegex(exception.InvalidValue,
                                 "Invalid sort direction"):
         utils.validate_sort_dir('abc')
Ejemplo n.º 9
0
 def test_validate_sort_dir(self):
     self.assertEqual('asc', utils.validate_sort_dir('asc'))
     self.assertEqual('desc', utils.validate_sort_dir('desc'))
     with self.assertRaisesRegex(exception.InvalidValue,
                                 "Invalid sort direction"):
         utils.validate_sort_dir(None)
     with self.assertRaisesRegex(exception.InvalidValue,
                                 "Invalid sort direction"):
         utils.validate_sort_dir('abc')
Ejemplo n.º 10
0
    def _get_containers_collection(self, **kwargs):
        context = pecan.request.context
        all_tenants = kwargs.get('all_tenants')
        if all_tenants:
            try:
                all_tenants = strutils.bool_from_string(all_tenants, True)
            except ValueError as err:
                raise exception.InvalidInput(six.text_type(err))
        else:
            # If no value, it's considered to disable all_tenants
            all_tenants = False
        if all_tenants:
            context.all_tenants = True
        compute_api = pecan.request.compute_api
        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)

        for i, c in enumerate(containers):
            try:
                containers[i] = compute_api.container_show(context, c)
            except Exception as e:
                LOG.exception(("Error while list container %(uuid)s: "
                               "%(e)s."), {
                                   'uuid': c.uuid,
                                   'e': e
                               })
                containers[i].status = consts.UNKNOWN

        return ContainerCollection.convert_with_links(containers,
                                                      limit,
                                                      url=resource_url,
                                                      expand=expand,
                                                      sort_key=sort_key,
                                                      sort_dir=sort_dir)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    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)
Ejemplo n.º 13
0
    def _get_containers_collection(self, **kwargs):
        context = pecan.request.context
        if is_all_tenants(kwargs):
            policy.enforce(context, "container:get_all_all_tenants",
                           action="container:get_all_all_tenants")
            context.all_tenants = True
        compute_api = pecan.request.compute_api
        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)

        for i, c in enumerate(containers):
            try:
                containers[i] = compute_api.container_show(context, c)
            except Exception as e:
                LOG.exception(("Error while list container %(uuid)s: "
                               "%(e)s."),
                              {'uuid': c.uuid, 'e': e})
                containers[i].status = consts.UNKNOWN

        return ContainerCollection.convert_with_links(containers, limit,
                                                      url=resource_url,
                                                      expand=expand,
                                                      sort_key=sort_key,
                                                      sort_dir=sort_dir)
Ejemplo n.º 14
0
    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)
Ejemplo n.º 15
0
 def _get_host_collection(self, **kwargs):
     context = pecan.request.context
     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', 'hostname')
     expand = kwargs.get('expand')
     filters = None
     marker_obj = None
     resource_url = kwargs.get('resource_url')
     marker = kwargs.get('marker')
     if marker:
         marker_obj = objects.ComputeNode.get_by_uuid(context, marker)
     nodes = objects.ComputeNode.list(context,
                                      limit,
                                      marker_obj,
                                      sort_key,
                                      sort_dir,
                                      filters=filters)
     return HostCollection.convert_with_links(nodes, limit,
                                              url=resource_url,
                                              expand=expand,
                                              sort_key=sort_key,
                                              sort_dir=sort_dir)
Ejemplo n.º 16
0
 def _get_images_collection(self, **kwargs):
     context = pecan.request.context
     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.Image.get_by_uuid(context, marker)
     images = objects.Image.list(context,
                                 limit,
                                 marker_obj,
                                 sort_key,
                                 sort_dir,
                                 filters=filters)
     return ImageCollection.convert_with_links(images, limit,
                                               url=resource_url,
                                               expand=expand,
                                               sort_key=sort_key,
                                               sort_dir=sort_dir)