本文整理汇总了Python中nova.compute.instance_types.get_instance_type函数的典型用法代码示例。如果您正苦于以下问题:Python get_instance_type函数的具体用法?Python get_instance_type怎么用?Python get_instance_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_instance_type函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
示例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",
},
)
示例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()
示例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
示例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")
示例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)
示例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
示例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
示例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?
}
示例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")
示例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
示例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)
示例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
示例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}
示例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