예제 #1
0
    def test_getid(self):
        self.assertEqual(4, base.getid(4))

        class TmpObject(object):
            id = 4

        self.assertEqual(4, base.getid(TmpObject))
예제 #2
0
 def get(self, image, member_id):
     image_id = base.getid(image)
     url = '/v1/images/%s/members/%s' % (image_id, member_id)
     resp, body = self.client.get(url)
     member = body['member']
     member['image_id'] = image_id
     return ImageMember(self, member, loaded=True)
예제 #3
0
 def delete(self, image, **kwargs):
     """Delete an image."""
     url = "/v1/images/%s" % base.getid(image)
     resp, body = self.client.delete(url)
     return_request_id = kwargs.get('return_req_id', None)
     if return_request_id is not None:
         return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))
예제 #4
0
 def delete(self, image, **kwargs):
     """Delete an image."""
     url = "/v1/images/%s" % base.getid(image)
     resp, body = self.client.delete(url)
     return_request_id = kwargs.get("return_req_id", None)
     if return_request_id is not None:
         return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))
예제 #5
0
 def _list_by_member(self, member):
     member_id = base.getid(member)
     url = '/v1/shared-images/%s' % member_id
     resp, body = self.client.get(url)
     out = []
     for member in body['shared_images']:
         member['member_id'] = member_id
         out.append(ImageMember(self, member, loaded=True))
     return out
예제 #6
0
 def _list_by_image(self, image):
     image_id = base.getid(image)
     url = '/v1/images/%s/members' % image_id
     resp, body = self.client.get(url)
     out = []
     for member in body['members']:
         member['image_id'] = image_id
         out.append(ImageMember(self, member, loaded=True))
     return out
예제 #7
0
    def get(self, image, **kwargs):
        """Get the metadata for a specific image.

        :param image: image object or id to look up
        :rtype: :class:`Image`
        """
        image_id = base.getid(image)
        resp, body = self.client.head("/v1/images/%s" % urlparse.quote(str(image_id)))
        meta = self._image_meta_from_headers(resp.headers)
        return_request_id = kwargs.get("return_req_id", None)
        if return_request_id is not None:
            return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))
        return Image(self, meta)
예제 #8
0
    def get(self, image, **kwargs):
        """Get the metadata for a specific image.

        :param image: image object or id to look up
        :rtype: :class:`Image`
        """
        image_id = base.getid(image)
        resp, body = self.client.head('/v1/images/%s' %
                                      urlparse.quote(str(image_id)))
        meta = self._image_meta_from_headers(resp.headers)
        return_request_id = kwargs.get('return_req_id', None)
        if return_request_id is not None:
            return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))
        return Image(self, meta)
예제 #9
0
 def replace(self, image, members):
     memberships = []
     for member in members:
         try:
             obj = {
                 'member_id': member.member_id,
                 'can_share': member.can_share,
             }
         except AttributeError:
             obj = {'member_id': member['member_id']}
             if 'can_share' in member:
                 obj['can_share'] = member['can_share']
         memberships.append(obj)
     url = '/v1/images/%s/members' % base.getid(image)
     self.client.put(url, data={'memberships': memberships})
예제 #10
0
    def data(self, image, do_checksum=True, **kwargs):
        """Get the raw data for a specific image.

        :param image: image object or id to look up
        :param do_checksum: Enable/disable checksum validation
        :rtype: iterable containing image data
        """
        image_id = base.getid(image)
        resp, body = self.client.get("/v1/images/%s" % urlparse.quote(str(image_id)))
        content_length = int(resp.headers.get("content-length", 0))
        checksum = resp.headers.get("x-image-meta-checksum", None)
        if do_checksum and checksum is not None:
            body = utils.integrity_iter(body, checksum)
        return_request_id = kwargs.get("return_req_id", None)
        if return_request_id is not None:
            return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))

        return utils.IterableWithLength(body, content_length)
예제 #11
0
파일: images.py 프로젝트: ziziwu/openstack
    def data(self, image, do_checksum=True, **kwargs):
        """Get the raw data for a specific image.

        :param image: image object or id to look up
        :param do_checksum: Enable/disable checksum validation
        :rtype: iterable containing image data
        """
        image_id = base.getid(image)
        resp, body = self.client.raw_request(
            'GET', '/v1/images/%s' % parse.quote(str(image_id)))
        checksum = resp.getheader('x-image-meta-checksum', None)
        if do_checksum and checksum is not None:
            body.set_checksum(checksum)
        return_request_id = kwargs.get('return_req_id', None)
        if return_request_id is not None:
            return_request_id.append(resp.getheader(OS_REQ_ID_HDR, None))

        return body
예제 #12
0
    def data(self, image, do_checksum=True, **kwargs):
        """Get the raw data for a specific image.

        :param image: image object or id to look up
        :param do_checksum: Enable/disable checksum validation
        :rtype: iterable containing image data
        """
        image_id = base.getid(image)
        resp, body = self.client.get('/v1/images/%s' %
                                     urlparse.quote(str(image_id)))
        checksum = resp.headers.get('x-image-meta-checksum', None)
        if do_checksum and checksum is not None:
            return utils.integrity_iter(body, checksum)
        return_request_id = kwargs.get('return_req_id', None)
        if return_request_id is not None:
            return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))

        return body
예제 #13
0
파일: images.py 프로젝트: ziziwu/openstack
    def update(self, image, **kwargs):
        """Update an image

        TODO(bcwaldon): document accepted params
        """
        image_data = kwargs.pop('data', None)
        if image_data is not None:
            image_size = utils.get_file_size(image_data)
            if image_size is not None:
                kwargs.setdefault('size', image_size)

        hdrs = {}
        purge_props = 'false'
        purge_props_bool = kwargs.pop('purge_props', None)
        if purge_props_bool:
            purge_props = 'true'

        hdrs['x-glance-registry-purge-props'] = purge_props
        fields = {}
        for field in kwargs:
            if field in UPDATE_PARAMS:
                fields[field] = kwargs[field]
            elif field == 'return_req_id':
                continue
            else:
                msg = 'update() got an unexpected keyword argument \'%s\''
                raise TypeError(msg % field)

        copy_from = fields.pop('copy_from', None)
        hdrs.update(self._image_meta_to_headers(fields))
        if copy_from is not None:
            hdrs['x-glance-api-copy-from'] = copy_from

        url = '/v1/images/%s' % base.getid(image)
        resp, body_iter = self.client.raw_request(
            'PUT', url, headers=hdrs, body=image_data)
        body = json.loads(''.join([c for c in body_iter]))
        return_request_id = kwargs.get('return_req_id', None)
        if return_request_id is not None:
            return_request_id.append(resp.getheader(OS_REQ_ID_HDR, None))

        return Image(self, self._format_image_meta_for_user(body['image']))
예제 #14
0
    def update(self, image, **kwargs):
        """Update an image

        TODO(bcwaldon): document accepted params
        """
        image_data = kwargs.pop("data", None)
        if image_data is not None:
            image_size = utils.get_file_size(image_data)
            if image_size is not None:
                kwargs.setdefault("size", image_size)

        hdrs = {}
        purge_props = "false"
        purge_props_bool = kwargs.pop("purge_props", None)
        if purge_props_bool:
            purge_props = "true"

        hdrs["x-glance-registry-purge-props"] = purge_props
        fields = {}
        for field in kwargs:
            if field in UPDATE_PARAMS:
                fields[field] = kwargs[field]
            elif field == "return_req_id":
                continue
            else:
                msg = "update() got an unexpected keyword argument '%s'"
                raise TypeError(msg % field)

        copy_from = fields.pop("copy_from", None)
        hdrs.update(self._image_meta_to_headers(fields))
        if copy_from is not None:
            hdrs["x-glance-api-copy-from"] = copy_from

        url = "/v1/images/%s" % base.getid(image)
        resp, body = self.client.put(url, headers=hdrs, data=image_data)
        return_request_id = kwargs.get("return_req_id", None)
        if return_request_id is not None:
            return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))

        return Image(self, self._format_image_meta_for_user(body["image"]))
예제 #15
0
    def update(self, image, **kwargs):
        """Update an image.

        TODO(bcwaldon): document accepted params
        """
        image_data = kwargs.pop('data', None)
        if image_data is not None:
            image_size = utils.get_file_size(image_data)
            if image_size is not None:
                kwargs.setdefault('size', image_size)

        hdrs = {}
        purge_props = 'false'
        purge_props_bool = kwargs.pop('purge_props', None)
        if purge_props_bool:
            purge_props = 'true'

        hdrs['x-glance-registry-purge-props'] = purge_props
        fields = {}
        for field in kwargs:
            if field in UPDATE_PARAMS:
                fields[field] = kwargs[field]
            elif field == 'return_req_id':
                continue
            else:
                msg = 'update() got an unexpected keyword argument \'%s\''
                raise TypeError(msg % field)

        copy_from = fields.pop('copy_from', None)
        hdrs.update(self._image_meta_to_headers(fields))
        if copy_from is not None:
            hdrs['x-glance-api-copy-from'] = copy_from

        url = '/v1/images/%s' % base.getid(image)
        resp, body = self.client.put(url, headers=hdrs, data=image_data)
        return_request_id = kwargs.get('return_req_id', None)
        if return_request_id is not None:
            return_request_id.append(resp.headers.get(OS_REQ_ID_HDR, None))

        return Image(self, self._format_image_meta_for_user(body['image']))
예제 #16
0
    def test_getid(self):
        self.assertEqual(4, base.getid(4))

        class TmpObject(object):
            id = 4
        self.assertEqual(4, base.getid(TmpObject))
예제 #17
0
 def create(self, image, member_id, can_share=False):
     """Creates an image."""
     url = '/v1/images/%s/members/%s' % (base.getid(image), member_id)
     body = {'member': {'can_share': can_share}}
     self.client.put(url, data=body)
예제 #18
0
파일: images.py 프로젝트: ziziwu/openstack
 def delete(self, image, **kwargs):
     """Delete an image."""
     resp = self._delete("/v1/images/%s" % base.getid(image))[0]
     return_request_id = kwargs.get('return_req_id', None)
     if return_request_id is not None:
         return_request_id.append(resp.getheader(OS_REQ_ID_HDR, None))