本文整理汇总了Python中nova.db.block_device_mapping_get_all_by_instance函数的典型用法代码示例。如果您正苦于以下问题:Python block_device_mapping_get_all_by_instance函数的具体用法?Python block_device_mapping_get_all_by_instance怎么用?Python block_device_mapping_get_all_by_instance使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了block_device_mapping_get_all_by_instance函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_delete_fast_if_host_not_set
def test_delete_fast_if_host_not_set(self):
inst = self._create_instance_obj()
inst.host = ''
updates = {'progress': 0, 'task_state': task_states.DELETING}
self.mox.StubOutWithMock(inst, 'save')
self.mox.StubOutWithMock(db,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(db, 'constraint')
self.mox.StubOutWithMock(db, 'instance_destroy')
self.mox.StubOutWithMock(self.compute_api, '_create_reservations')
db.block_device_mapping_get_all_by_instance(self.context,
inst.uuid).AndReturn([])
inst.save()
self.compute_api._create_reservations(self.context,
inst, inst.instance_type_id,
inst.project_id, inst.user_id
).AndReturn(None)
db.constraint(host=mox.IgnoreArg()).AndReturn('constraint')
db.instance_destroy(self.context, inst.uuid, 'constraint')
self.mox.ReplayAll()
self.compute_api.delete(self.context, inst)
for k, v in updates.items():
self.assertEqual(inst[k], v)
开发者ID:raidwang,项目名称:nova,代码行数:28,代码来源:test_compute_api.py
示例2: test_delete_fast_if_host_not_set
def test_delete_fast_if_host_not_set(self):
inst = self._create_instance_obj()
inst.host = ''
db_inst = obj_base.obj_to_primitive(inst)
updates = {'progress': 0, 'task_state': task_states.DELETING}
new_inst = dict(db_inst, **updates)
self.mox.StubOutWithMock(db,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(db,
'instance_update_and_get_original')
self.mox.StubOutWithMock(db, 'constraint')
self.mox.StubOutWithMock(db, 'instance_destroy')
self.mox.StubOutWithMock(self.compute_api, '_create_reservations')
db.block_device_mapping_get_all_by_instance(self.context,
inst.uuid).AndReturn([])
db.instance_update_and_get_original(
self.context, inst.uuid, updates).AndReturn((db_inst, new_inst))
self.compute_api._create_reservations(self.context,
db_inst, new_inst,
inst.project_id,
inst.user_id).AndReturn(None)
db.constraint(host=mox.IgnoreArg()).AndReturn('constraint')
db.instance_destroy(self.context, inst.uuid, 'constraint')
if self.is_cells:
self.mox.StubOutWithMock(self.compute_api, '_cast_to_cells')
self.compute_api._cast_to_cells(
self.context, db_inst, 'delete')
self.mox.ReplayAll()
self.compute_api.delete(self.context, db_inst)
开发者ID:xqueralt,项目名称:nova,代码行数:34,代码来源:test_compute_api.py
示例3: test_block_device_mapping_get_all_by_instance
def test_block_device_mapping_get_all_by_instance(self):
fake_inst = {"uuid": "fake-uuid"}
self.mox.StubOutWithMock(db, "block_device_mapping_get_all_by_instance")
db.block_device_mapping_get_all_by_instance(self.context, fake_inst["uuid"]).AndReturn("fake-result")
self.mox.ReplayAll()
result = self.conductor.block_device_mapping_get_all_by_instance(self.context, fake_inst)
self.assertEqual(result, "fake-result")
开发者ID:jdurgin,项目名称:nova,代码行数:7,代码来源:test_conductor.py
示例4: test_block_device_mapping_get_all_by_instance
def test_block_device_mapping_get_all_by_instance(self):
fake_inst = {'uuid': 'fake-uuid'}
self.mox.StubOutWithMock(db,
'block_device_mapping_get_all_by_instance')
db.block_device_mapping_get_all_by_instance(
self.context, fake_inst['uuid']).AndReturn('fake-result')
self.mox.ReplayAll()
result = self.conductor.block_device_mapping_get_all_by_instance(
self.context, fake_inst)
self.assertEqual(result, 'fake-result')
开发者ID:gminator,项目名称:nova,代码行数:10,代码来源:test_conductor.py
示例5: _assertSimilarBlockDeviceMapping
def _assertSimilarBlockDeviceMapping(original, copy):
original_bdms = db.block_device_mapping_get_all_by_instance(self.context, original["uuid"])
copy_bdms = db.block_device_mapping_get_all_by_instance(self.context, copy["uuid"])
original_bdms = [dict(i.iteritems()) for i in original_bdms]
copy_bdms = [dict(i.iteritems()) for i in copy_bdms]
# Remove fields that we do not care about for comparison
for bdm in original_bdms + copy_bdms:
del bdm["instance_uuid"]
del bdm["created_at"]
del bdm["deleted_at"]
del bdm["id"]
self.assertEquals(original_bdms, copy_bdms)
开发者ID:peterfeiner,项目名称:cobalt,代码行数:14,代码来源:test_api.py
示例6: get_device_name_for_instance
def get_device_name_for_instance(context, instance, device):
# NOTE(vish): this will generate a unique device name that is not
# in use already. It is a reasonable guess at where
# it will show up in a linux guest, but it may not
# always be correct
req_prefix = None
req_letters = None
if device:
try:
match = re.match("(^/dev/x{0,1}[a-z]d)([a-z]+)$", device)
req_prefix, req_letters = match.groups()
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:
match = re.match("(^/dev/x{0,1}[a-z]d)[a-z]+[0-9]*$", mappings["root"])
prefix = match.groups()[0]
except (TypeError, AttributeError, ValueError):
raise exception.InvalidDevicePath(path=mappings["root"])
if not req_prefix:
req_prefix = prefix
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)
if not req_letters:
req_letters = _get_unused_letters(used_letters)
if req_letters in used_letters:
raise exception.DevicePathInUse(path=device)
return req_prefix + req_letters
开发者ID:99cloud,项目名称:nova,代码行数:35,代码来源:utils.py
示例7: _validate_device
def _validate_device(self, device=None):
bdms = db.block_device_mapping_get_all_by_instance(
self.context, self.instance['uuid'])
return compute_utils.get_device_name_for_instance(self.context,
self.instance,
bdms,
device)
开发者ID:beride,项目名称:nova,代码行数:7,代码来源:test_compute_utils.py
示例8: block_device_mapping_get_all_by_instance
def block_device_mapping_get_all_by_instance(self, context, instance,
legacy=True):
bdms = db.block_device_mapping_get_all_by_instance(context,
instance['uuid'])
if legacy:
bdms = block_device.legacy_mapping(bdms)
return bdms
开发者ID:Yuriy-Leonov,项目名称:nova,代码行数:7,代码来源:fake.py
示例9: _prepare_instance
def _prepare_instance(self, context, instance):
instance["name"] = instance["display_name"]
instance["status"] = self._status_map.get(
instance["vm_state"], instance["vm_state"])
image_id = instance["image_ref"]
if image_id is None or len(image_id) == 0:
image_id = instance["system_metadata"]["image_base_image_ref"]
if image_id is None or len(image_id) == 0:
image_id = instance["system_metadata"]["image_image_id"]
image = image_api.API().get_item_by_id(context, image_id)
if image is not None:
instance["image"] = image['name']
instance["cached_nwinfo"] = \
compute_utils.get_nw_info_for_instance(instance)
attached_disks = db.block_device_mapping_get_all_by_instance(
nova_context.get_admin_context(), instance['uuid'])
for disk in attached_disks:
if disk["volume_id"] is not None:
disk["volume"] = disk_api.API().get_item_by_id(
context, disk["volume_id"])
instance["attached_disks"] = attached_disks
return instance
开发者ID:pombredanne,项目名称:gce,代码行数:26,代码来源:instance_api.py
示例10: _tearDownBlockDeviceMapping
def _tearDownBlockDeviceMapping(self, inst1, inst2, volumes):
for vol in volumes:
self.volume_api.delete(self.context, vol)
for uuid in (inst1["uuid"], inst2["uuid"]):
for bdm in db.block_device_mapping_get_all_by_instance(self.context, uuid):
db.block_device_mapping_destroy(self.context, bdm["id"])
db.instance_destroy(self.context, inst2["uuid"])
db.instance_destroy(self.context, inst1["uuid"])
开发者ID:99cloud,项目名称:nova,代码行数:8,代码来源:test_cinder_cloud.py
示例11: test_delete_soft_rollback
def test_delete_soft_rollback(self):
inst = self._create_instance_obj()
self.mox.StubOutWithMock(db,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(inst, 'save')
delete_time = datetime.datetime(1955, 11, 5)
timeutils.set_time_override(delete_time)
db.block_device_mapping_get_all_by_instance(
self.context, inst.uuid).AndReturn([])
inst.save().AndRaise(Exception)
self.mox.ReplayAll()
self.assertRaises(Exception,
self.compute_api.soft_delete, self.context, inst)
开发者ID:raidwang,项目名称:nova,代码行数:17,代码来源:test_compute_api.py
示例12: _tearDownBlockDeviceMapping
def _tearDownBlockDeviceMapping(self, instances, volumes):
for vols in volumes:
for vol in vols:
self.volume_api.delete(self.context, vol['id'])
for instance in instances:
for bdm in db.block_device_mapping_get_all_by_instance(
self.context, instance['uuid']):
db.block_device_mapping_destroy(self.context, bdm['id'])
db.instance_destroy(self.context, instance['uuid'])
开发者ID:kitch,项目名称:nova,代码行数:9,代码来源:test_cinder_cloud.py
示例13: test_create_instances_here
def test_create_instances_here(self):
# Just grab the first instance type
inst_type = objects.Flavor.get_by_id(self.ctxt, 1)
image = {'properties': {}}
instance_uuids = self.instance_uuids
instance_props = {'id': 'removed',
'security_groups': 'removed',
'info_cache': 'removed',
'name': 'instance-00000001',
'hostname': 'meow',
'display_name': 'moo',
'image_ref': uuidsentinel.fake_image_ref,
'user_id': self.ctxt.user_id,
# Test these as lists
'metadata': {'moo': 'cow'},
'system_metadata': {'meow': 'cat'},
'flavor': inst_type,
'project_id': self.ctxt.project_id}
call_info = {'uuids': []}
block_device_mapping = objects.BlockDeviceMappingList(
objects=[
objects.BlockDeviceMapping(context=self.ctxt,
**fake_block_device.FakeDbBlockDeviceDict(
block_device.create_image_bdm(
uuidsentinel.fake_image_ref),
anon=True))
])
def _fake_instance_update_at_top(self, _ctxt, instance):
call_info['uuids'].append(instance['uuid'])
self.stub_out('nova.cells.messaging.MessageRunner.'
'instance_update_at_top',
_fake_instance_update_at_top)
self.scheduler._create_instances_here(self.ctxt, instance_uuids,
instance_props, inst_type, image,
['default'], block_device_mapping)
self.assertEqual(instance_uuids, call_info['uuids'])
for count, instance_uuid in enumerate(instance_uuids):
bdms = db.block_device_mapping_get_all_by_instance(self.ctxt,
instance_uuid)
self.assertIsNotNone(bdms)
instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
meta = utils.instance_meta(instance)
self.assertEqual('cow', meta['moo'])
sys_meta = utils.instance_sys_meta(instance)
self.assertEqual('cat', sys_meta['meow'])
self.assertEqual('meow', instance['hostname'])
self.assertEqual('moo-%d' % (count + 1),
instance['display_name'])
self.assertEqual(uuidsentinel.fake_image_ref,
instance['image_ref'])
开发者ID:Juniper,项目名称:nova,代码行数:55,代码来源:test_cells_scheduler.py
示例14: 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
示例15: test_create_block_device_mapping
def test_create_block_device_mapping(self):
instance_type = {"swap": 1, "ephemeral_gb": 1}
instance = self._create_fake_instance_obj()
bdms = [
block_device.BlockDeviceDict(
{"source_type": "image", "destination_type": "local", "image_id": "fake-image", "boot_index": 0}
)
]
self.compute_api._create_block_device_mapping(instance_type, instance.uuid, bdms)
bdms = db.block_device_mapping_get_all_by_instance(self.context, instance["uuid"])
self.assertEqual(0, len(bdms))
开发者ID:tangguochang,项目名称:nova,代码行数:11,代码来源:test_compute_cells.py
示例16: test_create_instances_here
def test_create_instances_here(self):
# Just grab the first instance type
inst_type = objects.Flavor.get_by_id(self.ctxt, 1)
image = {"properties": {}}
instance_uuids = self.instance_uuids
instance_props = {
"id": "removed",
"security_groups": "removed",
"info_cache": "removed",
"name": "instance-00000001",
"hostname": "meow",
"display_name": "moo",
"image_ref": uuidsentinel.fake_image_ref,
"user_id": self.ctxt.user_id,
# Test these as lists
"metadata": {"moo": "cow"},
"system_metadata": {"meow": "cat"},
"flavor": inst_type,
"project_id": self.ctxt.project_id,
}
call_info = {"uuids": []}
block_device_mapping = objects.BlockDeviceMappingList(
objects=[
objects.BlockDeviceMapping(
context=self.ctxt,
**fake_block_device.FakeDbBlockDeviceDict(
block_device.create_image_bdm(uuidsentinel.fake_image_ref), anon=True
)
)
]
)
def _fake_instance_update_at_top(_ctxt, instance):
call_info["uuids"].append(instance["uuid"])
self.stubs.Set(self.msg_runner, "instance_update_at_top", _fake_instance_update_at_top)
self.scheduler._create_instances_here(
self.ctxt, instance_uuids, instance_props, inst_type, image, ["default"], block_device_mapping
)
self.assertEqual(instance_uuids, call_info["uuids"])
for count, instance_uuid in enumerate(instance_uuids):
bdms = db.block_device_mapping_get_all_by_instance(self.ctxt, instance_uuid)
self.assertIsNotNone(bdms)
instance = db.instance_get_by_uuid(self.ctxt, instance_uuid)
meta = utils.instance_meta(instance)
self.assertEqual("cow", meta["moo"])
sys_meta = utils.instance_sys_meta(instance)
self.assertEqual("cat", sys_meta["meow"])
self.assertEqual("meow", instance["hostname"])
self.assertEqual("moo-%d" % (count + 1), instance["display_name"])
self.assertEqual(uuidsentinel.fake_image_ref, instance["image_ref"])
开发者ID:cyx1231st,项目名称:nova,代码行数:54,代码来源:test_cells_scheduler.py
示例17: test_create_block_device_mapping
def test_create_block_device_mapping(self):
instance_type = {'swap': 1, 'ephemeral_gb': 1}
instance = self._create_fake_instance_obj()
bdms = [block_device.BlockDeviceDict({'source_type': 'image',
'destination_type': 'local',
'image_id': 'fake-image',
'boot_index': 0})]
self.compute_api._create_block_device_mapping(
instance_type, instance.uuid, bdms)
bdms = db.block_device_mapping_get_all_by_instance(
self.context, instance['uuid'])
self.assertEqual(0, len(bdms))
开发者ID:TonyChengTW,项目名称:OpenStack_Liberty_Control,代码行数:12,代码来源:test_compute_cells.py
示例18: test_delete_soft_rollback
def test_delete_soft_rollback(self):
inst = self._create_instance_obj()
db_inst = obj_base.obj_to_primitive(inst)
self.mox.StubOutWithMock(db,
'block_device_mapping_get_all_by_instance')
self.mox.StubOutWithMock(db,
'instance_update_and_get_original')
delete_time = datetime.datetime(1955, 11, 5)
timeutils.set_time_override(delete_time)
db.block_device_mapping_get_all_by_instance(
self.context, inst.uuid).AndReturn([])
db.instance_update_and_get_original(
self.context, inst.uuid,
{'progress': 0,
'deleted_at': delete_time,
'task_state': task_states.SOFT_DELETING,
}).AndRaise(test.TestingException)
self.mox.ReplayAll()
self.assertRaises(test.TestingException,
self.compute_api.soft_delete, self.context, db_inst)
开发者ID:xqueralt,项目名称:nova,代码行数:24,代码来源:test_compute_api.py
示例19: _format_instance_mapping
def _format_instance_mapping(self, ctxt, instance_ref):
root_device_name = instance_ref['root_device_name']
if root_device_name is None:
return _DEFAULT_MAPPINGS
mappings = {}
mappings['ami'] = block_device.strip_dev(root_device_name)
mappings['root'] = root_device_name
default_ephemeral_device = \
instance_ref.get('default_ephemeral_device')
if default_ephemeral_device:
mappings['ephemeral0'] = default_ephemeral_device
default_swap_device = instance_ref.get('default_swap_device')
if default_swap_device:
mappings['swap'] = default_swap_device
ebs_devices = []
# 'ephemeralN', 'swap' and ebs
for bdm in db.block_device_mapping_get_all_by_instance(
ctxt, instance_ref['id']):
if bdm['no_device']:
continue
# ebs volume case
if (bdm['volume_id'] or bdm['snapshot_id']):
ebs_devices.append(bdm['device_name'])
continue
virtual_name = bdm['virtual_name']
if not virtual_name:
continue
if block_device.is_swap_or_ephemeral(virtual_name):
mappings[virtual_name] = bdm['device_name']
# NOTE(yamahata): I'm not sure how ebs device should be numbered.
# Right now sort by device name for deterministic
# result.
if ebs_devices:
nebs = 0
ebs_devices.sort()
for ebs in ebs_devices:
mappings['ebs%d' % nebs] = ebs
nebs += 1
return mappings
开发者ID:KarimAllah,项目名称:nova,代码行数:46,代码来源:handler.py
示例20: _format_instance_mapping
def _format_instance_mapping(ctxt, instance):
root_device_name = instance["root_device_name"]
if root_device_name is None:
return _DEFAULT_MAPPINGS
mappings = {}
mappings["ami"] = block_device.strip_dev(root_device_name)
mappings["root"] = root_device_name
default_ephemeral_device = instance.get("default_ephemeral_device")
if default_ephemeral_device:
mappings["ephemeral0"] = default_ephemeral_device
default_swap_device = instance.get("default_swap_device")
if default_swap_device:
mappings["swap"] = default_swap_device
ebs_devices = []
# 'ephemeralN', 'swap' and ebs
for bdm in db.block_device_mapping_get_all_by_instance(ctxt, instance["uuid"]):
if bdm["no_device"]:
continue
# ebs volume case
if bdm["volume_id"] or bdm["snapshot_id"]:
ebs_devices.append(bdm["device_name"])
continue
virtual_name = bdm["virtual_name"]
if not virtual_name:
continue
if block_device.is_swap_or_ephemeral(virtual_name):
mappings[virtual_name] = bdm["device_name"]
# NOTE(yamahata): I'm not sure how ebs device should be numbered.
# Right now sort by device name for deterministic
# result.
if ebs_devices:
nebs = 0
ebs_devices.sort()
for ebs in ebs_devices:
mappings["ebs%d" % nebs] = ebs
nebs += 1
return mappings
开发者ID:nati,项目名称:nova,代码行数:44,代码来源:base.py
注:本文中的nova.db.block_device_mapping_get_all_by_instance函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论