本文整理汇总了Python中nova.compute.instance_types.get_instance_type函数的典型用法代码示例。如果您正苦于以下问题:Python get_instance_type函数的具体用法?Python get_instance_type怎么用?Python get_instance_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_instance_type函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _get_disk_size_mb
def _get_disk_size_mb(self, instance):
inst_type_id = instance['instance_type_id']
inst_type = instance_types.get_instance_type(inst_type_id)
if inst_type["local_gb"] == 0:
return 10 * 1024
return inst_type["local_gb"] * 1024
开发者ID:AsylumCorp,项目名称:dodai-compute,代码行数:7,代码来源:connection.py
示例2: _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.
"""
# TODO(russellb): no-db-compute: Send the old instance type
# info that is needed via rpc so db access isn't required
# here.
old_instance_type_id = instance["instance_type_id"]
old_instance_type = instance_types.get_instance_type(old_instance_type_id)
return db.migration_create(
context.elevated(),
{
"instance_uuid": instance["uuid"],
"source_compute": instance["host"],
"source_node": instance["node"],
"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:ameade,项目名称:nova,代码行数:25,代码来源:resource_tracker.py
示例3: _select_machine
def _select_machine(self, context, instance):
inst_type = instance_types.get_instance_type(instance['instance_type_id'])
bmm_found = None
reuse = False
# create a non autocommit session
session = get_session_dodai(False)
session.begin()
try:
bmms = db.bmm_get_all_by_instance_type(context, inst_type["name"], session)
if instance["availability_zone"] == "resource_pool": #Add a machine to resource pool.
for bmm in bmms:
if bmm["availability_zone"] != "resource_pool":
continue
if bmm["status"] != "inactive":
continue
bmm_found = bmm
break
else:
for bmm in bmms:
if bmm["availability_zone"] != "resource_pool":
continue
if bmm["status"] != "active":
continue
instance_ref = db.instance_get(context, bmm["instance_id"])
if instance_ref["image_ref"] != instance["image_ref"]:
continue
bmm_found = bmm
reuse = True
break
if not bmm_found:
for bmm in bmms:
if bmm["status"] == "used" or bmm["status"] == "processing":
continue
bmm_found = bmm
reuse = False
break
if bmm_found:
db.bmm_update(context, bmm_found["id"], {"status": "processing"}, session)
except Exception as ex:
LOG.exception(ex)
session.rollback()
raise exception.BareMetalMachineUnavailable()
session.commit()
if bmm_found:
return bmm_found, reuse
raise exception.BareMetalMachineUnavailable()
开发者ID:AsylumCorp,项目名称:dodai-compute,代码行数:59,代码来源:connection.py
示例4: ensure_free_mem
def ensure_free_mem(cls, session, instance):
inst_type_id = instance.instance_type_id
instance_type = instance_types.get_instance_type(inst_type_id)
mem = long(instance_type["memory_mb"]) * 1024 * 1024
# get free memory from host
host = session.get_xenapi_host()
host_free_mem = long(session.get_xenapi().host.compute_free_memory(host))
return host_free_mem >= mem
开发者ID:rajarammallya,项目名称:openstack-nova,代码行数:8,代码来源:vm_utils.py
示例5: activate_bootloader
def activate_bootloader(self, var, context, node, instance):
image_path = var['image_path']
inst_type_id = instance['instance_type_id']
inst_type = instance_types.get_instance_type(inst_type_id)
network_info = var['network_info']
nets = self._find_MAC_Addresses(network_info)
self._getregion(image_path, node, nets)
LOG.debug("successfully bypassing activate_bootloader")
开发者ID:stuartbyma,项目名称:nova,代码行数:8,代码来源:pr_virt.py
示例6: _setUpBlockDeviceMapping
def _setUpBlockDeviceMapping(self):
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
sys_meta = instance_types.save_instance_type_info(
{}, instance_types.get_instance_type(1))
inst1 = db.instance_create(self.context,
{'image_ref': image_uuid,
'instance_type_id': 1,
'root_device_name': '/dev/sdb1',
'system_metadata': sys_meta})
inst2 = db.instance_create(self.context,
{'image_ref': image_uuid,
'instance_type_id': 1,
'root_device_name': '/dev/sdc1',
'system_metadata': sys_meta})
instance_uuid = inst1['uuid']
mappings0 = [
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb1',
'snapshot_id': '1',
'volume_id': '2'},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb2',
'volume_id': '3',
'volume_size': 1},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb3',
'delete_on_termination': True,
'snapshot_id': '4',
'volume_id': '5'},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb4',
'delete_on_termination': False,
'snapshot_id': '6',
'volume_id': '7'},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb5',
'snapshot_id': '8',
'volume_id': '9',
'volume_size': 0},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb6',
'snapshot_id': '10',
'volume_id': '11',
'volume_size': 1},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb7',
'no_device': True},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb8',
'virtual_name': 'swap'},
{'instance_uuid': instance_uuid,
'device_name': '/dev/sdb9',
'virtual_name': 'ephemeral3'}]
volumes = self._block_device_mapping_create(instance_uuid, mappings0)
return (inst1, inst2, volumes)
开发者ID:achbarou,项目名称:nova,代码行数:57,代码来源:test_cinder_cloud.py
示例7: _instance_to_router
def _instance_to_router(self, context, instance, image_meta):
inst_type = \
instance_types.get_instance_type(instance["instance_type_id"])
chassis = self._chassis_for_flavor(inst_type['name'])
C = self._class_for_instance(image_meta)
r = C(self.dynamips, name=instance["id"], chassis=chassis)
r.os_name = instance["name"]
r.ram = inst_type["memory_mb"]
r.os_prototype = instance
return r
开发者ID:leloulight,项目名称:nova-dynamips-driver,代码行数:10,代码来源:dynamips.py
示例8: get_device_name_for_instance
def get_device_name_for_instance(context, instance, 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_letters = None
if device:
try:
req_prefix, req_letters = block_device.match_device(device)
except (TypeError, AttributeError, ValueError):
raise exception.InvalidDevicePath(path=device)
bdms = db.block_device_mapping_get_all_by_instance(context,
instance['uuid'])
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 (FLAGS.connection_type == 'xenapi' or
FLAGS.compute_driver.endswith('xenapi.XenAPIDriver')):
prefix = '/dev/xvd'
if req_prefix != prefix:
LOG.debug(_("Using %(prefix)s instead of %(req_prefix)s") % locals())
letters_list = []
for _name, device in mappings.iteritems():
letter = block_device.strip_prefix(device)
# NOTE(vish): delete numbers in case we have something like
# /dev/sda1
letter = re.sub("\d+", "", letter)
letters_list.append(letter)
used_letters = set(letters_list)
# NOTE(vish): remove this when xenapi is properly setting
# default_ephemeral_device and default_swap_device
if (FLAGS.connection_type == 'xenapi' or
FLAGS.compute_driver.endswith('xenapi.XenAPIDriver')):
instance_type_id = instance['instance_type_id']
instance_type = instance_types.get_instance_type(instance_type_id)
if instance_type['ephemeral_gb']:
used_letters.update('b')
if instance_type['swap']:
used_letters.update('c')
if not req_letters:
req_letters = _get_unused_letters(used_letters)
if req_letters in used_letters:
raise exception.DevicePathInUse(path=device)
return prefix + req_letters
开发者ID:Mirantis,项目名称:nova,代码行数:55,代码来源:utils.py
示例9: get_info
def get_info(self, instance):
n = self._router_by_name(instance["name"])
mem_mb = instance_types.get_instance_type(
n.os_prototype['instance_type_id']).get("memory_mb")
return {
'state': n.os_state,
'max_mem': int(mem_mb) * 1024,
'mem': n.ram * 1024,
'num_cpu': 1,
'cpu_time': 0 # cpuinfo?
}
开发者ID:leloulight,项目名称:nova-dynamips-driver,代码行数:11,代码来源:dynamips.py
示例10: test_instance_type_create_then_delete
def test_instance_type_create_then_delete(self):
"""Ensure instance types can be created"""
starting_inst_list = instance_types.get_all_types()
instance_types.create(self.name, 256, 1, 120, self.flavorid)
new = instance_types.get_all_types()
self.assertNotEqual(len(starting_inst_list), len(new), "instance type was not created")
instance_types.destroy(self.name)
self.assertEqual(1, instance_types.get_instance_type(self.id)["deleted"])
self.assertEqual(starting_inst_list, instance_types.get_all_types())
instance_types.purge(self.name)
self.assertEqual(len(starting_inst_list), len(instance_types.get_all_types()), "instance type not purged")
开发者ID:rajarammallya,项目名称:openstack-nova,代码行数:11,代码来源:test_instance_types.py
示例11: fetch_blank_disk
def fetch_blank_disk(cls, session, instance_type_id):
# Size the blank harddrive to suit the machine type:
one_gig = 1024 * 1024 * 1024
req_type = instance_types.get_instance_type(instance_type_id)
req_size = req_type["local_gb"]
LOG.debug("Creating blank HD of size %(req_size)d gigs" % locals())
vdi_size = one_gig * req_size
LOG.debug("ISO vm create: Looking for the SR")
sr_ref = safe_find_sr(session)
vdi_ref = cls.create_vdi(session, sr_ref, "blank HD", vdi_size, False)
return vdi_ref
开发者ID:nfantini,项目名称:openstack-bill,代码行数:14,代码来源:vm_utils.py
示例12: get_partition_sizes
def get_partition_sizes(instance):
type_id = instance["instance_type_id"]
root_mb = instance["root_gb"] * 1024
# NOTE(deva): is there a way to get swap_mb directly from instance?
swap_mb = instance_types.get_instance_type(type_id)["swap"]
# NOTE(deva): For simpler code paths on the deployment side,
# we always create a swap partition. If the flavor
# does not specify any swap, we default to 1MB
if swap_mb < 1:
swap_mb = 1
return (root_mb, swap_mb)
开发者ID:gtriolo,项目名称:nova,代码行数:14,代码来源:pxe.py
示例13: get_instance_nw_info
def get_instance_nw_info(self, context, instance_id, instance_uuid,
instance_type_id, host):
"""This method is used by compute to fetch all network data
that should be used when creating the VM.
The method simply loops through all virtual interfaces
stored in the nova DB and queries the IPAM lib to get
the associated IP data.
The format of returned data is 'defined' by the initial
set of NetworkManagers found in nova/network/manager.py .
Ideally this 'interface' will be more formally defined
in the future.
"""
admin_context = context.elevated()
project_id = context.project_id
vifs = db.virtual_interface_get_by_instance(context, instance_id)
instance_type = instance_types.get_instance_type(instance_type_id)
net_tenant_dict = dict((net_id, tenant_id)
for (net_id, tenant_id)
in self.ipam.get_project_and_global_net_ids(
context, project_id))
networks = {}
for vif in vifs:
if vif.get('network_id') is not None:
network = db.network_get(admin_context, vif['network_id'])
net_tenant_id = net_tenant_dict[network['uuid']]
if net_tenant_id is None:
net_tenant_id = FLAGS.quantum_default_tenant_id
network = {'id': network['id'],
'uuid': network['uuid'],
'bridge': 'ovs_flag',
'label': self.q_conn.get_network_name(net_tenant_id,
network['uuid']),
'project_id': net_tenant_id}
networks[vif['uuid']] = network
# update instance network cache and return network_info
nw_info = self.build_network_info_model(context, vifs, networks,
instance_type, host)
db.instance_info_cache_update(context, instance_uuid,
{'network_info': nw_info.as_cache()})
return nw_info
开发者ID:xinnet-iaas-openstack,项目名称:io,代码行数:45,代码来源:manager.py
示例14: _live_migration_instance
def _live_migration_instance(self):
inst_type = instance_types.get_instance_type(1)
# NOTE(danms): we have _got_ to stop doing this!
inst_type['memory_mb'] = 1024
sys_meta = utils.dict_to_metadata(
instance_types.save_instance_type_info({}, inst_type))
return {'id': 31337,
'uuid': 'fake_uuid',
'name': 'fake-instance',
'host': 'fake_host1',
'power_state': power_state.RUNNING,
'memory_mb': 1024,
'root_gb': 1024,
'ephemeral_gb': 0,
'vm_state': '',
'task_state': '',
'instance_type_id': inst_type['id'],
'image_ref': 'fake-image-ref',
'system_metadata': sys_meta}
开发者ID:achbarou,项目名称:nova,代码行数:19,代码来源:test_scheduler.py
示例15: activate_bootloader
def activate_bootloader(self, var, context, node, instance):
tftp_root = var['tftp_root']
image_root = var['image_root']
disk_path = os.path.join(image_root, 'disk')
image_path = tftp_root + "/disk_" + str(node['id'])
target_path = tftp_root + "/fs_" + str(node['id'])
utils.execute('mv', disk_path, image_path, run_as_root=True)
utils.execute('mount', '-o', 'loop', image_path, target_path,
run_as_root=True)
root_mb = instance['root_gb'] * 1024
inst_type_id = instance['instance_type_id']
inst_type = instance_types.get_instance_type(inst_type_id)
swap_mb = inst_type['swap']
if swap_mb < 1024:
swap_mb = 1024
iscsi_iqn = "iqn-%s" % str(instance['uuid'])
iscsi_portal = None
开发者ID:hesamrahimi,项目名称:nova,代码行数:20,代码来源:tilera.py
示例16: _prepare_xml_info
def _prepare_xml_info(self, instance, network_info, rescue, block_device_info=None):
# block_device_mapping = driver.block_device_info_get_mapping(
# block_device_info)
_map = 0
for (_, mapping) in network_info:
_map += 1
nics = []
# FIXME(vish): stick this in db
inst_type_id = instance["instance_type_id"]
inst_type = instance_types.get_instance_type(inst_type_id)
driver_type = "raw"
xml_info = {
"type": FLAGS.baremetal_type,
"name": instance["name"],
"basepath": os.path.join(FLAGS.instances_path, instance["name"]),
"memory_kb": inst_type["memory_mb"] * 1024,
"vcpus": inst_type["vcpus"],
"rescue": rescue,
"driver_type": driver_type,
"nics": nics,
"ip_address": mapping["ips"][0]["ip"],
"mac_address": mapping["mac"],
"user_data": instance["user_data"],
"image_id": instance["image_ref"],
"kernel_id": instance["kernel_id"],
"ramdisk_id": instance["ramdisk_id"],
}
if not rescue:
if instance["kernel_id"]:
xml_info["kernel"] = xml_info["basepath"] + "/kernel"
if instance["ramdisk_id"]:
xml_info["ramdisk"] = xml_info["basepath"] + "/ramdisk"
xml_info["disk"] = xml_info["basepath"] + "/disk"
return xml_info
开发者ID:OpenStack-Kha,项目名称:nova,代码行数:40,代码来源:proxy.py
示例17: _prepare_xml_info
def _prepare_xml_info(self, instance, network_info, rescue,
block_device_info=None):
# block_device_mapping = driver.block_device_info_get_mapping(
# block_device_info)
map = 0
for (network, mapping) in network_info:
map += 1
nics = []
# FIXME(vish): stick this in db
inst_type_id = instance['instance_type_id']
inst_type = instance_types.get_instance_type(inst_type_id)
driver_type = 'raw'
xml_info = {'type': FLAGS.baremetal_type,
'name': instance['name'],
'basepath': os.path.join(FLAGS.instances_path,
instance['name']),
'memory_kb': inst_type['memory_mb'] * 1024,
'vcpus': inst_type['vcpus'],
'rescue': rescue,
'driver_type': driver_type,
'nics': nics,
'ip_address': mapping['ips'][0]['ip'],
'mac_address': mapping['mac'],
'user_data': instance['user_data'],
'image_id': instance['image_ref'],
'kernel_id': instance['kernel_id'],
'ramdisk_id': instance['ramdisk_id']}
if not rescue:
if instance['kernel_id']:
xml_info['kernel'] = xml_info['basepath'] + "/kernel"
if instance['ramdisk_id']:
xml_info['ramdisk'] = xml_info['basepath'] + "/ramdisk"
xml_info['disk'] = xml_info['basepath'] + "/disk"
return xml_info
开发者ID:derekhiggins,项目名称:nova,代码行数:40,代码来源:proxy.py
示例18: 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_id = instance['instance_type_id']
old_instance_type = instance_types.get_instance_type(
old_instance_type_id)
flavor_id = kwargs.get('flavor_id')
if not flavor_id:
new_instance_type = old_instance_type
else:
new_instance_type = instance_types.get_instance_type_by_flavor_id(
flavor_id)
# 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:bihicheng,项目名称:nova,代码行数:40,代码来源:cells_api.py
示例19: test_instance_type_create_then_delete
def test_instance_type_create_then_delete(self):
"""Ensure instance types can be created"""
name = 'Small Flavor'
flavorid = 'flavor1'
original_list = instance_types.get_all_types()
# create new type and make sure values stick
inst_type = instance_types.create(name, 256, 1, 120, flavorid)
inst_type_id = inst_type['id']
self.assertEqual(inst_type['flavorid'], flavorid)
self.assertEqual(inst_type['name'], name)
self.assertEqual(inst_type['memory_mb'], 256)
self.assertEqual(inst_type['vcpus'], 1)
self.assertEqual(inst_type['local_gb'], 120)
self.assertEqual(inst_type['swap'], 0)
self.assertEqual(inst_type['rxtx_quota'], 0)
self.assertEqual(inst_type['rxtx_cap'], 0)
# make sure new type shows up in list
new_list = instance_types.get_all_types()
self.assertNotEqual(len(original_list), len(new_list),
'instance type was not created')
# destroy instance and make sure deleted flag is set to True
instance_types.destroy(name)
inst_type = instance_types.get_instance_type(inst_type_id)
self.assertEqual(1, inst_type["deleted"])
# deleted instance should not be in list anymoer
new_list = instance_types.get_all_types()
self.assertEqual(original_list, new_list)
# ensure instances are gone after purge
instance_types.purge(name)
new_list = instance_types.get_all_types()
self.assertEqual(original_list, new_list,
'instance type not purged')
开发者ID:BillTheBest,项目名称:nova,代码行数:38,代码来源:test_instance_types.py
示例20: create_vm
def create_vm(cls, session, instance, kernel, ramdisk,
use_pv_kernel=False):
"""Create a VM record. Returns a Deferred that gives the new
VM reference.
the use_pv_kernel flag indicates whether the guest is HVM or PV
There are 3 scenarios:
1. Using paravirtualization, kernel passed in
2. Using paravirtualization, kernel within the image
3. Using hardware virtualization
"""
inst_type_id = instance.instance_type_id
instance_type = instance_types.get_instance_type(inst_type_id)
mem = str(long(instance_type['memory_mb']) * 1024 * 1024)
vcpus = str(instance_type['vcpus'])
rec = {
'actions_after_crash': 'destroy',
'actions_after_reboot': 'restart',
'actions_after_shutdown': 'destroy',
'affinity': '',
'blocked_operations': {},
'ha_always_run': False,
'ha_restart_priority': '',
'HVM_boot_params': {},
'HVM_boot_policy': '',
'is_a_template': False,
'memory_dynamic_min': mem,
'memory_dynamic_max': mem,
'memory_static_min': '0',
'memory_static_max': mem,
'memory_target': mem,
'name_description': '',
'name_label': instance.name,
'other_config': {'allowvssprovider': False},
'other_config': {},
'PCI_bus': '',
'platform': {'acpi': 'true', 'apic': 'true', 'pae': 'true',
'viridian': 'true', 'timeoffset': '0'},
'PV_args': '',
'PV_bootloader': '',
'PV_bootloader_args': '',
'PV_kernel': '',
'PV_legacy_args': '',
'PV_ramdisk': '',
'recommendations': '',
'tags': [],
'user_version': '0',
'VCPUs_at_startup': vcpus,
'VCPUs_max': vcpus,
'VCPUs_params': {},
'xenstore_data': {}}
# Complete VM configuration record according to the image type
# non-raw/raw with PV kernel/raw in HVM mode
if use_pv_kernel:
rec['platform']['nx'] = 'false'
if instance.kernel_id:
# 1. Kernel explicitly passed in, use that
rec['PV_args'] = 'root=/dev/xvda1'
rec['PV_kernel'] = kernel
rec['PV_ramdisk'] = ramdisk
else:
# 2. Use kernel within the image
rec['PV_bootloader'] = 'pygrub'
else:
# 3. Using hardware virtualization
rec['platform']['nx'] = 'true'
rec['HVM_boot_params'] = {'order': 'dc'}
rec['HVM_boot_policy'] = 'BIOS order'
LOG.debug(_('Created VM %s...'), instance.name)
vm_ref = session.call_xenapi('VM.create', rec)
instance_name = instance.name
LOG.debug(_('Created VM %(instance_name)s as %(vm_ref)s.') % locals())
return vm_ref
开发者ID:kavanista,项目名称:nova,代码行数:78,代码来源:vm_utils.py
注:本文中的nova.compute.instance_types.get_instance_type函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论