当前位置: 首页>>代码示例>>Python>>正文


Python ec2utils.id_to_ec2_id函数代码示例

本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


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