Example #1
0
    def create(self, session, prepend_key=True, base_path=None):
        """Create a remote resource based on this instance.

        :param session: The session to use for making this request.
        :type session: :class:`~keystoneauth1.adapter.Adapter`
        :param prepend_key: A boolean indicating whether the resource_key
                            should be prepended in a resource creation
                            request. Default to True.
        :param str base_path: Base part of the URI for creating resources, if
                              different from
                              :data:`~openstack.resource.Resource.base_path`.
        :return: This :class:`Resource` instance.
        :raises: :exc:`~openstack.exceptions.MethodNotSupported` if
                 :data:`Resource.allow_create` is not set to ``True``.
        """
        if not self.allow_create:
            raise exceptions.MethodNotSupported(self, "create")

        session = self._get_session(session)
        microversion = self._get_microversion_for(session, 'create')
        # Create ZoneImport requires empty body and 'text/dns' as content-type
        # skip _prepare_request completely, since we need just empty body
        request = resource._Request(
            self.base_path,
            None,
            {'content-type': 'text/dns'}
        )
        response = session.post(request.url,
                                json=request.body, headers=request.headers,
                                microversion=microversion)

        self.microversion = microversion
        self._translate_response(response)
        return self
Example #2
0
    def _prepare_request(self, requires_id=None, prepend_key=False,
                         patch=False, base_path=None, params=None, **kwargs):
        """Prepare a request to be sent to the server

        Create operations don't require an ID, but all others do,
        so only try to append an ID when it's needed with
        requires_id. Create and update operations sometimes require
        their bodies to be contained within an dict -- if the
        instance contains a resource_key and prepend_key=True,
        the body will be wrapped in a dict with that key.
        If patch=True, a JSON patch is prepared instead of the full body.

        Return a _Request object that contains the constructed URI
        as well a body and headers that are ready to send.
        Only dirty body and header contents will be returned.
        """
        if requires_id is None:
            requires_id = self.requires_id

        body = self._prepare_request_body(patch, prepend_key)
        headers = {}

        if base_path is None:
            base_path = self.base_path
        uri = base_path % self._uri.attributes
        if requires_id:
            if self.id is None:
                raise exceptions.InvalidRequest(
                    "Request requires an ID but none was found")

            uri = utils.urljoin(uri, self.id)

        uri = utils.urljoin(self.location.project['id'], uri)

        return resource._Request(uri, body, headers)
Example #3
0
    def _prepare_request(self, requires_id=True, prepend_key=True):
        """Prepare a request for the database service's create call

        User.create calls require the resources_key.
        The base_prepare_request would insert the resource_key (singular)
        """
        body = {self.resources_key: self._body.dirty}

        uri = self.base_path % self._uri.attributes
        uri = utils.urljoin(uri, self.id)

        return resource._Request(uri, body, None)
Example #4
0
    def _prepare_request(self, requires_id=True, prepend_key=True,
                         base_path=None):
        """Prepare a request for the database service's create call

        User.create calls require the resources_key.
        The base_prepare_request would insert the resource_key (singular)
        """
        body = {self.resources_key: self._body.dirty}

        if base_path is None:
            base_path = self.base_path

        uri = base_path % self._uri.attributes
        uri = utils.urljoin(uri, self.id)

        return resource._Request(uri, body, None)
    def _prepare_request(self, requires_id=None, prepend_key=False):
        """Prepare a request to be sent to the server

        Create operations don't require an ID, but all others do,
        so only try to append an ID when it's needed with
        requires_id. Create and update operations sometimes require
        their bodies to be contained within an dict -- if the
        instance contains a resource_key and prepend_key=True,
        the body will be wrapped in a dict with that key.

        Return a _Request object that contains the constructed URI
        as well a body and headers that are ready to send.
        Only dirty body and header contents will be returned.
        """
        if requires_id is None:
            requires_id = self.requires_id

        body = None
        # body = self._body.dirty
        # if prepend_key and self.resource_key is not None:
        #     body = {self.resource_key: body}

        # if self.name:
        #     body['Bucket'] = self.name

        base_path = '/'
        headers = {}
        uri = base_path % self._uri.attributes
        if requires_id:
            if self.id is None:
                raise exceptions.InvalidRequest(
                    "Request requires an ID but none was found")

            uri = utils.urljoin(uri, self.id)

        return resource._Request(uri, body, headers)