• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python flavors.get_flavor_by_name函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了get_flavor_by_name函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_reverse_quota_delta

    def test_reverse_quota_delta(self, mock_get_flavor):
        inst = create_instance(self.context, params=None)
        inst.old_flavor = flavors.get_flavor_by_name('m1.tiny')
        inst.new_flavor = flavors.get_flavor_by_name('m1.medium')

        expected_deltas = {
            'cores': -1 * (inst.new_flavor['vcpus'] -
                           inst.old_flavor['vcpus']),
            'ram': -1 * (inst.new_flavor['memory_mb'] -
                         inst.old_flavor['memory_mb'])
        }
        updates = {'old_instance_type_id': inst.old_flavor['id'],
                   'new_instance_type_id': inst.new_flavor['id']}

        fake_migration = test_migration.fake_db_migration(**updates)

        def _flavor_get_by_id(context, type_id):
            if type_id == updates['old_instance_type_id']:
                return inst.old_flavor
            else:
                return inst.new_flavor

        mock_get_flavor.side_effect = _flavor_get_by_id
        deltas = compute_utils.reverse_upsize_quota_delta(self.context,
                                                          fake_migration)
        self.assertEqual(expected_deltas, deltas)
开发者ID:billhu422,项目名称:nova,代码行数:26,代码来源:test_compute_utils.py


示例2: test_notify_usage_exists_instance_not_found

 def test_notify_usage_exists_instance_not_found(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = instance_obj.Instance.get_by_id(self.context, instance_id,
             expected_attrs=['metadata', 'system_metadata', 'info_cache'])
     self.compute.terminate_instance(self.context, instance, [], [])
     compute_utils.notify_usage_exists(
         rpc.get_notifier('compute'), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.exists')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'], {})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
开发者ID:ewindisch,项目名称:nova,代码行数:29,代码来源:test_compute_utils.py


示例3: test_notify_about_instance_usage

 def test_notify_about_instance_usage(self):
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     extra_usage_info = {"image_name": "fake_name"}
     db.instance_system_metadata_update(self.context, instance["uuid"], sys_metadata, False)
     # NOTE(russellb) Make sure our instance has the latest system_metadata
     # in it.
     instance = db.instance_get(self.context, instance_id)
     compute_utils.notify_about_instance_usage(
         notify.get_notifier("compute"), self.context, instance, "create.start", extra_usage_info=extra_usage_info
     )
     self.assertEquals(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg.priority, "INFO")
     self.assertEquals(msg.event_type, "compute.instance.create.start")
     payload = msg.payload
     self.assertEquals(payload["tenant_id"], self.project_id)
     self.assertEquals(payload["user_id"], self.user_id)
     self.assertEquals(payload["instance_id"], instance["uuid"])
     self.assertEquals(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEquals(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEquals(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in ("display_name", "created_at", "launched_at", "state", "state_description", "image_meta"):
         self.assertTrue(attr in payload, msg="Key %s not in payload" % attr)
     self.assertEquals(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     self.assertEquals(payload["image_name"], "fake_name")
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, jsonutils.to_primitive(instance))
开发者ID:kraman,项目名称:nova,代码行数:33,代码来源:test_compute_utils.py


示例4: test_notify_about_instance_usage

 def test_notify_about_instance_usage(self):
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     extra_usage_info = {'image_name': 'fake_name'}
     compute_utils.notify_about_instance_usage(
         rpc.get_notifier('compute'),
         self.context, instance, 'create.start',
         extra_usage_info=extra_usage_info)
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.create.start')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description', 'image_meta'):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     self.assertEqual(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context, instance, [], [])
开发者ID:billhu422,项目名称:nova,代码行数:35,代码来源:test_compute_utils.py


示例5: test_notify_usage_exists_deleted_instance

 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     self.compute.terminate_instance(self.context, instance, [], [])
     compute_utils.notify_usage_exists(
         rpc.get_notifier('compute'), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, 'INFO')
     self.assertEqual(msg.event_type, 'compute.instance.exists')
     payload = msg.payload
     self.assertEqual(payload['tenant_id'], self.project_id)
     self.assertEqual(payload['user_id'], self.user_id)
     self.assertEqual(payload['instance_id'], instance['uuid'])
     self.assertEqual(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEqual(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEqual(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     image_ref_url = "%s/images/%s" % (glance.generate_glance_url(),
                                       uuids.fake_image_ref)
     self.assertEqual(payload['image_ref_url'], image_ref_url)
开发者ID:binarycode,项目名称:nova,代码行数:34,代码来源:test_compute_utils.py


示例6: test_notify_usage_exists_instance_not_found

 def test_notify_usage_exists_instance_not_found(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance = create_instance(self.context)
     self.compute.terminate_instance(self.context, instance, [], [])
     compute_utils.notify_usage_exists(rpc.get_notifier("compute"), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, "INFO")
     self.assertEqual(msg.event_type, "compute.instance.exists")
     payload = msg.payload
     self.assertEqual(payload["tenant_id"], self.project_id)
     self.assertEqual(payload["user_id"], self.user_id)
     self.assertEqual(payload["instance_id"], instance["uuid"])
     self.assertEqual(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEqual(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEqual(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in (
         "display_name",
         "created_at",
         "launched_at",
         "state",
         "state_description",
         "bandwidth",
         "audit_period_beginning",
         "audit_period_ending",
         "image_meta",
     ):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload["image_meta"], {})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload["image_ref_url"], image_ref_url)
开发者ID:jorgevgut,项目名称:nova,代码行数:32,代码来源:test_compute_utils.py


示例7: test_notify_about_instance_usage

 def test_notify_about_instance_usage(self):
     instance = create_instance(self.context)
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     extra_usage_info = {"image_name": "fake_name"}
     compute_utils.notify_about_instance_usage(
         rpc.get_notifier("compute"), self.context, instance, "create.start", extra_usage_info=extra_usage_info
     )
     self.assertEqual(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEqual(msg.priority, "INFO")
     self.assertEqual(msg.event_type, "compute.instance.create.start")
     payload = msg.payload
     self.assertEqual(payload["tenant_id"], self.project_id)
     self.assertEqual(payload["user_id"], self.user_id)
     self.assertEqual(payload["instance_id"], instance["uuid"])
     self.assertEqual(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEqual(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEqual(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in ("display_name", "created_at", "launched_at", "state", "state_description", "image_meta"):
         self.assertIn(attr, payload, "Key %s not in payload" % attr)
     self.assertEqual(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     self.assertEqual(payload["image_name"], "fake_name")
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload["image_ref_url"], image_ref_url)
     self.compute.terminate_instance(self.context, instance, [], [])
开发者ID:jorgevgut,项目名称:nova,代码行数:30,代码来源:test_compute_utils.py


示例8: test_upsize_quota_delta

    def test_upsize_quota_delta(self):
        old_flavor = flavors.get_flavor_by_name("m1.tiny")
        new_flavor = flavors.get_flavor_by_name("m1.medium")

        expected_deltas = {
            "cores": new_flavor["vcpus"] - old_flavor["vcpus"],
            "ram": new_flavor["memory_mb"] - old_flavor["memory_mb"],
        }

        deltas = compute_utils.upsize_quota_delta(self.context, new_flavor, old_flavor)
        self.assertEqual(expected_deltas, deltas)
开发者ID:jorgevgut,项目名称:nova,代码行数:11,代码来源:test_compute_utils.py


示例9: test_downsize_quota_delta

    def test_downsize_quota_delta(self):
        inst = create_instance(self.context, params=None)
        inst.old_flavor = flavors.get_flavor_by_name("m1.medium")
        inst.new_flavor = flavors.get_flavor_by_name("m1.tiny")

        expected_deltas = {
            "cores": (inst.new_flavor["vcpus"] - inst.old_flavor["vcpus"]),
            "ram": (inst.new_flavor["memory_mb"] - inst.old_flavor["memory_mb"]),
        }

        deltas = compute_utils.downsize_quota_delta(self.context, inst)
        self.assertEqual(expected_deltas, deltas)
开发者ID:jorgevgut,项目名称:nova,代码行数:12,代码来源:test_compute_utils.py


示例10: test_upsize_quota_delta

    def test_upsize_quota_delta(self):
        old_flavor = flavors.get_flavor_by_name('m1.tiny')
        new_flavor = flavors.get_flavor_by_name('m1.medium')

        expected_deltas = {
            'cores': new_flavor['vcpus'] - old_flavor['vcpus'],
            'ram': new_flavor['memory_mb'] - old_flavor['memory_mb']
        }

        deltas = compute_utils.upsize_quota_delta(self.context, new_flavor,
                                                  old_flavor)
        self.assertEqual(expected_deltas, deltas)
开发者ID:binarycode,项目名称:nova,代码行数:12,代码来源:test_compute_utils.py


示例11: test_reserve_quota_delta

    def test_reserve_quota_delta(self, mock_ids_from_instance, mock_reserve):
        quotas = objects.Quotas(context=context)
        inst = create_instance(self.context, params=None)
        inst.old_flavor = flavors.get_flavor_by_name("m1.tiny")
        inst.new_flavor = flavors.get_flavor_by_name("m1.medium")

        mock_ids_from_instance.return_value = (inst.project_id, inst.user_id)
        mock_reserve.return_value = quotas

        deltas = compute_utils.upsize_quota_delta(self.context, inst.new_flavor, inst.old_flavor)
        compute_utils.reserve_quota_delta(self.context, deltas, inst)
        mock_reserve.assert_called_once_with(project_id=inst.project_id, user_id=inst.user_id, **deltas)
开发者ID:jorgevgut,项目名称:nova,代码行数:12,代码来源:test_compute_utils.py


示例12: test_reverse_quota_delta

    def test_reverse_quota_delta(self):
        inst = create_instance(self.context, params=None)
        inst.old_flavor = flavors.get_flavor_by_name('m1.tiny')
        inst.new_flavor = flavors.get_flavor_by_name('m1.medium')

        expected_deltas = {
            'cores': -1 * (inst.new_flavor['vcpus'] -
                           inst.old_flavor['vcpus']),
            'ram': -1 * (inst.new_flavor['memory_mb'] -
                         inst.old_flavor['memory_mb'])
        }

        deltas = compute_utils.reverse_upsize_quota_delta(self.context, inst)
        self.assertEqual(expected_deltas, deltas)
开发者ID:binarycode,项目名称:nova,代码行数:14,代码来源:test_compute_utils.py


示例13: create_instance

def create_instance(context, user_id="fake", project_id="fake", params=None):
    """Create a test instance."""
    flavor = flavors.get_flavor_by_name("m1.tiny")
    net_info = model.NetworkInfo([])
    info_cache = objects.InstanceInfoCache(network_info=net_info)
    inst = objects.Instance(
        context=context,
        image_ref=1,
        reservation_id="r-fakeres",
        user_id=user_id,
        project_id=project_id,
        instance_type_id=flavor.id,
        flavor=flavor,
        old_flavor=None,
        new_flavor=None,
        system_metadata={},
        ami_launch_index=0,
        root_gb=0,
        ephemeral_gb=0,
        info_cache=info_cache,
    )
    if params:
        inst.update(params)
    inst.create()
    return inst
开发者ID:jorgevgut,项目名称:nova,代码行数:25,代码来源:test_compute_utils.py


示例14: test_notify_about_instance_action

    def test_notify_about_instance_action(self):
        instance = create_instance(self.context)

        compute_utils.notify_about_instance_action(
            self.context,
            instance,
            host='fake-compute',
            action='delete',
            phase='start')

        self.assertEqual(len(fake_notifier.VERSIONED_NOTIFICATIONS), 1)
        notification = fake_notifier.VERSIONED_NOTIFICATIONS[0]

        self.assertEqual(notification['priority'], 'INFO')
        self.assertEqual(notification['event_type'], 'instance.delete.start')
        self.assertEqual(notification['publisher_id'],
                         'nova-compute:fake-compute')

        payload = notification['payload']['nova_object.data']
        self.assertEqual(payload['tenant_id'], self.project_id)
        self.assertEqual(payload['user_id'], self.user_id)
        self.assertEqual(payload['uuid'], instance['uuid'])

        flavorid = flavors.get_flavor_by_name('m1.tiny')['flavorid']
        flavor = payload['flavor']['nova_object.data']
        self.assertEqual(str(flavor['flavorid']), flavorid)

        for attr in ('display_name', 'created_at', 'launched_at',
                     'state', 'task_state', 'display_description', 'locked'):
            self.assertIn(attr, payload, "Key %s not in payload" % attr)

        self.assertEqual(payload['image_uuid'], uuids.fake_image_ref)
开发者ID:vmturbo,项目名称:nova,代码行数:32,代码来源:test_compute_utils.py


示例15: test_notify_usage_exists_deleted_instance

 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     self.compute.terminate_instance(self.context, instance)
     instance = db.instance_get(self.context.elevated(read_deleted='yes'),
                                instance_id)
     compute_utils.notify_usage_exists(self.context, instance)
     msg = test_notifier.NOTIFICATIONS[-1]
     self.assertEquals(msg['priority'], 'INFO')
     self.assertEquals(msg['event_type'], 'compute.instance.exists')
     payload = msg['payload']
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description',
                  'bandwidth', 'audit_period_beginning',
                  'audit_period_ending', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
开发者ID:DavidYan,项目名称:nova,代码行数:34,代码来源:test_compute_utils.py


示例16: test_flavor_get_by_None_name_returns_default

 def test_flavor_get_by_None_name_returns_default(self):
     # Ensure get by name returns default flavor with no name.
     default = flavors.get_default_flavor()
     actual = flavors.get_flavor_by_name(None)
     self.assertIsInstance(default, objects.Flavor)
     self.assertIsInstance(actual, objects.Flavor)
     self.assertEqual(default.flavorid, actual.flavorid)
开发者ID:Juniper,项目名称:nova,代码行数:7,代码来源:test_flavors.py


示例17: _test_get_resources

    def _test_get_resources(self):
        old_flavor = flavors.get_flavor_by_name('m1.tiny')
        new_flavor = flavors.get_flavor_by_name('m1.medium')

        params = {'flavor': new_flavor, 'old_flavor': old_flavor,
                  'new_flavor': new_flavor, 'vcpus': new_flavor['vcpus'],
                  'memory_mb': new_flavor['memory_mb']}
        instance = create_instance(self.context, params=params)

        updates = {'old_instance_type_id': old_flavor['id'],
                   'new_instance_type_id': new_flavor['id']}

        fake_migration = test_migration.fake_db_migration(**updates)
        migration = objects.Migration._from_db_object(self.context,
                                                      objects.Migration(),
                                                      fake_migration)
        return old_flavor, migration, instance
开发者ID:fabian4,项目名称:nova,代码行数:17,代码来源:test_compute_utils.py


示例18: test_notify_usage_exists_deleted_instance

 def test_notify_usage_exists_deleted_instance(self):
     # Ensure 'exists' notification generates appropriate usage data.
     instance_id = self._create_instance()
     instance = instance_obj.Instance.get_by_id(
         self.context, instance_id, expected_attrs=["metadata", "system_metadata", "info_cache"]
     )
     # Set some system metadata
     sys_metadata = {"image_md_key1": "val1", "image_md_key2": "val2", "other_data": "meow"}
     instance.system_metadata.update(sys_metadata)
     instance.save()
     self.compute.terminate_instance(self.context, instance, [], [])
     instance = instance_obj.Instance.get_by_id(
         self.context.elevated(read_deleted="yes"), instance_id, expected_attrs=["system_metadata"]
     )
     compute_utils.notify_usage_exists(rpc.get_notifier("compute"), self.context, instance)
     msg = fake_notifier.NOTIFICATIONS[-1]
     self.assertEqual(msg.priority, "INFO")
     self.assertEqual(msg.event_type, "compute.instance.exists")
     payload = msg.payload
     self.assertEqual(payload["tenant_id"], self.project_id)
     self.assertEqual(payload["user_id"], self.user_id)
     self.assertEqual(payload["instance_id"], instance["uuid"])
     self.assertEqual(payload["instance_type"], "m1.tiny")
     type_id = flavors.get_flavor_by_name("m1.tiny")["id"]
     self.assertEqual(str(payload["instance_type_id"]), str(type_id))
     flavor_id = flavors.get_flavor_by_name("m1.tiny")["flavorid"]
     self.assertEqual(str(payload["instance_flavor_id"]), str(flavor_id))
     for attr in (
         "display_name",
         "created_at",
         "launched_at",
         "state",
         "state_description",
         "bandwidth",
         "audit_period_beginning",
         "audit_period_ending",
         "image_meta",
     ):
         self.assertTrue(attr in payload, msg="Key %s not in payload" % attr)
     self.assertEqual(payload["image_meta"], {"md_key1": "val1", "md_key2": "val2"})
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEqual(payload["image_ref_url"], image_ref_url)
开发者ID:jacobwagner,项目名称:nova,代码行数:42,代码来源:test_compute_utils.py


示例19: test_notify_about_instance_usage

 def test_notify_about_instance_usage(self):
     instance_id = self._create_instance()
     instance = db.instance_get(self.context, instance_id)
     # Set some system metadata
     sys_metadata = {'image_md_key1': 'val1',
                     'image_md_key2': 'val2',
                     'other_data': 'meow'}
     extra_usage_info = {'image_name': 'fake_name'}
     db.instance_system_metadata_update(self.context, instance['uuid'],
             sys_metadata, False)
     # NOTE(russellb) Make sure our instance has the latest system_metadata
     # in it.
     instance = db.instance_get(self.context, instance_id)
     compute_utils.notify_about_instance_usage(
         notify.get_notifier('compute'),
         self.context, instance, 'create.start',
         extra_usage_info=extra_usage_info)
     self.assertEquals(len(fake_notifier.NOTIFICATIONS), 1)
     msg = fake_notifier.NOTIFICATIONS[0]
     self.assertEquals(msg.priority, 'INFO')
     self.assertEquals(msg.event_type, 'compute.instance.create.start')
     payload = msg.payload
     self.assertEquals(payload['tenant_id'], self.project_id)
     self.assertEquals(payload['user_id'], self.user_id)
     self.assertEquals(payload['instance_id'], instance['uuid'])
     self.assertEquals(payload['instance_type'], 'm1.tiny')
     type_id = flavors.get_flavor_by_name('m1.tiny')['id']
     self.assertEquals(str(payload['instance_type_id']), str(type_id))
     flavor_id = flavors.get_flavor_by_name('m1.tiny')['flavorid']
     self.assertEquals(str(payload['instance_flavor_id']), str(flavor_id))
     for attr in ('display_name', 'created_at', 'launched_at',
                  'state', 'state_description', 'image_meta'):
         self.assertTrue(attr in payload,
                         msg="Key %s not in payload" % attr)
     self.assertEquals(payload['image_meta'],
             {'md_key1': 'val1', 'md_key2': 'val2'})
     self.assertEquals(payload['image_name'], 'fake_name')
     image_ref_url = "%s/images/1" % glance.generate_glance_url()
     self.assertEquals(payload['image_ref_url'], image_ref_url)
     self.compute.terminate_instance(self.context,
                                     jsonutils.to_primitive(instance))
开发者ID:Yuriy-Leonov,项目名称:nova,代码行数:41,代码来源:test_compute_utils.py


示例20: create_instance

def create_instance(context, instance=None, driver=None):
    """Create a test instance"""

    if instance == None:
        instance = {}

    system_metadata = instance.get('system_metadata', {})
    instance_type = flavors.get_flavor_by_name('m1.tiny')
    system_metadata.update(flavors.save_flavor_info(dict(), instance_type))

    instance.setdefault('user_id', context.user_id)
    instance.setdefault('project_id', context.project_id)
    instance.setdefault('instance_type_id', instance_type['id'])
    instance.setdefault('system_metadata', system_metadata)
    instance.setdefault('image_id', 1)
    instance.setdefault('image_ref', 1)
    instance.setdefault('reservation_id', 'r-fakeres')
    instance.setdefault('launch_time', '10')
    instance.setdefault('mac_address', "ca:ca:ca:01")
    instance.setdefault('ami_launch_index', 0)
    instance.setdefault('vm_state', vm_states.ACTIVE)
    instance.setdefault('root_gb', 10)
    instance.setdefault('ephemeral_gb', 10)
    instance.setdefault('memory_mb', 512)
    instance.setdefault('vcpus', 1)
    instance.setdefault('info_cache', {'network_info':json.dumps({})})

        # We should record in the quotas information about this instance.
    reservations = quota.QUOTAS.reserve(context, instances=1,
                         ram=instance['memory_mb'],
                         cores=instance['vcpus'])

    context.elevated()
    instance_ref = db.instance_create(context, instance)
    db.block_device_mapping_create(context,
            {'source_type': 'image',
             'destination_type': 'local',
             'device_type': 'disk',
             'image_id': 1,
             'boot_index': 0,
             'instance_uuid': instance_ref['uuid']},
             legacy=False)

    if driver:
        # Add this instance to the driver
        driver.instances[instance_ref.name] = FakeInstance(instance_ref.name,
                                                           instance_ref.get('power_state',
                                                                             power_state.RUNNING))

    quota.QUOTAS.commit(context, reservations)

    return instance_ref['uuid']
开发者ID:alanmeadows,项目名称:cobalt,代码行数:52,代码来源:utils.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python flavors.save_flavor_info函数代码示例发布时间:2022-05-27
下一篇:
Python flavors.get_flavor_by_flavor_id函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap