本文整理汇总了Python中nova.compute.flavors.extract_flavor函数的典型用法代码示例。如果您正苦于以下问题:Python extract_flavor函数的具体用法?Python extract_flavor怎么用?Python extract_flavor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了extract_flavor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zero_root_gb_disables_check
def test_zero_root_gb_disables_check(self):
self.mox.StubOutWithMock(flavors, "extract_flavor")
flavors.extract_flavor(self.instance).AndReturn(dict(root_gb=0))
self.mox.ReplayAll()
vm_utils._check_vdi_size(self.context, self.session, self.instance, self.vdi_uuid)
示例2: test_find_destination_retry_with_invalid_livem_checks
def test_find_destination_retry_with_invalid_livem_checks(self):
self.flags(migrate_max_retries=1)
self.mox.StubOutWithMock(self.task.image_service, 'show')
self.mox.StubOutWithMock(flavors, 'extract_flavor')
self.mox.StubOutWithMock(self.task.scheduler_rpcapi, 'select_hosts')
self.mox.StubOutWithMock(self.task,
'_check_compatible_with_source_hypervisor')
self.mox.StubOutWithMock(self.task, '_call_livem_checks_on_host')
self.task.image_service.show(self.context,
self.instance_image).AndReturn("image")
flavors.extract_flavor(self.instance).AndReturn("inst_type")
self.task.scheduler_rpcapi.select_hosts(self.context, mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(["host1"])
self.task._check_compatible_with_source_hypervisor("host1")
self.task._call_livem_checks_on_host("host1")\
.AndRaise(exception.Invalid)
self.task.scheduler_rpcapi.select_hosts(self.context, mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(["host2"])
self.task._check_compatible_with_source_hypervisor("host2")
self.task._call_livem_checks_on_host("host2")
self.mox.ReplayAll()
self.assertEqual("host2", self.task._find_destination())
示例3: test_not_too_large
def test_not_too_large(self):
self.mox.StubOutWithMock(flavors, "extract_flavor")
flavors.extract_flavor(self.instance).AndReturn(dict(root_gb=1))
self.mox.StubOutWithMock(vm_utils, "_get_vdi_chain_size")
vm_utils._get_vdi_chain_size(self.session, self.vdi_uuid).AndReturn(1073741824)
self.mox.ReplayAll()
vm_utils._check_vdi_size(self.context, self.session, self.instance, self.vdi_uuid)
示例4: test_build_request_spec_without_image
def test_build_request_spec_without_image(self):
image = None
instance = {'uuid': 'fake-uuid'}
instance_type = {'flavorid': 'fake-id'}
self.mox.StubOutWithMock(flavors, 'extract_flavor')
flavors.extract_flavor(mox.IgnoreArg()).AndReturn(instance_type)
self.mox.ReplayAll()
request_spec = scheduler_utils.build_request_spec(self.context, image,
[instance])
self.assertEqual({}, request_spec['image'])
示例5: test_build_request_spec_without_image
def test_build_request_spec_without_image(self, mock_get):
image = None
instance = {'uuid': 'fake-uuid'}
instance_type = objects.Flavor(**test_flavor.fake_flavor)
mock_get.return_value = objects.Flavor(extra_specs={})
self.mox.StubOutWithMock(flavors, 'extract_flavor')
flavors.extract_flavor(mox.IgnoreArg()).AndReturn(instance_type)
self.mox.ReplayAll()
request_spec = scheduler_utils.build_request_spec(self.context, image,
[instance])
self.assertEqual({}, request_spec['image'])
示例6: test_too_large
def test_too_large(self):
self.mox.StubOutWithMock(flavors, 'extract_flavor')
flavors.extract_flavor(self.instance).AndReturn(
dict(root_gb=1))
self.mox.StubOutWithMock(vm_utils, '_get_vdi_chain_size')
vm_utils._get_vdi_chain_size(self.session,
self.vdi_uuid).AndReturn(1073741825)
self.mox.ReplayAll()
self.assertRaises(exception.InstanceTypeDiskTooSmall,
vm_utils._check_vdi_size, self.context, self.session,
self.instance, self.vdi_uuid)
示例7: test_find_destination_works
def test_find_destination_works(self):
self.mox.StubOutWithMock(self.task.image_service, 'show')
self.mox.StubOutWithMock(flavors, 'extract_flavor')
self.mox.StubOutWithMock(self.task,
'_check_compatible_with_source_hypervisor')
self.mox.StubOutWithMock(self.task, '_call_livem_checks_on_host')
self.task.image_service.show(self.context,
self.instance_image).AndReturn("image")
flavors.extract_flavor(self.instance).AndReturn("inst_type")
self.task._check_compatible_with_source_hypervisor("host1")
self.task._call_livem_checks_on_host("host1")
self.mox.ReplayAll()
self.assertEqual("host1", self.task._find_destination())
示例8: build_request_spec
def build_request_spec(ctxt, image, instances, instance_type=None):
"""Build a request_spec for the scheduler.
The request_spec assumes that all instances to be scheduled are the same
type.
"""
instance = instances[0]
if instance_type is None:
if isinstance(instance, objects.Instance):
instance_type = instance.get_flavor()
else:
instance_type = flavors.extract_flavor(instance)
if isinstance(instance, objects.Instance):
instance = instance_obj.compat_instance(instance)
if isinstance(instance_type, objects.Flavor):
instance_type = obj_base.obj_to_primitive(instance_type)
request_spec = {
'image': image or {},
'instance_properties': instance,
'instance_type': instance_type,
'num_instances': len(instances)}
return jsonutils.to_primitive(request_spec)
示例9: allocate_for_instance
def allocate_for_instance(self, context, instance, vpn,
requested_networks, macs=None,
conductor_api=None, security_groups=None,
dhcp_options=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).
:param dhcp_options: None or a set of key/value pairs that should
determine the DHCP BOOTP response, eg. for PXE booting an instance
configured with the baremetal hypervisor. It is expected that these
are already formatted for the neutron v2 api.
See nova/virt/driver.py:dhcp_options_for_instance for an example.
: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 = flavors.extract_flavor(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
args['dhcp_options'] = dhcp_options
nw_info = self.network_rpcapi.allocate_for_instance(context, **args)
return network_model.NetworkInfo.hydrate(nw_info)
示例10: test_resize
def test_resize(self):
self.mox.StubOutWithMock(self.compute_api, 'update')
self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
self.mox.StubOutWithMock(self.compute_api.compute_task_api,
'migrate_server')
if self.is_cells:
self.mox.StubOutWithMock(self.compute_api.db, 'migration_create')
self.compute_api.db.migration_create(mox.IgnoreArg(),
mox.IgnoreArg())
inst = self._create_instance_obj()
self.compute_api.update(self.context, inst, expected_task_state=None,
progress=0,
task_state='resize_prep').AndReturn(inst)
self.compute_api._record_action_start(self.context, inst, 'resize')
filter_properties = {'ignore_hosts': ['fake_host', 'fake_host']}
scheduler_hint = {'filter_properties': filter_properties}
flavor = flavors.extract_flavor(inst)
self.compute_api.compute_task_api.migrate_server(
self.context, inst, scheduler_hint=scheduler_hint,
live=False, rebuild=False, flavor=flavor,
block_migration=None, disk_over_commit=None,
reservations=None)
self.mox.ReplayAll()
self.compute_api.resize(self.context, inst)
示例11: get_image_metadata
def get_image_metadata(context, image_api, image_id_or_uri, instance):
image_system_meta = {}
# In case of boot from volume, image_id_or_uri may be None
if image_id_or_uri is not None:
# If the base image is still available, get its metadata
try:
image = image_api.get(context, image_id_or_uri)
except (exception.ImageNotAuthorized,
exception.ImageNotFound,
exception.Invalid) as e:
LOG.warning(_LW("Can't access image %(image_id)s: %(error)s"),
{"image_id": image_id_or_uri, "error": e},
instance=instance)
else:
flavor = flavors.extract_flavor(instance)
image_system_meta = utils.get_system_metadata_from_image(image,
flavor)
# Get the system metadata from the instance
system_meta = utils.instance_sys_meta(instance)
# Merge the metadata from the instance with the image's, if any
system_meta.update(image_system_meta)
# Convert the system metadata to image metadata
return utils.get_image_from_system_metadata(system_meta)
示例12: _find_destination
def _find_destination(self):
#TODO(johngarbutt) this retry loop should be shared
attempted_hosts = [self.source]
image = None
if self.instance.image_ref:
image = compute_utils.get_image_metadata(self.context,
self.image_service,
self.instance.image_ref,
self.instance)
instance_type = flavors.extract_flavor(self.instance)
host = None
while host is None:
self._check_not_over_max_retries(attempted_hosts)
host = self._get_candidate_destination(image,
instance_type, attempted_hosts)
try:
self._check_compatible_with_source_hypervisor(host)
self._call_livem_checks_on_host(host)
except exception.Invalid as e:
LOG.debug(_("Skipping host: %(host)s because: %(e)s") %
{"host": host, "e": e})
attempted_hosts.append(host)
host = None
return host
示例13: test_find_destination_when_runs_out_of_hosts
def test_find_destination_when_runs_out_of_hosts(self):
self.mox.StubOutWithMock(self.task.image_service, 'show')
self.mox.StubOutWithMock(flavors, 'extract_flavor')
self.mox.StubOutWithMock(self.task.scheduler_rpcapi, 'select_hosts')
self.mox.StubOutWithMock(self.task,
'_check_compatible_with_source_hypervisor')
self.mox.StubOutWithMock(self.task, '_call_livem_checks_on_host')
self.task.image_service.show(self.context,
self.instance_image).AndReturn("image")
flavors.extract_flavor(self.instance).AndReturn("inst_type")
self.task.scheduler_rpcapi.select_hosts(self.context, mox.IgnoreArg(),
mox.IgnoreArg()).AndRaise(exception.NoValidHost(reason=""))
self.mox.ReplayAll()
self.assertRaises(exception.NoValidHost, self.task._find_destination)
示例14: build_request_spec
def build_request_spec(ctxt, image, instances, instance_type=None):
"""Build a request_spec for the scheduler.
The request_spec assumes that all instances to be scheduled are the same
type.
"""
instance = instances[0]
if isinstance(instance, obj_base.NovaObject):
instance = obj_base.obj_to_primitive(instance)
if instance_type is None:
instance_type = flavors.extract_flavor(instance)
# NOTE(comstud): This is a bit ugly, but will get cleaned up when
# we're passing an InstanceType internal object.
extra_specs = db.flavor_extra_specs_get(ctxt, instance_type['flavorid'])
instance_type['extra_specs'] = extra_specs
request_spec = {
'image': image or {},
'instance_properties': instance,
'instance_type': instance_type,
'num_instances': len(instances),
# NOTE(alaski): This should be removed as logic moves from the
# scheduler to conductor. Provides backwards compatibility now.
'instance_uuids': [inst['uuid'] for inst in instances]}
return jsonutils.to_primitive(request_spec)
示例15: build_request_spec
def build_request_spec(ctxt, image, instances, instance_type=None):
"""Build a request_spec for the scheduler.
The request_spec assumes that all instances to be scheduled are the same
type.
"""
instance = instances[0]
if isinstance(instance, obj_base.NovaObject):
instance = obj_base.obj_to_primitive(instance)
if instance_type is None:
instance_type = flavors.extract_flavor(instance)
# NOTE(danms): This won't have extra_specs, so fill in the gaps
_instance_type = objects.Flavor.get_by_flavor_id(
ctxt, instance_type['flavorid'])
instance_type.extra_specs = instance_type.get('extra_specs', {})
instance_type.extra_specs.update(_instance_type.extra_specs)
if isinstance(instance_type, objects.Flavor):
instance_type = obj_base.obj_to_primitive(instance_type)
request_spec = {
'image': image or {},
'instance_properties': instance,
'instance_type': instance_type,
'num_instances': len(instances)}
return jsonutils.to_primitive(request_spec)