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

Python instance_types.extract_instance_type函数代码示例

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

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



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

示例1: allocate_for_instance

    def allocate_for_instance(self, context, instance, vpn,
                              requested_networks, macs=None,
                              conductor_api=None, security_groups=None):
        """Allocates all network structures for an instance.

        TODO(someone): document the rest of these parameters.

        :param macs: None or a set of MAC addresses that the instance
            should use. macs is supplied by the hypervisor driver (contrast
            with requested_networks which is user supplied).
        :returns: network info as from get_instance_nw_info() below
        """
        # NOTE(vish): We can't do the floating ip allocation here because
        #             this is called from compute.manager which shouldn't
        #             have db access so we do it on the other side of the
        #             rpc.
        instance_type = instance_types.extract_instance_type(instance)
        args = {}
        args['vpn'] = vpn
        args['requested_networks'] = requested_networks
        args['instance_id'] = instance['uuid']
        args['project_id'] = instance['project_id']
        args['host'] = instance['host']
        args['rxtx_factor'] = instance_type['rxtx_factor']
        args['macs'] = macs
        nw_info = self.network_rpcapi.allocate_for_instance(context, **args)

        return network_model.NetworkInfo.hydrate(nw_info)
开发者ID:Balakrishnan-Vivek,项目名称:nova,代码行数:28,代码来源:api.py


示例2: test_live_migration_dest_check_auto_set_host

    def test_live_migration_dest_check_auto_set_host(self):
        instance = self._live_migration_instance()

        # Confirm dest is picked by scheduler if not set.
        self.mox.StubOutWithMock(self.driver, 'select_hosts')
        self.mox.StubOutWithMock(db, 'instance_type_get')

        instance_type = instance_types.extract_instance_type(instance)
        request_spec = {'instance_properties': instance,
                        'instance_type': instance_type,
                        'instance_uuids': [instance['uuid']],
                        'image': self.image_service.show(self.context,
                                                         instance['image_ref'])
                        }
        ignore_hosts = [instance['host']]
        filter_properties = {'ignore_hosts': ignore_hosts}

        db.instance_type_get(self.context, instance_type['id']).AndReturn(
            instance_type)
        self.driver.select_hosts(self.context, request_spec,
                                 filter_properties).AndReturn(['fake_host2'])

        self.mox.ReplayAll()
        result = self.driver._live_migration_dest_check(self.context, instance,
                                                        None, ignore_hosts)
        self.assertEqual('fake_host2', result)
开发者ID:AnyBucket,项目名称:nova,代码行数:26,代码来源:test_scheduler.py


示例3: setUp

    def setUp(self):
        super(SimpleTenantUsageControllerTest, self).setUp()
        self.controller = simple_tenant_usage.SimpleTenantUsageController()

        class FakeComputeAPI:
            def get_instance_type(self, context, flavor_type):
                if flavor_type == 1:
                    return instance_types.get_default_instance_type()
                else:
                    raise exception.InstanceTypeNotFound(flavor_type)

        self.compute_api = FakeComputeAPI()
        self.context = None

        now = datetime.datetime.now()
        self.baseinst = dict(display_name='foo',
                             launched_at=now - datetime.timedelta(1),
                             terminated_at=now,
                             instance_type_id=1,
                             vm_state='deleted',
                             deleted=0)
        basetype = instance_types.get_default_instance_type()
        sys_meta = utils.dict_to_metadata(
            instance_types.save_instance_type_info({}, basetype))
        self.baseinst['system_metadata'] = sys_meta
        self.basetype = instance_types.extract_instance_type(self.baseinst)
开发者ID:AnyBucket,项目名称:nova,代码行数:26,代码来源:test_simple_tenant_usage.py


示例4: allocate_for_instance

    def allocate_for_instance(self, context, instance, vpn,
                              requested_networks, macs=None,
                              conductor_api=None, security_groups=None,
                              **kwargs):
        """Allocates all network structures for an instance.

        TODO(someone): document the rest of these parameters.

        :param macs: None or a set of MAC addresses that the instance
            should use. macs is supplied by the hypervisor driver (contrast
            with requested_networks which is user supplied).
            NB: macs is ignored by nova-network.
        :returns: network info as from get_instance_nw_info() below
        """
        instance_type = instance_types.extract_instance_type(instance)
        args = {}
        args['vpn'] = vpn
        args['requested_networks'] = requested_networks
        args['instance_id'] = instance['uuid']
        args['project_id'] = instance['project_id']
        args['host'] = instance['host']
        args['rxtx_factor'] = instance_type['rxtx_factor']
        nw_info = self.network_rpcapi.allocate_for_instance(context, **args)

        return network_model.NetworkInfo.hydrate(nw_info)
开发者ID:GoodDingo,项目名称:openstack-nova,代码行数:25,代码来源:api_deprecated.py


示例5: finish_migration

    def finish_migration(self, context, migration, instance, disk_info,
                         network_info, image_meta, resize_instance,
                         block_device_info=None):
        """Completes a resize, turning on the migrated instance

        :param network_info:
           :py:meth:`~nova.network.manager.NetworkManager.get_instance_nw_info`
        :param image_meta: image object returned by nova.image.glance that
                           defines the image from which this instance
                           was created
        """
        lpar_obj = self._powervm._create_lpar_instance(instance)

        instance_type = instance_types.extract_instance_type(instance)
        new_lv_size = instance_type['root_gb']
        old_lv_size = disk_info['old_lv_size']
        if 'root_disk_file' in disk_info:
            disk_size = max(int(new_lv_size), int(old_lv_size))
            disk_size_bytes = disk_size * 1024 * 1024 * 1024
            self._powervm.deploy_from_migrated_file(
                    lpar_obj, disk_info['root_disk_file'], disk_size_bytes)
        else:
            # this shouldn't get hit unless someone forgot to handle
            # a certain migration type
            raise Exception(
                    _('Unrecognized root disk information: %s') %
                    disk_info)
开发者ID:amalaba,项目名称:nova,代码行数:27,代码来源:driver.py


示例6: _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

        """
        compute = self._get_compute_info(context, dest)
        node = compute.get('hypervisor_hostname')
        host_state = self.host_manager.host_state_cls(dest, node)
        host_state.update_from_compute_node(compute)

        instance_type = instance_types.extract_instance_type(instance_ref)
        filter_properties = {'instance_type': instance_type}

        hosts = self.host_manager.get_filtered_hosts([host_state],
                                                     filter_properties,
                                                     'RamFilter')
        if not hosts:
            instance_uuid = instance_ref['uuid']
            reason = _("Unable to migrate %(instance_uuid)s to %(dest)s: "
                       "Lack of memory")
            raise exception.MigrationError(reason=reason % locals())
开发者ID:k-i-t-e,项目名称:nova,代码行数:26,代码来源:filter_scheduler.py


示例7: get_device_name_for_instance

def get_device_name_for_instance(context, instance, bdms, device):
    """Validates (or generates) a device name for instance.

    If device is not set, it will generate a unique device appropriate
    for the instance. It uses the block device mapping table to find
    valid device names. If the device name is valid but applicable to
    a different backend (for example /dev/vdc is specified but the
    backend uses /dev/xvdc), the device name will be converted to the
    appropriate format.
    """
    req_prefix = None
    req_letter = None

    if device:
        try:
            req_prefix, req_letter = block_device.match_device(device)
        except (TypeError, AttributeError, ValueError):
            raise exception.InvalidDevicePath(path=device)

    mappings = block_device.instance_block_mapping(instance, bdms)

    try:
        prefix = block_device.match_device(mappings['root'])[0]
    except (TypeError, AttributeError, ValueError):
        raise exception.InvalidDevicePath(path=mappings['root'])

    # NOTE(vish): remove this when xenapi is setting default_root_device
    if driver.compute_driver_matches('xenapi.XenAPIDriver'):
        prefix = '/dev/xvd'

    if req_prefix != prefix:
        LOG.debug(_("Using %(prefix)s instead of %(req_prefix)s") % locals())

    used_letters = set()
    for device_path in mappings.itervalues():
        letter = block_device.strip_prefix(device_path)
        # NOTE(vish): delete numbers in case we have something like
        #             /dev/sda1
        letter = re.sub("\d+", "", letter)
        used_letters.add(letter)

    # NOTE(vish): remove this when xenapi is properly setting
    #             default_ephemeral_device and default_swap_device
    if driver.compute_driver_matches('xenapi.XenAPIDriver'):
        instance_type = instance_types.extract_instance_type(instance)
        if instance_type['ephemeral_gb']:
            used_letters.add('b')

        if instance_type['swap']:
            used_letters.add('c')

    if not req_letter:
        req_letter = _get_unused_letter(used_letters)

    if req_letter in used_letters:
        raise exception.DevicePathInUse(path=device)

    device_name = prefix + req_letter
    return device_name
开发者ID:AnyBucket,项目名称:nova,代码行数:59,代码来源:utils.py


示例8: _get_root_vhd_size_gb

 def _get_root_vhd_size_gb(self, instance):
     try:
         # In case of resizes we need the old root disk size
         old_instance_type = instance_types.extract_instance_type(
             instance, prefix='old_')
         return old_instance_type['root_gb']
     except KeyError:
         return instance['root_gb']
开发者ID:AnyBucket,项目名称:nova,代码行数:8,代码来源:imagecache.py


示例9: add_fixed_ip_to_instance

 def add_fixed_ip_to_instance(self, context, instance, network_id,
                              conductor_api=None):
     """Adds a fixed ip to instance from specified network."""
     instance_type = instance_types.extract_instance_type(instance)
     args = {'instance_id': instance['uuid'],
             'rxtx_factor': instance_type['rxtx_factor'],
             'host': instance['host'],
             'network_id': network_id}
     self.network_rpcapi.add_fixed_ip_to_instance(context, **args)
开发者ID:Balakrishnan-Vivek,项目名称:nova,代码行数:9,代码来源:api.py


示例10: get_partition_sizes

def get_partition_sizes(instance):
    instance_type = instance_types.extract_instance_type(instance)
    root_mb = instance_type['root_gb'] * 1024
    swap_mb = instance_type['swap']

    if swap_mb < 1:
        swap_mb = 1

    return (root_mb, swap_mb)
开发者ID:CiscoAS,项目名称:nova,代码行数:9,代码来源:tilera.py


示例11: _get_instance_nw_info

    def _get_instance_nw_info(self, context, instance):
        """Returns all network info related to an instance."""
        instance_type = instance_types.extract_instance_type(instance)
        args = {'instance_id': instance['uuid'],
                'rxtx_factor': instance_type['rxtx_factor'],
                'host': instance['host'],
                'project_id': instance['project_id']}
        nw_info = self.network_rpcapi.get_instance_nw_info(context, **args)

        return network_model.NetworkInfo.hydrate(nw_info)
开发者ID:Balakrishnan-Vivek,项目名称:nova,代码行数:10,代码来源:api.py


示例12: _populate_quantum_extension_values

    def _populate_quantum_extension_values(self, instance, port_req_body):
        """Populate quantum extension values for the instance.

        If the extension contains nvp-qos then get the rxtx_factor.
        """
        self._refresh_quantum_extensions_cache()
        if 'nvp-qos' in self.extensions:
            instance_type = instance_types.extract_instance_type(instance)
            rxtx_factor = instance_type.get('rxtx_factor')
            port_req_body['port']['rxtx_factor'] = rxtx_factor
开发者ID:ashkasugai,项目名称:nova,代码行数:10,代码来源:api.py


示例13: remove_fixed_ip_from_instance

    def remove_fixed_ip_from_instance(self, context, instance, address,
                                      conductor_api=None):
        """Removes a fixed ip from instance from specified network."""

        instance_type = instance_types.extract_instance_type(instance)
        args = {'instance_id': instance['uuid'],
                'rxtx_factor': instance_type['rxtx_factor'],
                'host': instance['host'],
                'address': address}
        self.network_rpcapi.remove_fixed_ip_from_instance(context, **args)
开发者ID:Balakrishnan-Vivek,项目名称:nova,代码行数:10,代码来源:api.py


示例14: resize

    def resize(self, context, instance, *args, **kwargs):
        """Resize (ie, migrate) a running instance.

        If flavor_id is None, the process is considered a migration, keeping
        the original flavor_id. If flavor_id is not None, the instance should
        be migrated to a new host and resized to the new flavor_id.
        """
        super(ComputeCellsAPI, self).resize(context, instance, *args, **kwargs)

        # NOTE(johannes): If we get to this point, then we know the
        # specified flavor_id is valid and exists. We'll need to load
        # it again, but that should be safe.

        old_instance_type = instance_types.extract_instance_type(instance)

        flavor_id = kwargs.get("flavor_id")

        if not flavor_id:
            new_instance_type = old_instance_type
        else:
            new_instance_type = instance_types.extract_instance_type(instance, "new_")

        # NOTE(johannes): Later, when the resize is confirmed or reverted,
        # the superclass implementations of those methods will need access
        # to a local migration record for quota reasons. We don't need
        # source and/or destination information, just the old and new
        # instance_types. Status is set to 'finished' since nothing else
        # will update the status along the way.
        self.db.migration_create(
            context.elevated(),
            {
                "instance_uuid": instance["uuid"],
                "old_instance_type_id": old_instance_type["id"],
                "new_instance_type_id": new_instance_type["id"],
                "status": "finished",
            },
        )

        # FIXME(comstud): pass new instance_type object down to a method
        # that'll unfold it
        self._cast_to_cells(context, instance, "resize", *args, **kwargs)
开发者ID:tr3buchet,项目名称:nova,代码行数:41,代码来源:cells_api.py


示例15: _update_usage_from_migration

    def _update_usage_from_migration(self, instance, resources, migration):
        """Update usage for a single migration.  The record may
        represent an incoming or outbound migration.
        """
        uuid = migration['instance_uuid']
        LOG.audit(_("Updating from migration %s") % uuid)

        incoming = (migration['dest_compute'] == self.host and
                    migration['dest_node'] == self.nodename)
        outbound = (migration['source_compute'] == self.host and
                    migration['source_node'] == self.nodename)
        same_node = (incoming and outbound)

        record = self.tracked_instances.get(uuid, None)
        itype = None

        if same_node:
            # same node resize. record usage for whichever instance type the
            # instance is *not* in:
            if (instance['instance_type_id'] ==
                migration['old_instance_type_id']):
                itype = instance_types.extract_instance_type(instance)
            else:
                # instance record already has new flavor, hold space for a
                # possible revert to the old instance type:
                itype = instance_types.extract_instance_type(instance, 'old_')

        elif incoming and not record:
            # instance has not yet migrated here:
            itype = instance_types.extract_instance_type(instance, 'new_')

        elif outbound and not record:
            # instance migrated, but record usage for a possible revert:
            itype = instance_types.extract_instance_type(instance, 'old_')

        if itype:
            self.stats.update_stats_for_migration(itype)
            self._update_usage(resources, itype)
            resources['stats'] = self.stats
            self.tracked_migrations[uuid] = (migration, itype)
开发者ID:emagana,项目名称:nova,代码行数:40,代码来源:resource_tracker.py


示例16: _get_instance_type

    def _get_instance_type(self, context, instance, prefix, instance_type_id=None):
        """Get the instance type from sys metadata if it's stashed.  If not,
        fall back to fetching it via the conductor API.

        See bug 1164110
        """
        if not instance_type_id:
            instance_type_id = instance["instance_type_id"]

        try:
            return instance_types.extract_instance_type(instance, prefix)
        except KeyError:
            return self.conductor_api.instance_type_get(context, instance_type_id)
开发者ID:mygoda,项目名称:openstack,代码行数:13,代码来源:resource_tracker.py


示例17: create_volume_from_image

    def create_volume_from_image(self, context, instance, image_id):
        """Creates a Logical Volume and copies the specified image to it

        :param context: nova context used to retrieve image from glance
        :param instance: instance to create the volume for
        :param image_id: image_id reference used to locate image in glance
        :returns: dictionary with the name of the created
                  Logical Volume device in 'device_name' key
        """

        file_name = '.'.join([image_id, 'gz'])
        file_path = os.path.join(CONF.powervm_img_local_path,
                                 file_name)

        if not os.path.isfile(file_path):
            LOG.debug(_("Fetching image '%s' from glance") % image_id)
            images.fetch(context, image_id, file_path,
                        instance['user_id'],
                        instance['project_id'])
        else:
            LOG.debug((_("Using image found at '%s'") % file_path))

        LOG.debug(_("Ensuring image '%s' exists on IVM") % file_path)
        remote_path = CONF.powervm_img_remote_path
        remote_file_name, size = self._copy_image_file(file_path, remote_path)

        # calculate root device size in bytes
        # we respect the minimum root device size in constants
        instance_type = instance_types.extract_instance_type(instance)
        size_gb = max(instance_type['root_gb'], constants.POWERVM_MIN_ROOT_GB)
        size = size_gb * 1024 * 1024 * 1024

        try:
            LOG.debug(_("Creating logical volume of size %s bytes") % size)
            disk_name = self._create_logical_volume(size)

            LOG.debug(_("Copying image to the device '%s'") % disk_name)
            self._copy_file_to_device(remote_file_name, disk_name)
        except Exception:
            LOG.error(_("Error while creating logical volume from image. "
                        "Will attempt cleanup."))
            # attempt cleanup of logical volume before re-raising exception
            with excutils.save_and_reraise_exception():
                try:
                    self.delete_volume(disk_name)
                except Exception:
                    msg = _('Error while attempting cleanup of failed '
                            'deploy to logical volume.')
                    LOG.exception(msg)

        return {'device_name': disk_name}
开发者ID:AnyBucket,项目名称:nova,代码行数:51,代码来源:blockdev.py


示例18: _test_extract_instance_type

    def _test_extract_instance_type(self, prefix):
        instance_type = instance_types.get_default_instance_type()

        metadata = {}
        instance_types.save_instance_type_info(metadata, instance_type, prefix)
        instance = {"system_metadata": self._dict_to_metadata(metadata)}
        _instance_type = instance_types.extract_instance_type(instance, prefix)

        props = instance_types.system_metadata_instance_type_props.keys()
        for key in instance_type.keys():
            if key not in props:
                del instance_type[key]

        self.assertEqual(instance_type, _instance_type)
开发者ID:jamesbjackson,项目名称:openstack-smartos-nova-grizzly,代码行数:14,代码来源:test_instance_types.py


示例19: _create_migration

    def _create_migration(self, context, instance, instance_type):
        """Create a migration record for the upcoming resize.  This should
        be done while the COMPUTE_RESOURCES_SEMAPHORE is held so the resource
        claim will not be lost if the audit process starts.
        """
        old_instance_type = instance_types.extract_instance_type(instance)

        return self.conductor_api.migration_create(context, instance,
                {'dest_compute': self.host,
                 'dest_node': self.nodename,
                 'dest_host': self.driver.get_host_ip_addr(),
                 'old_instance_type_id': old_instance_type['id'],
                 'new_instance_type_id': instance_type['id'],
                 'status': 'pre-migrating'})
开发者ID:AnyBucket,项目名称:nova,代码行数:14,代码来源:resource_tracker.py


示例20: _get_flavor

 def _get_flavor(self, request, instance):
     instance_type = instance_types.extract_instance_type(instance)
     if not instance_type:
         LOG.warn(_("Instance has had its instance_type removed "
                 "from the DB"), instance=instance)
         return {}
     flavor_id = instance_type["flavorid"]
     flavor_bookmark = self._flavor_builder._get_bookmark_link(request,
                                                               flavor_id,
                                                               "flavors")
     return {
         "id": str(flavor_id),
         "links": [{
             "rel": "bookmark",
             "href": flavor_bookmark,
         }],
     }
开发者ID:zestrada,项目名称:nova-cs498cc,代码行数:17,代码来源:servers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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