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


Python instance_types.extract_instance_type函数代码示例

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


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


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