当前位置: 首页>>代码示例>>Python>>正文


Python db.instance_create函数代码示例

本文整理汇总了Python中nova.db.instance_create函数的典型用法代码示例。如果您正苦于以下问题:Python instance_create函数的具体用法?Python instance_create怎么用?Python instance_create使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了instance_create函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的nova.db.instance_create函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。