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


Python flavors.get_flavor_by_name函数代码示例

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


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