• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python ec2utils.ec2_id_to_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nova.api.ec2.ec2utils.ec2_id_to_id函数的典型用法代码示例。如果您正苦于以下问题:Python ec2_id_to_id函数的具体用法?Python ec2_id_to_id怎么用?Python ec2_id_to_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了ec2_id_to_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: validate_ec2_id

 def validate_ec2_id(val):
     if not validator.validate_str()(val):
         return False
     try:
         ec2utils.ec2_id_to_id(val)
     except exception.InvalidEc2Id:
         return False
     return True
开发者ID:acomisario,项目名称:nova,代码行数:8,代码来源:__init__.py


示例2: reboot_instances

 def reboot_instances(self, context, instance_id, **kwargs):
     """instance_id is a list of instance ids"""
     LOG.audit(_("Reboot instance %r"), instance_id, context=context)
     for ec2_id in instance_id:
         instance_id = ec2utils.ec2_id_to_id(ec2_id)
         self.compute_api.reboot(context, instance_id=instance_id)
     return True
开发者ID:pombredanne,项目名称:nova,代码行数:7,代码来源:cloud.py


示例3: terminate_instances

 def terminate_instances(self, context, instance_id, **kwargs):
     """Terminate each instance in instance_id, which is a list of ec2 ids.
     instance_id is a kwarg so its name cannot be modified."""
     LOG.debug(_("Going to start terminating instances"))
     for ec2_id in instance_id:
         instance_id = ec2utils.ec2_id_to_id(ec2_id)
         self.compute_api.delete(context, instance_id=instance_id)
     return True
开发者ID:pombredanne,项目名称:nova,代码行数:8,代码来源:cloud.py


示例4: associate_address

 def associate_address(self, context, instance_id, public_ip, **kwargs):
     LOG.audit(_("Associate address %(public_ip)s to"
             " instance %(instance_id)s") % locals(), context=context)
     instance_id = ec2utils.ec2_id_to_id(instance_id)
     self.compute_api.associate_floating_ip(context,
                                            instance_id=instance_id,
                                            address=public_ip)
     return {'associateResponse': ["Address associated."]}
开发者ID:pombredanne,项目名称:nova,代码行数:8,代码来源:cloud.py


示例5: attach_volume

 def attach_volume(self, context, volume_id, instance_id, device, **kwargs):
     volume_id = ec2utils.ec2_id_to_id(volume_id)
     instance_id = ec2utils.ec2_id_to_id(instance_id)
     msg = _("Attach volume %(volume_id)s to instance %(instance_id)s"
             " at %(device)s") % locals()
     LOG.audit(msg, context=context)
     self.compute_api.attach_volume(context,
                                    instance_id=instance_id,
                                    volume_id=volume_id,
                                    device=device)
     volume = self.volume_api.get(context, volume_id)
     return {'attachTime': volume['attach_time'],
             'device': volume['mountpoint'],
             'instanceId': ec2utils.id_to_ec2_id(instance_id),
             'requestId': context.request_id,
             'status': volume['attach_status'],
             'volumeId': ec2utils.id_to_ec2_id(volume_id, 'vol-%08x')}
开发者ID:pombredanne,项目名称:nova,代码行数:17,代码来源:cloud.py


示例6: _get_image

 def _get_image(self, context, ec2_id):
     try:
         internal_id = ec2utils.ec2_id_to_id(ec2_id)
         return self.image_service.show(context, internal_id)
     except (exception.InvalidEc2Id, exception.ImageNotFound):
         try:
             return self.image_service.show_by_name(context, ec2_id)
         except exception.NotFound:
             raise exception.ImageNotFound(image_id=ec2_id)
开发者ID:superstack,项目名称:nova,代码行数:9,代码来源:cloud.py


示例7: update_volume

 def update_volume(self, context, volume_id, **kwargs):
     volume_id = ec2utils.ec2_id_to_id(volume_id)
     updatable_fields = ['display_name', 'display_description']
     changes = {}
     for field in updatable_fields:
         if field in kwargs:
             changes[field] = kwargs[field]
     if changes:
         self.volume_api.update(context, volume_id, kwargs)
     return True
开发者ID:pombredanne,项目名称:nova,代码行数:10,代码来源:cloud.py


示例8: update_instance

 def update_instance(self, context, instance_id, **kwargs):
     updatable_fields = ['display_name', 'display_description']
     changes = {}
     for field in updatable_fields:
         if field in kwargs:
             changes[field] = kwargs[field]
     if changes:
         instance_id = ec2utils.ec2_id_to_id(instance_id)
         self.compute_api.update(context, instance_id=instance_id, **kwargs)
     return True
开发者ID:pombredanne,项目名称:nova,代码行数:10,代码来源:cloud.py


示例9: describe_volumes

 def describe_volumes(self, context, volume_id=None, **kwargs):
     if volume_id:
         volumes = []
         for ec2_id in volume_id:
             internal_id = ec2utils.ec2_id_to_id(ec2_id)
             volume = self.volume_api.get(context, internal_id)
             volumes.append(volume)
     else:
         volumes = self.volume_api.get_all(context)
     volumes = [self._format_volume(context, v) for v in volumes]
     return {'volumeSet': volumes}
开发者ID:pombredanne,项目名称:nova,代码行数:11,代码来源:cloud.py


示例10: detach_volume

 def detach_volume(self, context, volume_id, **kwargs):
     volume_id = ec2utils.ec2_id_to_id(volume_id)
     LOG.audit(_("Detach volume %s"), volume_id, context=context)
     volume = self.volume_api.get(context, volume_id)
     instance = self.compute_api.detach_volume(context, volume_id=volume_id)
     return {'attachTime': volume['attach_time'],
             'device': volume['mountpoint'],
             'instanceId': ec2utils.id_to_ec2_id(instance['id']),
             'requestId': context.request_id,
             'status': volume['attach_status'],
             'volumeId': ec2utils.id_to_ec2_id(volume_id, 'vol-%08x')}
开发者ID:pombredanne,项目名称:nova,代码行数:11,代码来源:cloud.py


示例11: test_describe_volumes

 def test_describe_volumes(self):
     """Makes sure describe_volumes works and filters results."""
     vol1 = db.volume_create(self.context, {})
     vol2 = db.volume_create(self.context, {})
     result = self.cloud.describe_volumes(self.context)
     self.assertEqual(len(result['volumeSet']), 2)
     volume_id = ec2utils.id_to_ec2_id(vol2['id'], 'vol-%08x')
     result = self.cloud.describe_volumes(self.context,
                                          volume_id=[volume_id])
     self.assertEqual(len(result['volumeSet']), 1)
     self.assertEqual(
             ec2utils.ec2_id_to_id(result['volumeSet'][0]['volumeId']),
             vol2['id'])
     db.volume_destroy(self.context, vol1['id'])
     db.volume_destroy(self.context, vol2['id'])
开发者ID:superstack,项目名称:nova,代码行数:15,代码来源:test_cloud.py


示例12: get_console_output

 def get_console_output(self, context, instance_id, **kwargs):
     LOG.audit(_("Get console output for instance %s"), instance_id,
               context=context)
     # instance_id may be passed in as a list of instances
     if type(instance_id) == list:
         ec2_id = instance_id[0]
     else:
         ec2_id = instance_id
     instance_id = ec2utils.ec2_id_to_id(ec2_id)
     output = self.compute_api.get_console_output(
             context, instance_id=instance_id)
     now = datetime.datetime.utcnow()
     return {"InstanceId": ec2_id,
             "Timestamp": now,
             "output": base64.b64encode(output)}
开发者ID:pombredanne,项目名称:nova,代码行数:15,代码来源:cloud.py


示例13: _s3_parse_manifest

    def _s3_parse_manifest(self, context, metadata, manifest):
        manifest = ElementTree.fromstring(manifest)
        image_format = 'ami'
        image_type = 'machine'

        try:
            kernel_id = manifest.find('machine_configuration/kernel_id').text
            if kernel_id == 'true':
                image_format = 'aki'
                image_type = 'kernel'
                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'
                image_type = 'ramdisk'
                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['project_id'] = context.project_id
        properties['architecture'] = arch

        if kernel_id:
            properties['kernel_id'] = ec2utils.ec2_id_to_id(kernel_id)

        if ramdisk_id:
            properties['ramdisk_id'] = ec2utils.ec2_id_to_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'
        image = self.service.create(context, metadata)
        return manifest, image
开发者ID:CaptTofu,项目名称:reddwarf,代码行数:71,代码来源:s3.py


示例14: _s3_create

    def _s3_create(self, context, metadata):
        """Gets a manifext from s3 and makes an image"""

        image_path = tempfile.mkdtemp(dir=FLAGS.image_decryption_dir)

        image_location = metadata['properties']['image_location']
        bucket_name = image_location.split("/")[0]
        manifest_path = image_location[len(bucket_name) + 1:]
        bucket = self._conn(context).get_bucket(bucket_name)
        key = bucket.get_key(manifest_path)
        manifest = key.get_contents_as_string()

        manifest = ElementTree.fromstring(manifest)
        image_format = 'ami'
        image_type = 'machine'

        try:
            kernel_id = manifest.find("machine_configuration/kernel_id").text
            if kernel_id == 'true':
                image_format = 'aki'
                image_type = 'kernel'
                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'
                image_type = 'ramdisk'
                ramdisk_id = None
        except Exception:
            ramdisk_id = None

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

        properties = metadata['properties']
        properties['owner_id'] = context.project_id
        properties['architecture'] = arch

        if kernel_id:
            properties['kernel_id'] = ec2utils.ec2_id_to_id(kernel_id)

        if ramdisk_id:
            properties['ramdisk_id'] = ec2utils.ec2_id_to_id(ramdisk_id)

        properties['is_public'] = False
        properties['type'] = image_type
        metadata.update({'disk_format': image_format,
                         'container_format': image_format,
                         'status': 'queued',
                         'is_public': True,
                         'properties': properties})
        metadata['properties']['image_state'] = 'pending'
        image = self.service.create(context, metadata)
        image_id = image['id']

        def delayed_create():
            """This handles the fetching and decrypting of the part files."""
            parts = []
            for fn_element in manifest.find("image").getiterator("filename"):
                part = self._download_file(bucket, fn_element.text, image_path)
                parts.append(part)

            # NOTE(vish): this may be suboptimal, should we use cat?
            encrypted_filename = os.path.join(image_path, 'image.encrypted')
            with open(encrypted_filename, 'w') as combined:
                for filename in parts:
                    with open(filename) as part:
                        shutil.copyfileobj(part, combined)

            metadata['properties']['image_state'] = 'decrypting'
            self.service.update(context, image_id, metadata)

            hex_key = manifest.find("image/ec2_encrypted_key").text
            encrypted_key = binascii.a2b_hex(hex_key)
            hex_iv = manifest.find("image/ec2_encrypted_iv").text
            encrypted_iv = binascii.a2b_hex(hex_iv)

            # FIXME(vish): grab key from common service so this can run on
            #              any host.
            cloud_pk = os.path.join(FLAGS.ca_path, "private/cakey.pem")

            decrypted_filename = os.path.join(image_path, 'image.tar.gz')
            self._decrypt_image(encrypted_filename, encrypted_key,
                                encrypted_iv, cloud_pk, decrypted_filename)

            metadata['properties']['image_state'] = 'untarring'
            self.service.update(context, image_id, metadata)

            unz_filename = self._untarzip_image(image_path, decrypted_filename)

            metadata['properties']['image_state'] = 'uploading'
            with open(unz_filename) as image_file:
                self.service.update(context, image_id, metadata, image_file)
            metadata['properties']['image_state'] = 'available'
            self.service.update(context, image_id, metadata)
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:nova,代码行数:101,代码来源:s3.py


示例15: _s3_parse_manifest

    def _s3_parse_manifest(self, context, metadata, manifest):
        manifest = ElementTree.fromstring(manifest)
        image_format = "ami"
        image_type = "machine"

        try:
            kernel_id = manifest.find("machine_configuration/kernel_id").text
            if kernel_id == "true":
                image_format = "aki"
                image_type = "kernel"
                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"
                image_type = "ramdisk"
                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["project_id"] = context.project_id
        properties["architecture"] = arch

        if kernel_id:
            properties["kernel_id"] = ec2utils.ec2_id_to_id(kernel_id)

        if ramdisk_id:
            properties["ramdisk_id"] = ec2utils.ec2_id_to_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"
        image = self.service.create(context, metadata)
        return manifest, image
开发者ID:nfantini,项目名称:openstack-bill,代码行数:72,代码来源:s3.py


示例16: test_ec2_id_to_id

 def test_ec2_id_to_id(self):
     self.assertEqual(ec2utils.ec2_id_to_id('i-0000001e'), 30)
     self.assertEqual(ec2utils.ec2_id_to_id('ami-1d'), 29)
开发者ID:superstack,项目名称:nova,代码行数:3,代码来源:test_api.py


示例17: update_image

 def update_image(self, context, image_id, **kwargs):
     internal_id = ec2utils.ec2_id_to_id(image_id)
     result = self.image_service.update(context, internal_id, dict(kwargs))
     return result
开发者ID:pombredanne,项目名称:nova,代码行数:4,代码来源:cloud.py


示例18: _get_image

 def _get_image(self, context, ec2_id):
     try:
         internal_id = ec2utils.ec2_id_to_id(ec2_id)
         return self.image_service.show(context, internal_id)
     except exception.NotFound:
         return self.image_service.show_by_name(context, ec2_id)
开发者ID:pombredanne,项目名称:nova,代码行数:6,代码来源:cloud.py


示例19: get_ajax_console

 def get_ajax_console(self, context, instance_id, **kwargs):
     ec2_id = instance_id[0]
     instance_id = ec2utils.ec2_id_to_id(ec2_id)
     return self.compute_api.get_ajax_console(context,
                                              instance_id=instance_id)
开发者ID:pombredanne,项目名称:nova,代码行数:5,代码来源:cloud.py


示例20: test_ec2_id_to_id

 def test_ec2_id_to_id(self):
     self.assertEqual(ec2utils.ec2_id_to_id('i-0000001e'), 30)
     self.assertEqual(ec2utils.ec2_id_to_id('ami-1d'), 29)
     self.assertEqual(ec2utils.ec2_id_to_id('snap-0000001c'), 28)
     self.assertEqual(ec2utils.ec2_id_to_id('vol-0000001b'), 27)
开发者ID:derekhiggins,项目名称:nova,代码行数:5,代码来源:test_api.py



注:本文中的nova.api.ec2.ec2utils.ec2_id_to_id函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python ec2utils.ec2_inst_id_to_uuid函数代码示例发布时间:2022-05-27
下一篇:
Python ec2utils.dict_from_dotted_str函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap