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


Python flavors.get_flavor_by_flavor_id函数代码示例

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


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

示例1: test_resize_quota_exceeds_fails

    def test_resize_quota_exceeds_fails(self):
        self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
        self.mox.StubOutWithMock(self.compute_api, '_upsize_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        # Should never reach these.
        self.mox.StubOutWithMock(self.compute_api, 'update')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(self.compute_api.compute_task_api,
                                 'migrate_server')

        fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
        current_flavor = flavors.extract_flavor(fake_inst)
        fake_flavor = dict(id=200, flavorid='flavor-id', name='foo',
                           disabled=False)
        flavors.get_flavor_by_flavor_id(
                'flavor-id', read_deleted='no').AndReturn(fake_flavor)
        deltas = dict(resource=0)
        self.compute_api._upsize_quota_delta(
                self.context, fake_flavor,
                current_flavor).AndReturn(deltas)
        usage = dict(in_use=0, reserved=0)
        over_quota_args = dict(quotas={'resource': 0},
                               usages={'resource': usage},
                               overs=['resource'])
        self.compute_api._reserve_quota_delta(self.context, deltas,
                project_id=fake_inst['project_id']).AndRaise(
                        exception.OverQuota(**over_quota_args))

        self.mox.ReplayAll()

        self.assertRaises(exception.TooManyInstances,
                          self.compute_api.resize, self.context,
                          fake_inst, flavor_id='flavor-id')
开发者ID:wingo1990,项目名称:nova,代码行数:34,代码来源:test_compute_api.py

示例2: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
            def_image_ref = "http://localhost/v3/os-images/%s" % image_uuid
            self.instance_cache_num += 1
            instance = {
                "id": self.instance_cache_num,
                "display_name": inst["display_name"] or "test",
                "uuid": MANUAL_INSTANCE_UUID,
                "instance_type": dict(inst_type),
                "access_ip_v4": "1.2.3.4",
                "access_ip_v6": "fead::1234",
                "image_ref": inst.get("image_ref", def_image_ref),
                "user_id": "fake",
                "project_id": "fake",
                "reservation_id": inst["reservation_id"],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "user_data": None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
            }

            self.instance_cache_by_id[instance["id"]] = instance
            self.instance_cache_by_uuid[instance["uuid"]] = instance
            return instance
开发者ID:cloudbau,项目名称:nova,代码行数:28,代码来源:test_disk_config.py

示例3: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "config_drive": None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
                "security_groups": inst['security_groups'],
                "extra": {"pci_requests": None,
                          "numa_topology": None},
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance
开发者ID:EdLeafe,项目名称:nova,代码行数:32,代码来源:test_multiple_create.py

示例4: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/{0!s}'.format(image_uuid)
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': inst['uuid'],
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "security_groups": inst['security_groups'],
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance
开发者ID:runt18,项目名称:nova,代码行数:28,代码来源:test_multiple_create.py

示例5: _fake_compute_api_create

        def _fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
            self._block_device_mapping_seen = kwargs.get("block_device_mapping")
            self._legacy_bdm_seen = kwargs.get("legacy_bdm")

            inst_type = flavors.get_flavor_by_flavor_id(2)
            resv_id = None
            return (
                [
                    {
                        "id": 1,
                        "display_name": "test_server",
                        "uuid": FAKE_UUID,
                        "instance_type": inst_type,
                        "access_ip_v4": "1.2.3.4",
                        "access_ip_v6": "fead::1234",
                        "image_ref": IMAGE_UUID,
                        "user_id": "fake",
                        "project_id": "fake",
                        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                        "progress": 0,
                        "fixed_ips": [],
                    }
                ],
                resv_id,
            )
开发者ID:yizhongyin,项目名称:OpenstackLiberty,代码行数:26,代码来源:test_volumes.py

示例6: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'availability_zone': 'nova',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
            })

            return instance
开发者ID:ezhangle,项目名称:nova,代码行数:27,代码来源:test_availability_zone.py

示例7: resize_vm

def resize_vm(uid, flavor_id, context):
    """
    Resizes a VM up or down

    Update: libvirt now supports resize see:
    http://wiki.openstack.org/HypervisorSupportMatrix

    uid -- id of the instance
    flavor_id -- image reference.
    context -- the os context
    """
    instance = get_vm(uid, context)
    kwargs = {}
    try:
        flavor = flavors.get_flavor_by_flavor_id(flavor_id)
        COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
                           **kwargs)
        ready = False
        i = 0
        # XXX are 15 secs enough to resize?
        while not ready and i < 15:
            i += 1
            state = get_vm(uid, context)['vm_state']
            if state == 'resized':
                ready = True
            import time
            time.sleep(1)
        instance = get_vm(uid, context)
        COMPUTE_API.confirm_resize(context, instance)
    except Exception as e:
        raise AttributeError(str(e))
开发者ID:ic-hep,项目名称:occi-os,代码行数:31,代码来源:vm.py

示例8: test_will_get_instance_by_flavor_id

 def test_will_get_instance_by_flavor_id(self):
     default_instance_type = objects.Flavor.get_by_name(
         context.get_admin_context(), 'm1.small')
     flavorid = default_instance_type.flavorid
     fetched = flavors.get_flavor_by_flavor_id(flavorid)
     self.assertIsInstance(fetched, objects.Flavor)
     self.assertEqual(default_instance_type.flavorid, fetched.flavorid)
开发者ID:mahak,项目名称:nova,代码行数:7,代码来源:test_flavors.py

示例9: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        try:
            flavor = flavors.get_flavor_by_flavor_id(id)
            req.cache_db_flavor(flavor)
        except exception.NotFound:
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, flavor)
开发者ID:ChaosCloud,项目名称:nova,代码行数:9,代码来源:flavors.py

示例10: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        try:
            flavor = flavors.get_flavor_by_flavor_id(id)
            req.cache_db_flavor(flavor)
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        return self._view_builder.show(req, flavor)
开发者ID:joseluizrf,项目名称:nova,代码行数:9,代码来源:flavors.py

示例11: _delete

    def _delete(self, req, id):
        context = req.environ["nova.context"]
        authorize(context)

        try:
            flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted="no")
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor["name"])
开发者ID:BU-NU-CLOUD-SP16,项目名称:Trusted-Platform-Module-nova,代码行数:10,代码来源:flavor_manage.py

示例12: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        try:
            context = req.environ['nova.context']
            flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted='no')
            req.cache_db_flavor(flavor)
        except exception.NotFound:
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, flavor)
开发者ID:guykr-stratoscale,项目名称:nova,代码行数:10,代码来源:flavors.py

示例13: test_read_deleted_false_converting_flavorid

    def test_read_deleted_false_converting_flavorid(self):
        """Ensure deleted flavors are not returned when not needed (for
        example when creating a server and attempting to translate from
        flavorid to instance_type_id.
        """
        flavors.create("instance_type1", 256, 1, 120, 100, "test1")
        flavors.destroy("instance_type1")
        flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1")

        instance_type = flavors.get_flavor_by_flavor_id("test1", read_deleted="no")
        self.assertEqual("instance_type1_redo", instance_type.name)
开发者ID:isyippee,项目名称:nova,代码行数:11,代码来源:test_flavors.py

示例14: test_resize_invalid_flavor_fails

    def test_resize_invalid_flavor_fails(self):
        self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
        # Should never reach these.
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, 'update')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(self.compute_api.compute_task_api,
                                 'migrate_server')

        fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
        exc = exception.FlavorNotFound(flavor_id='flavor-id')

        flavors.get_flavor_by_flavor_id('flavor-id',
                                        read_deleted='no').AndRaise(exc)

        self.mox.ReplayAll()

        self.assertRaises(exception.FlavorNotFound,
                          self.compute_api.resize, self.context,
                          fake_inst, flavor_id='flavor-id')
开发者ID:wingo1990,项目名称:nova,代码行数:21,代码来源:test_compute_api.py

示例15: _delete

    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)
        try:
            flavor = flavors.get_flavor_by_flavor_id(
                    id, ctxt=context, read_deleted="no")
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor['name'])

        return webob.Response(status_int=202)
开发者ID:375670450,项目名称:nova,代码行数:12,代码来源:flavormanage.py


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