Esempio n. 1
0
    def set_image_metadata_item(self,
                                image_id,
                                key,
                                value,
                                requestslib_kwargs=None):
        '''
        @summary: Sets a metadata item for a specified image
        @param image_id: Image ID
        @type image_id:String
        @param key: Key for which metadata item needs to be set
        @type key: String
        @param key: Value which the metadata key needs to be set to
        @type key: String
        @return: Metadata Item for the key on success
        @rtype:  Response object with metadata dictionary as entity
        '''

        url = '{base_url}/images/{image_id}/metadata/{meta_key}'.format(
            base_url=self.url, image_id=image_id, meta_key=key)
        metadata_item = MetadataItem({key: value})
        image_response = self.request('PUT',
                                      url,
                                      response_entity_type=MetadataItem,
                                      request_entity=metadata_item,
                                      requestslib_kwargs=requestslib_kwargs)
        return image_response
Esempio n. 2
0
    def setUpClass(cls):
        cls.meta_item = MetadataItem()
        cls.meta_item['key1'] = 'value1'

        cls.expected_xml = \
            ('<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
             '<meta key="key1">value1</meta>')
        cls.expected_json = json.dumps({'meta': {'key1': 'value1'}})
Esempio n. 3
0
    def set_server_metadata_item(self, server_id, key, value,
                                 requestslib_kwargs=None):
        """
        @summary: Sets a metadata item for a specified server
        @param server_id: server ID
        @type server_id:String
        @param key: Key for which metadata item needs to be set
        @type key: String
        @return: Metadata Item for the key on success
        @rtype:  Requests.response
        """

        url = '{base_url}/servers/{server_id}/metadata/{meta_key}'.format(
            base_url=self.url, server_id=server_id, meta_key=key)
        request = MetadataItem({key: value})
        resp = self.request('PUT', url,
                            request_entity=request,
                            response_entity_type=MetadataItem,
                            requestslib_kwargs=requestslib_kwargs)
        return resp
Esempio n. 4
0
 def test_metadata_json_deserialization(self):
     meta = MetadataItem.deserialize(self.expected_json, 'json')
     self.assertIsNotNone(meta)
     self.assertEqual(meta.get('key1'), 'value1')
Esempio n. 5
0
 def test_metadata_json_deserialization(self):
     meta = MetadataItem.deserialize(self.expected_json, 'json')
     self.assertIsNotNone(meta)
     self.assertEqual(meta.get('key1'), 'value1')