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

Python ec2utils.id_to_ec2_id函数代码示例

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

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



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

示例1: _format_volume

    def _format_volume(self, context, volume):
        instance_ec2_id = None
        instance_data = None
        if volume.get('instance', None):
            instance_id = volume['instance']['id']
            instance_ec2_id = ec2utils.id_to_ec2_id(instance_id)
            instance_data = '%s[%s]' % (instance_ec2_id,
                                        volume['instance']['host'])
        v = {}
        v['volumeId'] = ec2utils.id_to_ec2_id(volume['id'], 'vol-%08x')
        v['status'] = volume['status']
        v['size'] = volume['size']
        v['availabilityZone'] = volume['availability_zone']
        v['createTime'] = volume['created_at']
        if context.is_admin:
            v['status'] = '%s (%s, %s, %s, %s)' % (
                volume['status'],
                volume['project_id'],
                volume['host'],
                instance_data,
                volume['mountpoint'])
        if volume['attach_status'] == 'attached':
            v['attachmentSet'] = [{'attachTime': volume['attach_time'],
                                   'deleteOnTermination': False,
                                   'device': volume['mountpoint'],
                                   'instanceId': instance_ec2_id,
                                   'status': 'attached',
                                   'volumeId': v['volumeId']}]
        else:
            v['attachmentSet'] = [{}]

        v['display_name'] = volume['display_name']
        v['display_description'] = volume['display_description']
        return v
开发者ID:pombredanne,项目名称:nova,代码行数:34,代码来源:cloud.py


示例2: 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


示例3: assert_compute_node_has_enough_disk

    def assert_compute_node_has_enough_disk(self, context, instance_ref, dest,
                                            disk_over_commit):
        """Checks if destination host has enough disk for block migration.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host
        :param disk_over_commit: if True, consider real(not virtual)
                                 disk size.

        """

        # Libvirt supports qcow2 disk format,which is usually compressed
        # on compute nodes.
        # Real disk image (compressed) may enlarged to "virtual disk size",
        # that is specified as the maximum disk size.
        # (See qemu-img -f path-to-disk)
        # Scheduler recognizes destination host still has enough disk space
        # if real disk size < available disk size
        # if disk_over_commit is True,
        #  otherwise virtual disk size < available disk size.

        # Refresh compute_nodes table
        topic = db.queue_get_for(context, FLAGS.compute_topic, dest)
        rpc.call(context, topic,
                 {"method": "update_available_resource"})

        # Getting total available disk of host
        available_gb = self._get_compute_info(context,
                                              dest, 'disk_available_least')
        available = available_gb * (1024 ** 3)

        # Getting necessary disk size
        try:
            topic = db.queue_get_for(context, FLAGS.compute_topic,
                                              instance_ref['host'])
            ret = rpc.call(context, topic,
                           {"method": 'get_instance_disk_info',
                            "args": {'instance_name': instance_ref.name}})
            disk_infos = utils.loads(ret)
        except rpc.RemoteError:
            LOG.exception(_("host %(dest)s is not compatible with "
                                "original host %(src)s.") % locals())
            raise

        necessary = 0
        if disk_over_commit:
            for info in disk_infos:
                necessary += int(info['disk_size'])
        else:
            for info in disk_infos:
                necessary += int(info['virt_disk_size'])

        # Check that available disk > necessary disk
        if (available - necessary) < 0:
            instance_id = ec2utils.id_to_ec2_id(instance_ref['id'])
            reason = _("Unable to migrate %(instance_id)s to %(dest)s: "
                       "Lack of disk(host:%(available)s "
                       "<= instance:%(necessary)s)")
            raise exception.MigrationError(reason=reason % locals())
开发者ID:Razique,项目名称:nova,代码行数:60,代码来源:driver.py


示例4: assert_compute_node_has_enough_memory

    def assert_compute_node_has_enough_memory(self, context, instance_ref, dest):
        """Checks if destination host has enough memory for live migration.


        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """
        # Getting total available memory of host
        avail = self._get_compute_info(context, dest, "memory_mb")

        # Getting total used memory and disk of host
        # It should be sum of memories that are assigned as max value,
        # because overcommiting is risky.
        instance_refs = db.instance_get_all_by_host(context, dest)
        used = sum([i["memory_mb"] for i in instance_refs])

        mem_inst = instance_ref["memory_mb"]
        avail = avail - used
        if avail <= mem_inst:
            instance_id = ec2utils.id_to_ec2_id(instance_ref["id"])
            reason = _(
                "Unable to migrate %(instance_id)s to %(dest)s: "
                "Lack of memory(host:%(avail)s <= "
                "instance:%(mem_inst)s)"
            )
            raise exception.MigrationError(reason=reason % locals())
开发者ID:renuka-apte,项目名称:nova,代码行数:28,代码来源:driver.py


示例5: assert_compute_node_has_enough_memory

    def assert_compute_node_has_enough_memory(self, context,
                                              instance_ref, dest):
        """Checks if destination host has enough memory for live migration.


        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """
        elevated = context.elevated()
        # Getting total available memory and disk of host
        avail = self._get_compute_info(elevated, dest, 'memory_mb')

        # Getting total used memory and disk of host
        # It should be sum of memories that are assigned as max value,
        # because overcommiting is risky.
        used = 0
        instance_refs = db.instance_get_all_by_host(elevated, dest)
        used_list = [i['memory_mb'] for i in instance_refs]
        if used_list:
            used = reduce(lambda x, y: x + y, used_list)

        mem_inst = instance_ref['memory_mb']
        avail = avail - used - FLAGS.cs_host_reserved_memory_mb
        if avail <= mem_inst:
            instance_id = ec2utils.id_to_ec2_id(instance_ref['id'])
            reason = _("Lack of memory(host:%(avail)s"\
                       " <= instance:%(mem_inst)s)"\
                       "on $(dest)")
            raise exception.InsufficientFreeMemory(uuid=dest)
开发者ID:pperezrubio,项目名称:cs-nova-simplescheduler,代码行数:31,代码来源:simple.py


示例6: test_describe_instances

 def test_describe_instances(self):
     """Makes sure describe_instances works and filters results."""
     inst1 = db.instance_create(self.context, {'reservation_id': 'a',
                                               'image_id': 1,
                                               'host': 'host1'})
     inst2 = db.instance_create(self.context, {'reservation_id': 'a',
                                               'image_id': 1,
                                               'host': 'host2'})
     comp1 = db.service_create(self.context, {'host': 'host1',
                                              'availability_zone': 'zone1',
                                              'topic': "compute"})
     comp2 = db.service_create(self.context, {'host': 'host2',
                                              'availability_zone': 'zone2',
                                              'topic': "compute"})
     result = self.cloud.describe_instances(self.context)
     result = result['reservationSet'][0]
     self.assertEqual(len(result['instancesSet']), 2)
     instance_id = ec2utils.id_to_ec2_id(inst2['id'])
     result = self.cloud.describe_instances(self.context,
                                          instance_id=[instance_id])
     result = result['reservationSet'][0]
     self.assertEqual(len(result['instancesSet']), 1)
     self.assertEqual(result['instancesSet'][0]['instanceId'],
                      instance_id)
     self.assertEqual(result['instancesSet'][0]
                      ['placement']['availabilityZone'], 'zone2')
     db.instance_destroy(self.context, inst1['id'])
     db.instance_destroy(self.context, inst2['id'])
     db.service_destroy(self.context, comp1['id'])
     db.service_destroy(self.context, comp2['id'])
开发者ID:superstack,项目名称:nova,代码行数:30,代码来源:test_cloud.py


示例7: _live_migration_src_check

    def _live_migration_src_check(self, context, instance_ref):
        """Live migration check routine (for src host).

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object

        """

        # Checking instance is running.
        if instance_ref['power_state'] != power_state.RUNNING:
            instance_id = ec2utils.id_to_ec2_id(instance_ref['id'])
            raise exception.InstanceNotRunning(instance_id=instance_id)

        # Checing volume node is running when any volumes are mounted
        # to the instance.
        if len(instance_ref['volumes']) != 0:
            services = db.service_get_all_by_topic(context, 'volume')
            if len(services) < 1 or  not self.service_is_up(services[0]):
                raise exception.VolumeServiceUnavailable()

        # Checking src host exists and compute node
        src = instance_ref['host']
        services = db.service_get_all_compute_by_host(context, src)

        # Checking src host is alive.
        if not self.service_is_up(services[0]):
            raise exception.ComputeServiceUnavailable(host=src)
开发者ID:AsherBond,项目名称:dodai-compute,代码行数:27,代码来源:driver.py


示例8: _live_migration_dest_check

    def _live_migration_dest_check(self, context, instance_ref, dest,
                                   block_migration):
        """Live migration check routine (for destination host).

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        # Checking dest exists and compute node.
        dservice_refs = db.service_get_all_compute_by_host(context, dest)
        dservice_ref = dservice_refs[0]

        # Checking dest host is alive.
        if not self.service_is_up(dservice_ref):
            raise exception.ComputeServiceUnavailable(host=dest)

        # Checking whether The host where instance is running
        # and dest is not same.
        src = instance_ref['host']
        if dest == src:
            instance_id = ec2utils.id_to_ec2_id(instance_ref['id'])
            raise exception.UnableToMigrateToSelf(instance_id=instance_id,
                                                  host=dest)

        # Checking dst host still has enough capacities.
        self.assert_compute_node_has_enough_resources(context,
                                                      instance_ref,
                                                      dest,
                                                      block_migration)
开发者ID:AsherBond,项目名称:dodai-compute,代码行数:31,代码来源:driver.py


示例9: get_metadata

    def get_metadata(self, address):
        ctxt = context.get_admin_context()
        instance_ref = self.compute_api.get_all(ctxt, fixed_ip=address)
        if instance_ref is None:
            return None

        # This ensures that all attributes of the instance
        # are populated.
        instance_ref = db.instance_get(ctxt, instance_ref['id'])

        mpi = self._get_mpi_data(ctxt, instance_ref['project_id'])
        if instance_ref['key_name']:
            keys = {'0': {'_name': instance_ref['key_name'],
                          'openssh-key': instance_ref['key_data']}}
        else:
            keys = ''
        hostname = instance_ref['hostname']
        host = instance_ref['host']
        availability_zone = self._get_availability_zone_by_host(ctxt, host)
        floating_ip = db.instance_get_floating_address(ctxt,
                                                       instance_ref['id'])
        ec2_id = ec2utils.id_to_ec2_id(instance_ref['id'])
        image_ec2_id = self.image_ec2_id(instance_ref['image_id'])
        data = {
            'user-data': base64.b64decode(instance_ref['user_data']),
            'meta-data': {
                'ami-id': image_ec2_id,
                'ami-launch-index': instance_ref['launch_index'],
                'ami-manifest-path': 'FIXME',
                'block-device-mapping': {
                    # TODO(vish): replace with real data
                    'ami': 'sda1',
                    'ephemeral0': 'sda2',
                    'root': '/dev/sda1',
                    'swap': 'sda3'},
                'hostname': hostname,
                'instance-action': 'none',
                'instance-id': ec2_id,
                'instance-type': instance_ref['instance_type'],
                'local-hostname': hostname,
                'local-ipv4': address,
                'placement': {'availability-zone': availability_zone},
                'public-hostname': hostname,
                'public-ipv4': floating_ip or '',
                'public-keys': keys,
                'reservation-id': instance_ref['reservation_id'],
                'security-groups': '',
                'mpi': mpi}}

        for image_type in ['kernel', 'ramdisk']:
            if instance_ref.get('%s_id' % image_type):
                ec2_id = self.image_ec2_id(instance_ref['%s_id' % image_type],
                                           self._image_type(image_type))
                data['meta-data']['%s-id' % image_type] = ec2_id

        if False:  # TODO(vish): store ancestor ids
            data['ancestor-ami-ids'] = []
        if False:  # TODO(vish): store product codes
            data['product-codes'] = []
        return data
开发者ID:superstack,项目名称:nova,代码行数:60,代码来源:cloud.py


示例10: assert_compute_node_has_enough_disk

    def assert_compute_node_has_enough_disk(self, context,
                                            instance_ref, dest):
        """Checks if destination host has enough disk for block migration.

        :param context: security context
        :param instance_ref: nova.db.sqlalchemy.models.Instance object
        :param dest: destination host

        """

        # Getting total available memory and disk of host
        avail = self._get_compute_info(context, dest, 'local_gb')

        # Getting total used memory and disk of host
        # It should be sum of disks that are assigned as max value
        # because overcommiting is risky.
        used = 0
        instance_refs = db.instance_get_all_by_host(context, dest)
        used_list = [i['local_gb'] for i in instance_refs]
        if used_list:
            used = reduce(lambda x, y: x + y, used_list)

        disk_inst = instance_ref['local_gb']
        avail = avail - used
        if avail <= disk_inst:
            instance_id = ec2utils.id_to_ec2_id(instance_ref['id'])
            reason = _("Unable to migrate %(instance_id)s to %(dest)s: "
                       "Lack of disk(host:%(avail)s "
                       "<= instance:%(disk_inst)s)")
            raise exception.MigrationError(reason=reason % locals())
开发者ID:AsherBond,项目名称:dodai-compute,代码行数:30,代码来源:driver.py


示例11: test_update_of_volume_wont_update_private_fields

 def test_update_of_volume_wont_update_private_fields(self):
     vol = db.volume_create(self.context, {})
     self.cloud.update_volume(self.context,
                              ec2utils.id_to_ec2_id(vol['id'], 'vol-%08x'),
                              mountpoint='/not/here')
     vol = db.volume_get(self.context, vol['id'])
     self.assertEqual(None, vol['mountpoint'])
     db.volume_destroy(self.context, vol['id'])
开发者ID:superstack,项目名称:nova,代码行数:8,代码来源:test_cloud.py


示例12: test_update_of_volume_display_fields

 def test_update_of_volume_display_fields(self):
     vol = db.volume_create(self.context, {})
     self.cloud.update_volume(self.context,
                              ec2utils.id_to_ec2_id(vol['id'], 'vol-%08x'),
                              display_name='c00l v0lum3')
     vol = db.volume_get(self.context, vol['id'])
     self.assertEqual('c00l v0lum3', vol['display_name'])
     db.volume_destroy(self.context, vol['id'])
开发者ID:superstack,项目名称:nova,代码行数:8,代码来源:test_cloud.py


示例13: test_update_of_instance_display_fields

 def test_update_of_instance_display_fields(self):
     inst = db.instance_create(self.context, {})
     ec2_id = ec2utils.id_to_ec2_id(inst['id'])
     self.cloud.update_instance(self.context, ec2_id,
                                display_name='c00l 1m4g3')
     inst = db.instance_get(self.context, inst['id'])
     self.assertEqual('c00l 1m4g3', inst['display_name'])
     db.instance_destroy(self.context, inst['id'])
开发者ID:superstack,项目名称:nova,代码行数:8,代码来源:test_cloud.py


示例14: 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


示例15: _assertInstance

 def _assertInstance(self, instance_id):
     ec2_instance_id = ec2utils.id_to_ec2_id(instance_id)
     result = self.cloud.describe_instances(self.context, instance_id=[ec2_instance_id])
     result = result["reservationSet"][0]
     self.assertEqual(len(result["instancesSet"]), 1)
     result = result["instancesSet"][0]
     self.assertEqual(result["instanceId"], ec2_instance_id)
     return result
开发者ID:99cloud,项目名称:nova,代码行数:8,代码来源:test_cinder_cloud.py


示例16: __call__

 def __call__(self, req):
     context = req.environ['ec2.context']
     api_request = req.environ['ec2.request']
     result = None
     try:
         result = api_request.invoke(context)
     except exception.InstanceNotFound as ex:
         LOG.info(_('InstanceNotFound raised: %s'), unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_id(ex.instance_id)
         message = _('Instance %s not found') % ec2_id
         return self._error(req, context, type(ex).__name__, message)
     except exception.VolumeNotFound as ex:
         LOG.info(_('VolumeNotFound raised: %s'), unicode(ex),
                  context=context)
         ec2_id = ec2utils.id_to_ec2_id(ex.volume_id, 'vol-%08x')
         message = _('Volume %s not found') % ec2_id
         return self._error(req, context, type(ex).__name__, message)
     except exception.NotFound as ex:
         LOG.info(_('NotFound raised: %s'), unicode(ex), context=context)
         return self._error(req, context, type(ex).__name__, unicode(ex))
     except exception.ApiError as ex:
         LOG.exception(_('ApiError raised: %s'), unicode(ex),
                       context=context)
         if ex.code:
             return self._error(req, context, ex.code, unicode(ex))
         else:
             return self._error(req, context, type(ex).__name__,
                                unicode(ex))
     except Exception as ex:
         extra = {'environment': req.environ}
         LOG.exception(_('Unexpected error raised: %s'), unicode(ex),
                       extra=extra, context=context)
         return self._error(req,
                            context,
                            'UnknownError',
                            _('An unknown error has occurred. '
                            'Please try your request again.'))
     else:
         resp = webob.Response()
         resp.status = 200
         resp.headers['Content-Type'] = 'text/xml'
         resp.body = str(result)
         return resp
开发者ID:pombredanne,项目名称:nova,代码行数:44,代码来源:__init__.py


示例17: start_vpn

 def start_vpn(self, context, project):
     instance = self._vpn_for(context, project)
     if not instance:
         # NOTE(vish) import delayed because of __init__.py
         from nova.cloudpipe import pipelib
         pipe = pipelib.CloudPipe()
         try:
             pipe.launch_vpn_instance(project)
         except db.NoMoreNetworks:
             raise exception.ApiError("Unable to claim IP for VPN instance"
                                      ", ensure it isn't running, and try "
                                      "again in a few minutes")
         instance = self._vpn_for(context, project)
     return {'instance_id': ec2utils.id_to_ec2_id(instance['id'])}
开发者ID:superstack,项目名称:nova,代码行数:14,代码来源:admin.py


示例18: 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


示例19: test_vpn_dict_state_running

    def test_vpn_dict_state_running(self):
        isonow = datetime.datetime.utcnow()
        vpn_instance = {"id": 1, "created_at": isonow, "fixed_ip": {"address": "127.0.0.1"}}

        project = type("Project", (object,), {"id": "project", "vpn_ip": "127.0.0.1", "vpn_port": 1234})

        # Returns state running for 127.0.0.1 - look at class setup
        expected_vpn_dict = {
            "project_id": "project",
            "public_ip": "127.0.0.1",
            "public_port": 1234,
            "internal_ip": "127.0.0.1",
            "instance_id": ec2utils.id_to_ec2_id(1),
            "created_at": utils.isotime(isonow),
            "state": "running",
        }

        self.assertEqual(expected_vpn_dict, admin.vpn_dict(project, vpn_instance))
开发者ID:nanodayo,项目名称:nova,代码行数:18,代码来源:test_admin.py


示例20: vpn_dict

def vpn_dict(project, vpn_instance):
    rv = {"project_id": project.id, "public_ip": project.vpn_ip, "public_port": project.vpn_port}
    if vpn_instance:
        rv["instance_id"] = ec2utils.id_to_ec2_id(vpn_instance["id"])
        rv["created_at"] = utils.isotime(vpn_instance["created_at"])
        address = vpn_instance.get("fixed_ip", None)
        if address:
            rv["internal_ip"] = address["address"]
        if project.vpn_ip and project.vpn_port:
            if utils.vpn_ping(project.vpn_ip, project.vpn_port):
                rv["state"] = "running"
            else:
                rv["state"] = "down"
        else:
            rv["state"] = "down - invalid project vpn config"
    else:
        rv["state"] = "pending"
    return rv
开发者ID:rajarammallya,项目名称:openstack-nova,代码行数:18,代码来源:admin.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python ec2utils.id_to_ec2_inst_id函数代码示例发布时间:2022-05-27
下一篇:
Python ec2utils.glance_id_to_id函数代码示例发布时间: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