本文整理汇总了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函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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")
示例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')
示例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)
示例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
示例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)
示例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
示例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
示例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"])
示例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)
示例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'])
示例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'])
示例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
示例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))