Esempio n. 1
0
 def _format_image_from_db(self, db_image, db_tags):
     visibility = 'public' if db_image['is_public'] else 'private'
     properties = {}
     for prop in db_image.pop('properties'):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop['deleted']:
             properties[prop['name']] = prop['value']
     locations = db_image['locations']
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         ld = []
         for l in locations:
             url = crypt.urlsafe_decrypt(key, l['url'])
             ld.append({'url': url, 'metadata': l['metadata']})
         locations = ld
     return glance.domain.Image(
         image_id=db_image['id'],
         name=db_image['name'],
         status=db_image['status'],
         created_at=db_image['created_at'],
         updated_at=db_image['updated_at'],
         visibility=visibility,
         min_disk=db_image['min_disk'],
         min_ram=db_image['min_ram'],
         protected=db_image['protected'],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image['checksum'],
         owner=db_image['owner'],
         disk_format=db_image['disk_format'],
         container_format=db_image['container_format'],
         size=db_image['size'],
         virtual_size=db_image['virtual_size'],
         extra_properties=properties,
         tags=db_tags
     )
Esempio n. 2
0
 def _format_image_from_db(self, db_image, db_tags):
     visibility = 'public' if db_image['is_public'] else 'private'
     properties = {}
     for prop in db_image.pop('properties'):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop['deleted']:
             properties[prop['name']] = prop['value']
     locations = db_image['locations']
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         ld = []
         for l in locations:
             url = crypt.urlsafe_decrypt(key, l['url'])
             ld.append({'url': url, 'metadata': l['metadata']})
         locations = ld
     return glance.domain.Image(
         image_id=db_image['id'],
         name=db_image['name'],
         status=db_image['status'],
         created_at=db_image['created_at'],
         updated_at=db_image['updated_at'],
         visibility=visibility,
         min_disk=db_image['min_disk'],
         min_ram=db_image['min_ram'],
         protected=db_image['protected'],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image['checksum'],
         owner=db_image['owner'],
         disk_format=db_image['disk_format'],
         container_format=db_image['container_format'],
         size=db_image['size'],
         virtual_size=db_image['virtual_size'],
         extra_properties=properties,
         tags=db_tags)
Esempio n. 3
0
 def _format_image_from_db(self, db_image, db_tags):
     properties = {}
     for prop in db_image.pop('properties'):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop['deleted']:
             properties[prop['name']] = prop['value']
     locations = [
         loc for loc in db_image['locations'] if loc['status'] == 'active'
     ]
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         for l in locations:
             l['url'] = crypt.urlsafe_decrypt(key, l['url'])
     #利用数据库中查询到的数据,填充Image对象
     return glance.domain.Image(
         image_id=db_image['id'],
         name=db_image['name'],
         status=db_image['status'],
         created_at=db_image['created_at'],
         updated_at=db_image['updated_at'],
         visibility=db_image['visibility'],
         min_disk=db_image['min_disk'],
         min_ram=db_image['min_ram'],
         protected=db_image['protected'],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image['checksum'],
         owner=db_image['owner'],
         disk_format=db_image['disk_format'],
         container_format=db_image['container_format'],
         size=db_image['size'],
         virtual_size=db_image['virtual_size'],
         extra_properties=properties,
         tags=db_tags)
Esempio n. 4
0
 def _format_image_from_db(self, db_image, db_tags):
     properties = {}
     for prop in db_image.pop('properties'):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop['deleted']:
             properties[prop['name']] = prop['value']
     locations = [loc for loc in db_image['locations']
                  if loc['status'] == 'active']
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         for l in locations:
             l['url'] = crypt.urlsafe_decrypt(key, l['url'])
     return glance.domain.Image(
         image_id=db_image['id'],
         name=db_image['name'],
         status=db_image['status'],
         created_at=db_image['created_at'],
         updated_at=db_image['updated_at'],
         visibility=db_image['visibility'],
         min_disk=db_image['min_disk'],
         min_ram=db_image['min_ram'],
         protected=db_image['protected'],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image['checksum'],
         os_hash_algo=db_image['os_hash_algo'],
         os_hash_value=db_image['os_hash_value'],
         owner=db_image['owner'],
         disk_format=db_image['disk_format'],
         container_format=db_image['container_format'],
         size=db_image['size'],
         virtual_size=db_image['virtual_size'],
         extra_properties=properties,
         tags=db_tags,
         os_hidden=db_image['os_hidden'],
     )
Esempio n. 5
0
 def _format_image_from_db(self, db_image, db_tags):
     visibility = "public" if db_image["is_public"] else "private"
     properties = {}
     for prop in db_image.pop("properties"):
         # NOTE(markwash) db api requires us to filter deleted
         if not prop["deleted"]:
             properties[prop["name"]] = prop["value"]
     locations = [loc for loc in db_image["locations"] if loc["status"] == "active"]
     if CONF.metadata_encryption_key:
         key = CONF.metadata_encryption_key
         for l in locations:
             l["url"] = crypt.urlsafe_decrypt(key, l["url"])
     return glance.domain.Image(
         image_id=db_image["id"],
         name=db_image["name"],
         status=db_image["status"],
         created_at=db_image["created_at"],
         updated_at=db_image["updated_at"],
         visibility=visibility,
         min_disk=db_image["min_disk"],
         min_ram=db_image["min_ram"],
         protected=db_image["protected"],
         locations=location_strategy.get_ordered_locations(locations),
         checksum=db_image["checksum"],
         owner=db_image["owner"],
         disk_format=db_image["disk_format"],
         container_format=db_image["container_format"],
         size=db_image["size"],
         virtual_size=db_image["virtual_size"],
         extra_properties=properties,
         tags=db_tags,
     )
Esempio n. 6
0
    def test_get_ordered_locations(self):
        self.config(location_strategy='location_order')

        original_locs = [{'url': 'loc1'}, {'url': 'loc2'}]
        ordered_locs = location_strategy.get_ordered_locations(original_locs)

        # Original location list should remain unchanged
        self.assertNotEqual(id(original_locs), id(ordered_locs))
        self.assertEqual(original_locs, ordered_locs)
    def test_get_ordered_locations(self):
        self.config(location_strategy='location_order')

        original_locs = [{'url': 'loc1'}, {'url': 'loc2'}]
        ordered_locs = location_strategy.get_ordered_locations(original_locs)

        # Original location list should remain unchanged
        self.assertNotEqual(id(original_locs), id(ordered_locs))
        self.assertEqual(original_locs, ordered_locs)
Esempio n. 8
0
    def test_get_ordered_locations(self):
        self.config(location_strategy='location_order')

        original_locs = [{'url': 'loc1'}, {'url': 'loc2'}]
        ordered_locs = location_strategy.get_ordered_locations(original_locs)

        # Deep copy protect original location list.
        self.assertNotEqual(id(original_locs), id(ordered_locs))
        self.assertEqual(original_locs, ordered_locs)
Esempio n. 9
0
    def _format_image_from_db(self, db_image, db_tags):
        properties = {}
        for prop in db_image.pop('properties'):
            # NOTE(markwash) db api requires us to filter deleted
            if not prop['deleted']:
                properties[prop['name']] = prop['value']
        locations = [
            loc for loc in db_image['locations'] if loc['status'] == 'active'
        ]
        if CONF.metadata_encryption_key:
            key = CONF.metadata_encryption_key
            for l in locations:
                l['url'] = crypt.urlsafe_decrypt(key, l['url'])

        # NOTE(danms): If the image is shared and we are not the
        # owner, we must have found it because we are a member. Set
        # our tenant on the image as 'member' for policy checks in the
        # upper layers. For any other image stage, we found the image
        # some other way, so leave member=None.
        if (db_image['visibility'] == 'shared'
                and self.context.owner != db_image['owner']):
            member = self.context.owner
        else:
            member = None

        return glance.domain.Image(
            image_id=db_image['id'],
            name=db_image['name'],
            status=db_image['status'],
            created_at=db_image['created_at'],
            updated_at=db_image['updated_at'],
            visibility=db_image['visibility'],
            min_disk=db_image['min_disk'],
            min_ram=db_image['min_ram'],
            protected=db_image['protected'],
            locations=location_strategy.get_ordered_locations(locations),
            checksum=db_image['checksum'],
            os_hash_algo=db_image['os_hash_algo'],
            os_hash_value=db_image['os_hash_value'],
            owner=db_image['owner'],
            disk_format=db_image['disk_format'],
            container_format=db_image['container_format'],
            size=db_image['size'],
            virtual_size=db_image['virtual_size'],
            extra_properties=properties,
            tags=db_tags,
            os_hidden=db_image['os_hidden'],
            member=member,
        )
Esempio n. 10
0
 def test_get_ordered_locations_with_none_or_empty_locations(self):
     self.assertEqual([], location_strategy.get_ordered_locations(None))
     self.assertEqual([], location_strategy.get_ordered_locations([]))
Esempio n. 11
0
 def test_get_ordered_locations_with_none_or_empty_locations(self):
     self.assertEqual([], location_strategy.get_ordered_locations(None))
     self.assertEqual([], location_strategy.get_ordered_locations([]))