本文整理汇总了Python中nova.compute.flavors.get_flavor_by_flavor_id函数的典型用法代码示例。如果您正苦于以下问题:Python get_flavor_by_flavor_id函数的具体用法?Python get_flavor_by_flavor_id怎么用?Python get_flavor_by_flavor_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_flavor_by_flavor_id函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_resize_quota_exceeds_fails
def test_resize_quota_exceeds_fails(self):
self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
self.mox.StubOutWithMock(self.compute_api, '_upsize_quota_delta')
self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
# Should never reach these.
self.mox.StubOutWithMock(self.compute_api, 'update')
self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
self.mox.StubOutWithMock(self.compute_api.compute_task_api,
'migrate_server')
fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
current_flavor = flavors.extract_flavor(fake_inst)
fake_flavor = dict(id=200, flavorid='flavor-id', name='foo',
disabled=False)
flavors.get_flavor_by_flavor_id(
'flavor-id', read_deleted='no').AndReturn(fake_flavor)
deltas = dict(resource=0)
self.compute_api._upsize_quota_delta(
self.context, fake_flavor,
current_flavor).AndReturn(deltas)
usage = dict(in_use=0, reserved=0)
over_quota_args = dict(quotas={'resource': 0},
usages={'resource': usage},
overs=['resource'])
self.compute_api._reserve_quota_delta(self.context, deltas,
project_id=fake_inst['project_id']).AndRaise(
exception.OverQuota(**over_quota_args))
self.mox.ReplayAll()
self.assertRaises(exception.TooManyInstances,
self.compute_api.resize, self.context,
fake_inst, flavor_id='flavor-id')
示例2: instance_create
def instance_create(context, inst):
inst_type = flavors.get_flavor_by_flavor_id(3)
image_uuid = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
def_image_ref = "http://localhost/v3/os-images/%s" % image_uuid
self.instance_cache_num += 1
instance = {
"id": self.instance_cache_num,
"display_name": inst["display_name"] or "test",
"uuid": MANUAL_INSTANCE_UUID,
"instance_type": dict(inst_type),
"access_ip_v4": "1.2.3.4",
"access_ip_v6": "fead::1234",
"image_ref": inst.get("image_ref", def_image_ref),
"user_id": "fake",
"project_id": "fake",
"reservation_id": inst["reservation_id"],
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"user_data": None,
"progress": 0,
"fixed_ips": [],
"task_state": "",
"vm_state": "",
}
self.instance_cache_by_id[instance["id"]] = instance
self.instance_cache_by_uuid[instance["uuid"]] = instance
return instance
示例3: instance_create
def instance_create(context, inst):
inst_type = flavors.get_flavor_by_flavor_id(3)
image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
def_image_ref = 'http://localhost/images/%s' % image_uuid
self.instance_cache_num += 1
instance = fake_instance.fake_db_instance(**{
'id': self.instance_cache_num,
'display_name': inst['display_name'] or 'test',
'uuid': FAKE_UUID,
'instance_type': inst_type,
'access_ip_v4': '1.2.3.4',
'access_ip_v6': 'fead::1234',
'image_ref': inst.get('image_ref', def_image_ref),
'user_id': 'fake',
'project_id': 'fake',
'reservation_id': inst['reservation_id'],
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"config_drive": None,
"progress": 0,
"fixed_ips": [],
"task_state": "",
"vm_state": "",
"root_device_name": inst.get('root_device_name', 'vda'),
"security_groups": inst['security_groups'],
"extra": {"pci_requests": None,
"numa_topology": None},
})
self.instance_cache_by_id[instance['id']] = instance
self.instance_cache_by_uuid[instance['uuid']] = instance
return instance
示例4: instance_create
def instance_create(context, inst):
inst_type = flavors.get_flavor_by_flavor_id(3)
image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
def_image_ref = 'http://localhost/images/{0!s}'.format(image_uuid)
self.instance_cache_num += 1
instance = fake_instance.fake_db_instance(**{
'id': self.instance_cache_num,
'display_name': inst['display_name'] or 'test',
'uuid': inst['uuid'],
'instance_type': inst_type,
'access_ip_v4': '1.2.3.4',
'access_ip_v6': 'fead::1234',
'image_ref': inst.get('image_ref', def_image_ref),
'user_id': 'fake',
'project_id': 'fake',
'reservation_id': inst['reservation_id'],
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"progress": 0,
"fixed_ips": [],
"task_state": "",
"vm_state": "",
"security_groups": inst['security_groups'],
})
self.instance_cache_by_id[instance['id']] = instance
self.instance_cache_by_uuid[instance['uuid']] = instance
return instance
示例5: _fake_compute_api_create
def _fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
self._block_device_mapping_seen = kwargs.get("block_device_mapping")
self._legacy_bdm_seen = kwargs.get("legacy_bdm")
inst_type = flavors.get_flavor_by_flavor_id(2)
resv_id = None
return (
[
{
"id": 1,
"display_name": "test_server",
"uuid": FAKE_UUID,
"instance_type": inst_type,
"access_ip_v4": "1.2.3.4",
"access_ip_v6": "fead::1234",
"image_ref": IMAGE_UUID,
"user_id": "fake",
"project_id": "fake",
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"progress": 0,
"fixed_ips": [],
}
],
resv_id,
)
示例6: instance_create
def instance_create(context, inst):
inst_type = flavors.get_flavor_by_flavor_id(3)
image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
def_image_ref = 'http://localhost/images/%s' % image_uuid
self.instance_cache_num += 1
instance = fake_instance.fake_db_instance(**{
'id': self.instance_cache_num,
'display_name': inst['display_name'] or 'test',
'uuid': FAKE_UUID,
'instance_type': inst_type,
'access_ip_v4': '1.2.3.4',
'access_ip_v6': 'fead::1234',
'image_ref': inst.get('image_ref', def_image_ref),
'user_id': 'fake',
'project_id': 'fake',
'availability_zone': 'nova',
'reservation_id': inst['reservation_id'],
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"progress": 0,
"fixed_ips": [],
"task_state": "",
"vm_state": "",
"root_device_name": inst.get('root_device_name', 'vda'),
})
return instance
示例7: resize_vm
def resize_vm(uid, flavor_id, context):
"""
Resizes a VM up or down
Update: libvirt now supports resize see:
http://wiki.openstack.org/HypervisorSupportMatrix
uid -- id of the instance
flavor_id -- image reference.
context -- the os context
"""
instance = get_vm(uid, context)
kwargs = {}
try:
flavor = flavors.get_flavor_by_flavor_id(flavor_id)
COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
**kwargs)
ready = False
i = 0
# XXX are 15 secs enough to resize?
while not ready and i < 15:
i += 1
state = get_vm(uid, context)['vm_state']
if state == 'resized':
ready = True
import time
time.sleep(1)
instance = get_vm(uid, context)
COMPUTE_API.confirm_resize(context, instance)
except Exception as e:
raise AttributeError(str(e))
示例8: test_will_get_instance_by_flavor_id
def test_will_get_instance_by_flavor_id(self):
default_instance_type = objects.Flavor.get_by_name(
context.get_admin_context(), 'm1.small')
flavorid = default_instance_type.flavorid
fetched = flavors.get_flavor_by_flavor_id(flavorid)
self.assertIsInstance(fetched, objects.Flavor)
self.assertEqual(default_instance_type.flavorid, fetched.flavorid)
示例9: show
def show(self, req, id):
"""Return data about the given flavor id."""
try:
flavor = flavors.get_flavor_by_flavor_id(id)
req.cache_db_flavor(flavor)
except exception.NotFound:
raise webob.exc.HTTPNotFound()
return self._view_builder.show(req, flavor)
示例10: show
def show(self, req, id):
"""Return data about the given flavor id."""
try:
flavor = flavors.get_flavor_by_flavor_id(id)
req.cache_db_flavor(flavor)
except exception.FlavorNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
return self._view_builder.show(req, flavor)
示例11: _delete
def _delete(self, req, id):
context = req.environ["nova.context"]
authorize(context)
try:
flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted="no")
except exception.FlavorNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
flavors.destroy(flavor["name"])
示例12: show
def show(self, req, id):
"""Return data about the given flavor id."""
try:
context = req.environ['nova.context']
flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted='no')
req.cache_db_flavor(flavor)
except exception.NotFound:
raise webob.exc.HTTPNotFound()
return self._view_builder.show(req, flavor)
示例13: test_read_deleted_false_converting_flavorid
def test_read_deleted_false_converting_flavorid(self):
"""Ensure deleted flavors are not returned when not needed (for
example when creating a server and attempting to translate from
flavorid to instance_type_id.
"""
flavors.create("instance_type1", 256, 1, 120, 100, "test1")
flavors.destroy("instance_type1")
flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1")
instance_type = flavors.get_flavor_by_flavor_id("test1", read_deleted="no")
self.assertEqual("instance_type1_redo", instance_type.name)
示例14: test_resize_invalid_flavor_fails
def test_resize_invalid_flavor_fails(self):
self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
# Should never reach these.
self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
self.mox.StubOutWithMock(self.compute_api, 'update')
self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
self.mox.StubOutWithMock(self.compute_api.compute_task_api,
'migrate_server')
fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
exc = exception.FlavorNotFound(flavor_id='flavor-id')
flavors.get_flavor_by_flavor_id('flavor-id',
read_deleted='no').AndRaise(exc)
self.mox.ReplayAll()
self.assertRaises(exception.FlavorNotFound,
self.compute_api.resize, self.context,
fake_inst, flavor_id='flavor-id')
示例15: _delete
def _delete(self, req, id):
context = req.environ['nova.context']
authorize(context)
try:
flavor = flavors.get_flavor_by_flavor_id(
id, ctxt=context, read_deleted="no")
except exception.FlavorNotFound as e:
raise webob.exc.HTTPNotFound(explanation=e.format_message())
flavors.destroy(flavor['name'])
return webob.Response(status_int=202)