Ejemplo n.º 1
0
    def _translate_uuid_to_id(self, context, image):
        """ 
        调用glance_id_to_id方法转换image_copy['id']、image_copy['properties']['kernel_id']和image_copy['properties']['ramdisk_id']; 
        更新image当中的相关属性,返回更新后的image数据; 
        """

        # 拷贝image对象给image_copy;
        image_copy = image.copy()

        try:
            image_uuid = image_copy['id']
        except KeyError:
            pass
        else:
            image_copy['id'] = ec2utils.glance_id_to_id(context, image_uuid)

        for prop in ['kernel_id', 'ramdisk_id']:
            try:
                image_uuid = image_copy['properties'][prop]
            except (KeyError, ValueError):
                pass
            else:
                image_id = ec2utils.glance_id_to_id(context, image_uuid)
                image_copy['properties'][prop] = image_id

        try:
            image_copy['properties']['image_state'] = self.image_state_map[
                image['properties']['image_state']]
        except (KeyError, ValueError):
            pass

        return image_copy
Ejemplo n.º 2
0
    def _translate_uuid_to_id(self, context, image):
        image_copy = image.copy()

        try:
            image_uuid = image_copy['id']
        except KeyError:
            pass
        else:
            image_copy['id'] = ec2utils.glance_id_to_id(context, image_uuid)

        for prop in ['kernel_id', 'ramdisk_id']:
            try:
                image_uuid = image_copy['properties'][prop]
            except (KeyError, ValueError):
                pass
            else:
                image_id = ec2utils.glance_id_to_id(context, image_uuid)
                image_copy['properties'][prop] = image_id

        try:
            image_copy['properties']['image_state'] = self.image_state_map[
                image['properties']['image_state']]
        except (KeyError, ValueError):
            pass

        return image_copy
Ejemplo n.º 3
0
Archivo: s3.py Proyecto: isyippee/nova
    def _translate_uuid_to_id(self, context, image):
        image_copy = image.copy()

        try:
            image_uuid = image_copy["id"]
        except KeyError:
            pass
        else:
            image_copy["id"] = ec2utils.glance_id_to_id(context, image_uuid)

        for prop in ["kernel_id", "ramdisk_id"]:
            try:
                image_uuid = image_copy["properties"][prop]
            except (KeyError, ValueError):
                pass
            else:
                image_id = ec2utils.glance_id_to_id(context, image_uuid)
                image_copy["properties"][prop] = image_id

        try:
            image_copy["properties"]["image_state"] = self.image_state_map[image["properties"]["image_state"]]
        except (KeyError, ValueError):
            pass

        return image_copy
Ejemplo n.º 4
0
    def _translate_uuid_to_id(self, context, image):
        image_copy = image.copy()

        try:
            image_uuid = image_copy['id']
        except KeyError:
            pass
        else:
            image_copy['id'] = ec2utils.glance_id_to_id(context, image_uuid)

        for prop in ['kernel_id', 'ramdisk_id']:
            try:
                image_uuid = image_copy['properties'][prop]
            except (KeyError, ValueError):
                pass
            else:
                image_id = ec2utils.glance_id_to_id(context, image_uuid)
                image_copy['properties'][prop] = image_id

        try:
            image_copy['properties']['image_state'] = self.image_state_map[
                image['properties']['image_state']]
        except (KeyError, ValueError):
            pass

        return image_copy
Ejemplo n.º 5
0
    def _translate_uuid_to_id(self, context, image):
        """ 
        调用glance_id_to_id方法转换image_copy['id']、image_copy['properties']['kernel_id']和image_copy['properties']['ramdisk_id']; 
        更新image当中的相关属性,返回更新后的image数据; 
        """  
      
        # 拷贝image对象给image_copy;
        image_copy = image.copy()

        try:
            image_uuid = image_copy['id']
        except KeyError:
            pass
        else:
            image_copy['id'] = ec2utils.glance_id_to_id(context, image_uuid)

        for prop in ['kernel_id', 'ramdisk_id']:
            try:
                image_uuid = image_copy['properties'][prop]
            except (KeyError, ValueError):
                pass
            else:
                image_id = ec2utils.glance_id_to_id(context, image_uuid)
                image_copy['properties'][prop] = image_id

        try:
            image_copy['properties']['image_state'] = self.image_state_map[
                image['properties']['image_state']]
        except (KeyError, ValueError):
            pass

        return image_copy
Ejemplo n.º 6
0
    def _s3_parse_manifest(self, context, metadata, manifest):
        manifest = etree.fromstring(manifest)
        image_format = 'ami'

        try:
            kernel_id = manifest.find('machine_configuration/kernel_id').text
            if kernel_id == 'true':
                image_format = 'aki'
                kernel_id = None
        except Exception:
            kernel_id = None

        try:
            ramdisk_id = manifest.find('machine_configuration/ramdisk_id').text
            if ramdisk_id == 'true':
                image_format = 'ari'
                ramdisk_id = None
        except Exception:
            ramdisk_id = None

        try:
            arch = manifest.find('machine_configuration/architecture').text
        except Exception:
            arch = 'x86_64'

        # NOTE(yamahata):
        # EC2 ec2-budlne-image --block-device-mapping accepts
        # <virtual name>=<device name> where
        # virtual name = {ami, root, swap, ephemeral<N>}
        #                where N is no negative integer
        # device name = the device name seen by guest kernel.
        # They are converted into
        # block_device_mapping/mapping/{virtual, device}
        #
        # Do NOT confuse this with ec2-register's block device mapping
        # argument.
        mappings = []
        try:
            block_device_mapping = manifest.findall('machine_configuration/'
                                                    'block_device_mapping/'
                                                    'mapping')
            for bdm in block_device_mapping:
                mappings.append({
                    'virtual': bdm.find('virtual').text,
                    'device': bdm.find('device').text
                })
        except Exception:
            mappings = []

        properties = metadata['properties']
        properties['architecture'] = arch

        def _translate_dependent_image_id(image_key, image_id):
            image_uuid = ec2utils.ec2_id_to_glance_id(context, image_id)
            properties[image_key] = image_uuid

        if kernel_id:
            _translate_dependent_image_id('kernel_id', kernel_id)

        if ramdisk_id:
            _translate_dependent_image_id('ramdisk_id', ramdisk_id)

        if mappings:
            properties['mappings'] = mappings

        metadata.update({
            'disk_format': image_format,
            'container_format': image_format,
            'status': 'queued',
            'is_public': False,
            'properties': properties
        })
        metadata['properties']['image_state'] = 'pending'

        #TODO(bcwaldon): right now, this removes user-defined ids.
        # We need to re-enable this.
        metadata.pop('id', None)

        image = self.service.create(context, metadata)

        # extract the new uuid and generate an int id to present back to user
        image_uuid = image['id']
        image['id'] = ec2utils.glance_id_to_id(context, image_uuid)

        # return image_uuid so the caller can still make use of image_service
        return manifest, image, image_uuid
Ejemplo n.º 7
0
    def _s3_parse_manifest(self, context, metadata, manifest):
        manifest = etree.fromstring(manifest)
        image_format = 'ami'

        try:
            kernel_id = manifest.find('machine_configuration/kernel_id').text
            if kernel_id == 'true':
                image_format = 'aki'
                kernel_id = None
        except Exception:
            kernel_id = None

        try:
            ramdisk_id = manifest.find('machine_configuration/ramdisk_id').text
            if ramdisk_id == 'true':
                image_format = 'ari'
                ramdisk_id = None
        except Exception:
            ramdisk_id = None

        try:
            arch = manifest.find('machine_configuration/architecture').text
        except Exception:
            arch = 'x86_64'

        # NOTE(yamahata):
        # EC2 ec2-budlne-image --block-device-mapping accepts
        # <virtual name>=<device name> where
        # virtual name = {ami, root, swap, ephemeral<N>}
        #                where N is no negative integer
        # device name = the device name seen by guest kernel.
        # They are converted into
        # block_device_mapping/mapping/{virtual, device}
        #
        # Do NOT confuse this with ec2-register's block device mapping
        # argument.
        mappings = []
        try:
            block_device_mapping = manifest.findall('machine_configuration/'
                                                    'block_device_mapping/'
                                                    'mapping')
            for bdm in block_device_mapping:
                mappings.append({'virtual': bdm.find('virtual').text,
                                 'device': bdm.find('device').text})
        except Exception:
            mappings = []

        properties = metadata['properties']
        properties['architecture'] = arch

        def _translate_dependent_image_id(image_key, image_id):
            image_uuid = ec2utils.ec2_id_to_glance_id(context, image_id)
            properties[image_key] = image_uuid

        if kernel_id:
            _translate_dependent_image_id('kernel_id', kernel_id)

        if ramdisk_id:
            _translate_dependent_image_id('ramdisk_id', ramdisk_id)

        if mappings:
            properties['mappings'] = mappings

        metadata.update({'disk_format': image_format,
                         'container_format': image_format,
                         'status': 'queued',
                         'is_public': False,
                         'properties': properties})
        metadata['properties']['image_state'] = 'pending'

        #TODO(bcwaldon): right now, this removes user-defined ids.
        # We need to re-enable this.
        metadata.pop('id', None)

        image = self.service.create(context, metadata)

        # extract the new uuid and generate an int id to present back to user
        image_uuid = image['id']
        image['id'] = ec2utils.glance_id_to_id(context, image_uuid)

        # return image_uuid so the caller can still make use of image_service
        return manifest, image, image_uuid
Ejemplo n.º 8
0
Archivo: s3.py Proyecto: isyippee/nova
    def _s3_parse_manifest(self, context, metadata, manifest):
        manifest = etree.fromstring(manifest)
        image_format = "ami"

        try:
            kernel_id = manifest.find("machine_configuration/kernel_id").text
            if kernel_id == "true":
                image_format = "aki"
                kernel_id = None
        except Exception:
            kernel_id = None

        try:
            ramdisk_id = manifest.find("machine_configuration/ramdisk_id").text
            if ramdisk_id == "true":
                image_format = "ari"
                ramdisk_id = None
        except Exception:
            ramdisk_id = None

        try:
            guestarch = manifest.find("machine_configuration/architecture").text
        except Exception:
            guestarch = arch.X86_64

        if not arch.is_valid(guestarch):
            raise exception.InvalidArchitectureName(arch=guestarch)

        # NOTE(yamahata):
        # EC2 ec2-budlne-image --block-device-mapping accepts
        # <virtual name>=<device name> where
        # virtual name = {ami, root, swap, ephemeral<N>}
        #                where N is no negative integer
        # device name = the device name seen by guest kernel.
        # They are converted into
        # block_device_mapping/mapping/{virtual, device}
        #
        # Do NOT confuse this with ec2-register's block device mapping
        # argument.
        mappings = []
        try:
            block_device_mapping = manifest.findall("machine_configuration/" "block_device_mapping/" "mapping")
            for bdm in block_device_mapping:
                mappings.append({"virtual": bdm.find("virtual").text, "device": bdm.find("device").text})
        except Exception:
            mappings = []

        properties = metadata["properties"]
        properties["architecture"] = guestarch

        def _translate_dependent_image_id(image_key, image_id):
            image_uuid = ec2utils.ec2_id_to_glance_id(context, image_id)
            properties[image_key] = image_uuid

        if kernel_id:
            _translate_dependent_image_id("kernel_id", kernel_id)

        if ramdisk_id:
            _translate_dependent_image_id("ramdisk_id", ramdisk_id)

        if mappings:
            properties["mappings"] = mappings

        metadata.update(
            {
                "disk_format": image_format,
                "container_format": image_format,
                "status": "queued",
                "is_public": False,
                "properties": properties,
            }
        )
        metadata["properties"]["image_state"] = "pending"

        # TODO(bcwaldon): right now, this removes user-defined ids.
        # We need to re-enable this.
        metadata.pop("id", None)

        image = self.service.create(context, metadata)

        # extract the new uuid and generate an int id to present back to user
        image_uuid = image["id"]
        image["id"] = ec2utils.glance_id_to_id(context, image_uuid)

        # return image_uuid so the caller can still make use of image_service
        return manifest, image, image_uuid
Ejemplo n.º 9
0
 def test_glance_id_to_id_creates_mapping(self):
     s3imap_id = ec2utils.glance_id_to_id(self.ctxt, 'fake-uuid')
     s3imap = objects.S3ImageMapping.get_by_id(self.ctxt, s3imap_id)
     self.assertEqual('fake-uuid', s3imap.uuid)
Ejemplo n.º 10
0
 def test_glance_id_to_id(self):
     s3imap = objects.S3ImageMapping(self.ctxt, uuid='fake-uuid')
     s3imap.create()
     s3imap_id = ec2utils.glance_id_to_id(self.ctxt, s3imap.uuid)
     self.assertEqual(s3imap_id, s3imap.id)
Ejemplo n.º 11
0
 def test_glance_id_to_id_creates_mapping(self):
     s3imap_id = ec2utils.glance_id_to_id(self.ctxt, 'fake-uuid')
     s3imap = objects.S3ImageMapping.get_by_id(self.ctxt, s3imap_id)
     self.assertEqual('fake-uuid', s3imap.uuid)
Ejemplo n.º 12
0
 def test_glance_id_to_id(self):
     s3imap = objects.S3ImageMapping(self.ctxt, uuid='fake-uuid')
     s3imap.create()
     s3imap_id = ec2utils.glance_id_to_id(self.ctxt, s3imap.uuid)
     self.assertEqual(s3imap_id, s3imap.id)