def post(self, run=False, **container_dict):
        """Create a new container.

        :param run: if true, starts the container
        :param container_dict: a container within the request body.
        """
        LOG.debug('providerregion post xxx run=%s, container_dict=%s', run,
                  container_dict)
        context = pecan.request.context
        compute_api = pecan.request.compute_api
        #LOG.debug('container py post xxx context=%s,compute_api=%s' % (context.to_dict(),dir(compute_api)))
        policy.enforce(context,
                       "providerregion:create",
                       action="providerregion:create")

        requested_networks = {}
        extra_spec = container_dict.get('hints', None)
        new_providerregion = objects.Providerregion(context, **container_dict)
        new_providerregion.create(context)
        compute_api.providerregion_create(context, new_providerregion,
                                          extra_spec, requested_networks)
        # Set the HTTP Location Header
        pecan.response.location = link.build_url('providerregions',
                                                 new_providerregion.uuid)
        pecan.response.status = 202
        LOG.debug('providerregion post xxx pecan.response.status=%s',
                  pecan.response.status)
        return view.format_container(pecan.request.host_url,
                                     new_providerregion)
 def convert_with_links(rpc_containers,
                        limit,
                        url=None,
                        expand=False,
                        **kwargs):
     collection = ContainerCollection()
     collection.providerregions = \
         [view.format_container(url, p) for p in rpc_containers]
     collection.next = collection.get_next(limit, url=url, **kwargs)
     return collection
    def patch(self, container_id, **patch):
        """Update an existing container.

        :param patch: a json PATCH document to apply to this container.
        """
        container = _get_container(container_id)
        check_policy_on_container(container.as_dict(), "providerregion:update")
        #utils.validate_container_state(container, 'update')
        context = pecan.request.context
        compute_api = pecan.request.compute_api
        container = compute_api.providerregion_update(context, container,
                                                      patch)
        return view.format_container(pecan.request.host_url, container)
    def rename(self, container_id, name):
        """rename an existing container.

        :param patch: a json PATCH document to apply to this container.
        """
        container = _get_container(container_id)
        check_policy_on_container(container.as_dict(), "providerregion:rename")
        if container.name == name:
            raise exception.Conflict('The new name for the container is the '
                                     'same as the old name.')
        container.name = name
        context = pecan.request.context
        container.save(context)
        return view.format_container(pecan.request.host_url, container)
    def get_one(self, container_id, **kwargs):
        """Retrieve information about the given container.

        :param container_ident: UUID or name of a container.
        """
        LOG.debug('providerregion get_one xxx container_id=%s, kwargs=%s',
                  container_id, kwargs)
        context = pecan.request.context
        if is_all_tenants(kwargs):
            policy.enforce(context,
                           "providerregion:get_one_all_tenants",
                           action="providerregion:get_one_all_tenants")
            context.all_tenants = True
        container = _get_container(container_id)
        check_policy_on_container(container.as_dict(),
                                  "providerregion:get_one")
        compute_api = pecan.request.compute_api
        container = compute_api.providerregion_show(context, container)
        LOG.debug('providerregion get_one xxx host_url=%s, dict=%s',
                  pecan.request.host_url, container.__dict__)
        return view.format_container(pecan.request.host_url, container)