本文整理汇总了Python中nova.db.instance_create函数的典型用法代码示例。如果您正苦于以下问题:Python instance_create函数的具体用法?Python instance_create怎么用?Python instance_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了instance_create函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create
def test_create(self):
self.mox.StubOutWithMock(db, 'instance_create')
db.instance_create(self.context, {}).AndReturn(self.fake_instance)
self.mox.ReplayAll()
inst = instance.Instance()
inst.create(self.context)
self.assertEqual(self.fake_instance['id'], inst.id)
开发者ID:slagle,项目名称:nova,代码行数:7,代码来源:test_instance.py
示例2: test_instance_fault_get_by_instance
def test_instance_fault_get_by_instance(self):
""" ensure we can retrieve an instance fault by instance UUID """
ctxt = context.get_admin_context()
instance1 = db.instance_create(ctxt, {})
instance2 = db.instance_create(ctxt, {})
uuids = [instance1["uuid"], instance2["uuid"]]
# Create faults
fault_values = {"message": "message", "details": "detail", "instance_uuid": uuids[0], "code": 404}
fault1 = db.instance_fault_create(ctxt, fault_values)
fault_values = {"message": "message", "details": "detail", "instance_uuid": uuids[0], "code": 500}
fault2 = db.instance_fault_create(ctxt, fault_values)
fault_values = {"message": "message", "details": "detail", "instance_uuid": uuids[1], "code": 404}
fault3 = db.instance_fault_create(ctxt, fault_values)
fault_values = {"message": "message", "details": "detail", "instance_uuid": uuids[1], "code": 500}
fault4 = db.instance_fault_create(ctxt, fault_values)
instance_faults = db.instance_fault_get_by_instance_uuids(ctxt, uuids)
expected = {uuids[0]: [fault2, fault1], uuids[1]: [fault4, fault3]}
self.assertEqual(instance_faults, expected)
开发者ID:hiteshwadekar,项目名称:nova,代码行数:25,代码来源:test_db_api.py
示例3: test_describe_instances
def test_describe_instances(self):
"""Makes sure describe_instances works and filters results."""
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
'host': 'host1'})
inst2 = db.instance_create(self.context, {'reservation_id': 'a',
'host': 'host2'})
comp1 = db.service_create(self.context, {'host': 'host1',
'availability_zone': 'zone1',
'topic': "compute"})
comp2 = db.service_create(self.context, {'host': 'host2',
'availability_zone': 'zone2',
'topic': "compute"})
result = self.cloud.describe_instances(self.context)
result = result['reservationSet'][0]
self.assertEqual(len(result['instancesSet']), 2)
instance_id = cloud.id_to_ec2_id(inst2['id'])
result = self.cloud.describe_instances(self.context,
instance_id=[instance_id])
result = result['reservationSet'][0]
self.assertEqual(len(result['instancesSet']), 1)
self.assertEqual(result['instancesSet'][0]['instanceId'],
instance_id)
self.assertEqual(result['instancesSet'][0]
['placement']['availabilityZone'], 'zone2')
db.instance_destroy(self.context, inst1['id'])
db.instance_destroy(self.context, inst2['id'])
db.service_destroy(self.context, comp1['id'])
db.service_destroy(self.context, comp2['id'])
开发者ID:yosh,项目名称:nova,代码行数:28,代码来源:test_cloud.py
示例4: test_instance_get_all_by_filters_unicode_value
def test_instance_get_all_by_filters_unicode_value(self):
args = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1',
'display_name': u'test♥'}
db.instance_create(self.context, args)
result = db.instance_get_all_by_filters(self.context.elevated(),
{'display_name': u'test'})
self.assertEqual(1, len(result))
开发者ID:hengxu,项目名称:nova,代码行数:7,代码来源:test_db_api.py
示例5: test_create_stubbed
def test_create_stubbed(self):
self.mox.StubOutWithMock(db, "instance_create")
vals = {"host": "foo-host", "memory_mb": 128, "system_metadata": {"foo": "bar"}}
fake_inst = fake_instance.fake_db_instance(**vals)
db.instance_create(self.context, vals).AndReturn(fake_inst)
self.mox.ReplayAll()
inst = instance.Instance(host="foo-host", memory_mb=128, system_metadata={"foo": "bar"})
inst.create(self.context)
开发者ID:ZelinIO,项目名称:nova,代码行数:8,代码来源:test_instance.py
示例6: _setUpBlockDeviceMapping
def _setUpBlockDeviceMapping(self):
image_uuid = 'cedef40a-ed67-4d10-800e-17455edce175'
sys_meta = flavors.save_flavor_info(
{}, flavors.get_flavor(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)
开发者ID:DavidYan,项目名称:nova,代码行数:57,代码来源:test_cinder_cloud.py
示例7: test_instance_faults_get_by_instance_uuids_no_faults
def test_instance_faults_get_by_instance_uuids_no_faults(self):
"""None should be returned when no faults exist"""
ctxt = context.get_admin_context()
instance1 = db.instance_create(ctxt, {})
instance2 = db.instance_create(ctxt, {})
uuids = [instance1['uuid'], instance2['uuid']]
instance_faults = db.instance_fault_get_by_instance_uuids(ctxt, uuids)
expected = {uuids[0]: [], uuids[1]: []}
self.assertEqual(expected, instance_faults)
开发者ID:matiu2,项目名称:nova,代码行数:9,代码来源:test_db_api.py
示例8: test_instance_get_all_by_filters_deleted
def test_instance_get_all_by_filters_deleted(self):
args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
inst1 = db.instance_create(self.context, args1)
args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
inst2 = db.instance_create(self.context, args2)
db.instance_destroy(self.context, inst1.id)
result = db.instance_get_all_by_filters(self.context.elevated(), {})
self.assertEqual(1, len(result))
self.assertEqual(result[0].id, inst2.id)
开发者ID:YouthSun,项目名称:nova,代码行数:9,代码来源:test_db_api.py
示例9: test_create_stubbed
def test_create_stubbed(self):
self.mox.StubOutWithMock(db, 'instance_create')
vals = {'host': 'foo-host',
'memory_mb': 128,
'system_metadata': {'foo': 'bar'}}
fake_inst = fake_instance.fake_db_instance(**vals)
db.instance_create(self.context, vals).AndReturn(fake_inst)
self.mox.ReplayAll()
inst = instance.Instance(host='foo-host', memory_mb=128,
system_metadata={'foo': 'bar'})
inst.create(self.context)
开发者ID:chengxiayan,项目名称:nova,代码行数:11,代码来源:test_instance.py
示例10: test_instance_get_all_by_filters_deleted
def test_instance_get_all_by_filters_deleted(self):
args1 = {"reservation_id": "a", "image_ref": 1, "host": "host1"}
inst1 = db.instance_create(self.context, args1)
args2 = {"reservation_id": "b", "image_ref": 1, "host": "host1"}
inst2 = db.instance_create(self.context, args2)
db.instance_destroy(self.context, inst1.id)
result = db.instance_get_all_by_filters(self.context.elevated(), {})
self.assertEqual(2, len(result))
self.assertEqual(result[0].id, inst2.id)
self.assertEqual(result[1].id, inst1.id)
self.assertTrue(result[1].deleted)
开发者ID:nii-cloud,项目名称:dodai-compute,代码行数:11,代码来源:test_db_api.py
示例11: test_instance_get_all_by_filters_deleted
def test_instance_get_all_by_filters_deleted(self):
args1 = {'reservation_id': 'a', 'image_ref': 1, 'host': 'host1'}
inst1 = db.instance_create(self.context, args1)
args2 = {'reservation_id': 'b', 'image_ref': 1, 'host': 'host1'}
inst2 = db.instance_create(self.context, args2)
db.instance_destroy(self.context.elevated(), inst1['uuid'])
result = db.instance_get_all_by_filters(self.context.elevated(), {})
self.assertEqual(2, len(result))
self.assertIn(inst1.id, [result[0].id, result[1].id])
self.assertIn(inst2.id, [result[0].id, result[1].id])
if inst1.id == result[0].id:
self.assertTrue(result[0].deleted)
else:
self.assertTrue(result[1].deleted)
开发者ID:matiu2,项目名称:nova,代码行数:14,代码来源:test_db_api.py
示例12: _setUpBlockDeviceMapping
def _setUpBlockDeviceMapping(self):
image_uuid = "cedef40a-ed67-4d10-800e-17455edce175"
inst1 = db.instance_create(
self.context, {"image_ref": image_uuid, "instance_type_id": 1, "root_device_name": "/dev/sdb1"}
)
inst2 = db.instance_create(
self.context, {"image_ref": image_uuid, "instance_type_id": 1, "root_device_name": "/dev/sdc1"}
)
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)
开发者ID:99cloud,项目名称:nova,代码行数:48,代码来源:test_cinder_cloud.py
示例13: test_instance_fault_get_by_instance
def test_instance_fault_get_by_instance(self):
""" ensure we can retrieve an instance fault by instance UUID """
ctxt = context.get_admin_context()
instance1 = db.instance_create(ctxt, {})
instance2 = db.instance_create(ctxt, {})
uuids = [instance1['uuid'], instance2['uuid']]
# Create faults
fault_values = {
'message': 'message',
'details': 'detail',
'instance_uuid': uuids[0],
'code': 404,
}
fault1 = db.instance_fault_create(ctxt, fault_values)
fault_values = {
'message': 'message',
'details': 'detail',
'instance_uuid': uuids[0],
'code': 500,
}
fault2 = db.instance_fault_create(ctxt, fault_values)
fault_values = {
'message': 'message',
'details': 'detail',
'instance_uuid': uuids[1],
'code': 404,
}
fault3 = db.instance_fault_create(ctxt, fault_values)
fault_values = {
'message': 'message',
'details': 'detail',
'instance_uuid': uuids[1],
'code': 500,
}
fault4 = db.instance_fault_create(ctxt, fault_values)
instance_faults = db.instance_fault_get_by_instance_uuids(ctxt, uuids)
expected = {
uuids[0]: [fault2, fault1],
uuids[1]: [fault4, fault3],
}
self.assertEqual(instance_faults, expected)
开发者ID:matiu2,项目名称:nova,代码行数:48,代码来源:test_db_api.py
示例14: test_finish_revert_migration
def test_finish_revert_migration(self):
self._instance_data = self._get_instance_data()
instance = db.instance_create(self._context, self._instance_data)
network_info = fake_network.fake_get_instance_nw_info(
self.stubs, spectacular=True)
fake_revert_path = ('C:\\FakeInstancesPath\\%s\\_revert' %
instance['name'])
m = basevolumeutils.BaseVolumeUtils.volume_in_mapping(mox.IsA(str),
None)
m.AndReturn(False)
m = pathutils.PathUtils.get_instance_migr_revert_dir(instance['name'])
m.AndReturn(fake_revert_path)
fake.PathUtils.rename(fake_revert_path, mox.IsA(str))
self._set_vm_name(instance['name'])
self._setup_create_instance_mocks(None, False)
vmutils.VMUtils.set_vm_state(mox.Func(self._check_instance_name),
constants.HYPERV_VM_STATE_ENABLED)
self._mox.ReplayAll()
self._conn.finish_revert_migration(instance, network_info, None)
self._mox.VerifyAll()
开发者ID:fifieldt,项目名称:nova,代码行数:26,代码来源:test_hypervapi.py
示例15: _timeout_test
def _timeout_test(self, ctxt, timeout, multi_host):
values = {'host': 'foo'}
instance = db.instance_create(ctxt, values)
values = {'multi_host': multi_host, 'host': 'bar'}
net = db.network_create_safe(ctxt, values)
old = time = timeout - datetime.timedelta(seconds=5)
new = time = timeout + datetime.timedelta(seconds=5)
# should deallocate
values = {'allocated': False,
'instance_id': instance['id'],
'network_id': net['id'],
'updated_at': old}
db.fixed_ip_create(ctxt, values)
# still allocated
values = {'allocated': True,
'instance_id': instance['id'],
'network_id': net['id'],
'updated_at': old}
db.fixed_ip_create(ctxt, values)
# wrong network
values = {'allocated': False,
'instance_id': instance['id'],
'network_id': None,
'updated_at': old}
db.fixed_ip_create(ctxt, values)
# too new
values = {'allocated': False,
'instance_id': instance['id'],
'network_id': None,
'updated_at': new}
db.fixed_ip_create(ctxt, values)
开发者ID:matiu2,项目名称:nova,代码行数:31,代码来源:test_db_api.py
示例16: test_network_get_associated_fixed_ips
def test_network_get_associated_fixed_ips(self):
ctxt = context.get_admin_context()
values = {'host': 'foo', 'hostname': 'myname'}
instance = db.instance_create(ctxt, values)
values = {'address': 'bar', 'instance_id': instance['id']}
vif = db.virtual_interface_create(ctxt, values)
values = {'address': 'baz',
'network_id': 1,
'allocated': True,
'instance_id': instance['id'],
'virtual_interface_id': vif['id']}
fixed_address = db.fixed_ip_create(ctxt, values)
data = db.network_get_associated_fixed_ips(ctxt, 1)
self.assertEqual(len(data), 1)
record = data[0]
self.assertEqual(record['address'], fixed_address)
self.assertEqual(record['instance_id'], instance['id'])
self.assertEqual(record['network_id'], 1)
self.assertEqual(record['instance_created'], instance['created_at'])
self.assertEqual(record['instance_updated'], instance['updated_at'])
self.assertEqual(record['instance_hostname'], instance['hostname'])
self.assertEqual(record['vif_id'], vif['id'])
self.assertEqual(record['vif_address'], vif['address'])
data = db.network_get_associated_fixed_ips(ctxt, 1, 'nothing')
self.assertEqual(len(data), 0)
开发者ID:matiu2,项目名称:nova,代码行数:25,代码来源:test_db_api.py
示例17: create
def create(self, context):
if self.obj_attr_is_set("id"):
raise exception.ObjectActionError(action="create", reason="already created")
updates = self.obj_get_changes()
expected_attrs = [attr for attr in INSTANCE_DEFAULT_FIELDS if attr in updates]
if "security_groups" in updates:
updates["security_groups"] = [x.name for x in updates["security_groups"]]
if "info_cache" in updates:
updates["info_cache"] = {"network_info": updates["info_cache"].network_info.json()}
updates["extra"] = {}
numa_topology = updates.pop("numa_topology", None)
if numa_topology:
expected_attrs.append("numa_topology")
updates["extra"]["numa_topology"] = numa_topology._to_json()
pci_requests = updates.pop("pci_requests", None)
if pci_requests:
expected_attrs.append("pci_requests")
updates["extra"]["pci_requests"] = pci_requests.to_json()
flavor = updates.pop("flavor", None)
if flavor:
expected_attrs.append("flavor")
old = (
(self.obj_attr_is_set("old_flavor") and self.old_flavor) and self.old_flavor.obj_to_primitive() or None
)
new = (
(self.obj_attr_is_set("new_flavor") and self.new_flavor) and self.new_flavor.obj_to_primitive() or None
)
flavor_info = {"cur": self.flavor.obj_to_primitive(), "old": old, "new": new}
updates["extra"]["flavor"] = jsonutils.dumps(flavor_info)
db_inst = db.instance_create(context, updates)
self._from_db_object(context, self, db_inst, expected_attrs)
开发者ID:jcalonsoh,项目名称:openstack-nova,代码行数:31,代码来源:instance.py
示例18: _do_build
def _do_build(id, proj, user, *args):
values = {
'id': id,
'project_id': proj,
'user_id': user,
'image_ref': 1,
'kernel_id': 2,
'ramdisk_id': 3,
'instance_type_id': '3', # m1.large
'os_type': 'linux',
'architecture': 'x86-64'}
network_info = [({'bridge': 'fa0', 'id': 0, 'injected': False},
{'broadcast': '192.168.0.255',
'dns': ['192.168.0.1'],
'gateway': '192.168.0.1',
'gateway6': 'dead:beef::1',
'ip6s': [{'enabled': '1',
'ip': 'dead:beef::dcad:beff:feef:0',
'netmask': '64'}],
'ips': [{'enabled': '1',
'ip': '192.168.0.100',
'netmask': '255.255.255.0'}],
'label': 'fake',
'mac': 'DE:AD:BE:EF:00:00',
'rxtx_cap': 3})]
instance = db.instance_create(self.context, values)
self.conn.spawn(instance, network_info)
开发者ID:cp16net,项目名称:reddwarf,代码行数:27,代码来源:test_xenapi.py
示例19: _test_create_image
def _test_create_image(self, cache_type):
sys_meta = {'image_cache_in_nova': True}
instance = db.instance_create(self.context,
{'system_metadata': sys_meta})
instance = db.instance_get_by_uuid(self.context, instance['uuid'])
self.flags(cache_images=cache_type)
was = {'called': None}
def fake_create_cached_image(*args):
was['called'] = 'some'
return {}
self.stubs.Set(vm_utils, '_create_cached_image',
fake_create_cached_image)
def fake_fetch_image(*args):
was['called'] = 'none'
return {}
self.stubs.Set(vm_utils, '_fetch_image',
fake_fetch_image)
vm_utils._create_image(self.context, None, instance,
'foo', 'bar', 'baz')
self.assertEqual(was['called'], cache_type)
开发者ID:DavidYan,项目名称:nova,代码行数:25,代码来源:test_vm_utils.py
示例20: test_get_disk_mapping_blockdev_eph
def test_get_disk_mapping_blockdev_eph(self):
# A disk mapping with a blockdev replacing the ephemeral device
user_context = context.RequestContext(self.user_id, self.project_id)
instance_ref = db.instance_create(user_context, self.test_instance)
block_device_info = {
'block_device_mapping': [
{'connection_info': "fake",
'mount_device': "/dev/vdb",
'boot_index': -1,
'delete_on_termination': True},
]
}
mapping = blockinfo.get_disk_mapping("kvm", instance_ref,
"virtio", "ide",
block_device_info)
expect = {
'disk': {'bus': 'virtio', 'dev': 'vda',
'type': 'disk', 'boot_index': '1'},
'/dev/vdb': {'bus': 'virtio', 'dev': 'vdb', 'type': 'disk'},
'root': {'bus': 'virtio', 'dev': 'vda',
'type': 'disk', 'boot_index': '1'},
}
self.assertEqual(mapping, expect)
开发者ID:Cisco-OCPChina,项目名称:nova,代码行数:25,代码来源:test_libvirt_blockinfo.py
注:本文中的nova.db.instance_create函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论