コード例 #1
0
    def test_getid(self):
        self.assertEqual(base.getid(4), 4)

        class TmpObject(object):
            id = 4

        self.assertEqual(base.getid(TmpObject), 4)
コード例 #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.api.json_request('GET', url)
     member = body['member']
     member['image_id'] = image_id
     return ImageMember(self, member, loaded=True)
コード例 #3
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 = self._get_file_size(image_data)
            if image_size != 0:
                kwargs.setdefault('size', image_size)
            else:
                image_data = None

        fields = {}
        for field in kwargs:
            if field in UPDATE_PARAMS:
                fields[field] = kwargs[field]
            else:
                msg = 'update() got an unexpected keyword argument \'%s\''
                raise TypeError(msg % field)

        copy_from = fields.pop('copy_from', None)
        hdrs = 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.api.put(url, headers=hdrs, body=image_data)
        return Image(self, body['image'])
コード例 #4
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 = self._get_file_size(image_data)
            if image_size != 0:
                kwargs.setdefault('size', image_size)
            else:
                image_data = None

        fields = {}
        for field in kwargs:
            if field in UPDATE_PARAMS:
                fields[field] = kwargs[field]
            else:
                msg = 'update() got an unexpected keyword argument \'%s\''
                raise TypeError(msg % field)

        copy_from = fields.pop('copy_from', None)
        hdrs = 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.api.raw_request(
                'PUT', url, headers=hdrs, body=image_data)
        return Image(self, json.loads(body)['image'])
コード例 #5
0
 def _list_by_member(self, member):
     member_id = base.getid(member)
     resp, body = self.api.get('/v1/shared-images/%s' %  member_id)
     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)
     resp, body = self.api.get('/v1/images/%s/members' %  image_id)
     out = []
     for member in body['members']:
         member['image_id'] = image_id
         out.append(ImageMember(self, member, loaded=True))
     return out
コード例 #7
0
ファイル: images.py プロジェクト: bhuvan/python-glanceclient
    def data(self, image):
        """Get the raw data for a specific image.

        :param image: image object or id to look up
        :rtype: iterable containing image data
        """
        image_id = base.getid(image)
        resp, body = self.api.raw_request('GET', '/v1/images/%s' % image_id)
        return body
コード例 #8
0
    def data(self, image):
        """Get the raw data for a specific image.

        :param image: image object or id to look up
        :rtype: iterable containing image data
        """
        image_id = base.getid(image)
        resp, body = self.api.raw_request('GET', '/v1/images/%s' % image_id)
        return body
コード例 #9
0
 def _list_by_image(self, image):
     image_id = base.getid(image)
     url = '/v1/images/%s/members' % image_id
     resp, body = self.api.json_request('GET', url)
     out = []
     for member in body['members']:
         member['image_id'] = image_id
         out.append(ImageMember(self, member, loaded=True))
     return out
コード例 #10
0
 def _list_by_member(self, member):
     member_id = base.getid(member)
     url = '/v1/shared-images/%s' % member_id
     resp, body = self.api.json_request('GET', url)
     out = []
     for member in body['shared_images']:
         member['member_id'] = member_id
         out.append(ImageMember(self, member, loaded=True))
     return out
コード例 #11
0
    def get(self, image):
        """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.api.raw_request("HEAD", "/v1/images/%s" % urllib.quote(image_id))
        meta = self._image_meta_from_headers(dict(resp.getheaders()))
        return Image(self, meta)
コード例 #12
0
    def get(self, image):
        """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.api.raw_request('HEAD', '/v1/images/%s'
                                          % urllib.quote(image_id))
        meta = self._image_meta_from_headers(dict(resp.getheaders()))
        return Image(self, meta)
コード例 #13
0
ファイル: images.py プロジェクト: wputra/MOS-centos
    def data(self, image, do_checksum=True):
        """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.api.raw_request('GET', '/v1/images/%s'
                                          % urllib.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 body
コード例 #14
0
    def data(self, image, do_checksum=True):
        """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.api.raw_request('GET', '/v1/images/%s'
                                          % urllib.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 body
コード例 #15
0
    def data(self, image, do_checksum=True):
        """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.api.raw_request("GET", "/v1/images/%s" % urllib.quote(image_id))
        checksum = resp.getheader("x-image-meta-checksum", None)
        if do_checksum and checksum is not None:
            return utils.integrity_iter(body, checksum)
        else:
            return body
コード例 #16
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.api.json_request('PUT', url, {}, {'memberships': memberships})
コード例 #17
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.api.raw_request('HEAD', '/v1/images/%s'
                                          % parse.quote(str(image_id)))
        meta = self._image_meta_from_headers(dict(resp.getheaders()))
        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, meta)
コード例 #18
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 = {}
        try:
            purge_props = 'true' if kwargs.pop('purge_props') else 'false'
        except KeyError:
            pass
        else:
            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.api.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']))
コード例 #19
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 = self._get_file_size(image_data)
            if image_size is not None:
                kwargs.setdefault("size", image_size)

        hdrs = {}
        try:
            purge_props = "true" if kwargs.pop("purge_props") else "false"
        except KeyError:
            pass
        else:
            hdrs["x-glance-registry-purge-props"] = purge_props

        fields = {}
        for field in kwargs:
            if field in UPDATE_PARAMS:
                fields[field] = kwargs[field]
            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.api.raw_request("PUT", url, headers=hdrs, body=image_data)
        body = json.loads("".join([c for c in body_iter]))
        return Image(self, self._format_image_meta_for_user(body["image"]))
コード例 #20
0
 def delete(self, image):
     """Delete an image."""
     self._delete("/v1/images/%s" % base.getid(image))
コード例 #21
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._update(url, body=body)
コード例 #22
0
 def delete(self, image, **kwargs):
     """Delete an image."""
     resp = self._delete("/v1/images/%s" % base.getid(image))
     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))
コード例 #23
0
    def test_getid(self):
        self.assertEqual(4, base.getid(4))

        class TmpObject(object):
            id = 4
        self.assertEqual(4, base.getid(TmpObject))