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

Python instance_types.get_instance_type_by_flavor_id函数代码示例

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

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



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

示例1: 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 = instance_types.get_instance_type_by_flavor_id(flavor_id)
        COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
                           **kwargs)
        ready = False
        i = 0
        while not ready or 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(e.message)
开发者ID:brene,项目名称:occi-os,代码行数:30,代码来源:vm.py


示例2: fake_compute_api_create

def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
    global _block_device_mapping_seen
    _block_device_mapping_seen = kwargs.get("block_device_mapping")

    inst_type = instance_types.get_instance_type_by_flavor_id(2)
    resv_id = None
    return (
        [
            {
                "id": 1,
                "display_name": "test_server",
                "uuid": FAKE_UUID,
                "instance_type": dict(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:rmk40,项目名称:nova,代码行数:26,代码来源:test_volumes.py


示例3: stub_instance

def stub_instance(id, metadata=None, image_ref="10", flavor_id="1",
                  name=None, vm_state=None, task_state=None, uuid=None):
    if metadata is not None:
        metadata_items = [{'key':k, 'value':v} for k, v in metadata.items()]
    else:
        metadata_items = [{'key':'seq', 'value':id}]

    if uuid is None:
        uuid = FAKE_UUID

    inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))

    instance = {
        "id": int(id),
        "name": str(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "admin_pass": "",
        "user_id": "fake",
        "project_id": "fake",
        "image_ref": image_ref,
        "kernel_id": "",
        "ramdisk_id": "",
        "launch_index": 0,
        "key_name": "",
        "key_data": "",
        "vm_state": vm_state or vm_states.ACTIVE,
        "task_state": task_state,
        "memory_mb": 0,
        "vcpus": 0,
        "local_gb": 0,
        "hostname": "",
        "host": "",
        "instance_type": dict(inst_type),
        "user_data": "",
        "reservation_id": "",
        "mac_address": "",
        "scheduled_at": utils.utcnow(),
        "launched_at": utils.utcnow(),
        "terminated_at": utils.utcnow(),
        "availability_zone": "",
        "display_name": name or "server%s" % id,
        "display_description": "",
        "locked": False,
        "metadata": metadata_items,
        "access_ip_v4": "",
        "access_ip_v6": "",
        "uuid": uuid,
        "virtual_interfaces": [],
        "progress": 0,
    }

    instance["fixed_ips"] = [{"address": '192.168.0.1',
                              "network":
                                      {'label': 'public', 'cidr_v6': None},
                              "virtual_interface":
                                      {'address': 'aa:aa:aa:aa:aa:aa'},
                              "floating_ips": []}]

    return instance
开发者ID:nicopal,项目名称:nova,代码行数:60,代码来源:test_server_actions.py


示例4: 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 = instance_types.get_instance_type_by_flavor_id(flavor_id)
        COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
                           **kwargs)
        ready = False
        i = 0
        while not ready or 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.FlavorNotFound:
        raise AttributeError('Unable to locate requested flavor.')
    except exception.InstanceInvalidState as error:
        raise AttributeError('VM is in an invalid state: ' + str(error))
开发者ID:Acidburn0zzz,项目名称:occi-os,代码行数:32,代码来源:vm.py


示例5: _delete

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

        try:
            flavor = instance_types.get_instance_type_by_flavor_id(id)
        except exception.NotFound, e:
            raise webob.exc.HTTPNotFound(explanation=str(e))
开发者ID:russellb,项目名称:nova,代码行数:8,代码来源:flavormanage.py


示例6: show

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

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


示例7: _delete

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

        try:
            flavor = instance_types.get_instance_type_by_flavor_id(
                    id, read_deleted="no")
        except exception.NotFound, e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())
开发者ID:AnyBucket,项目名称:nova,代码行数:9,代码来源:flavormanage.py


示例8: _delete

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

        if not context.is_admin:
            return webob.Response(status_int=403)

        try:
            flavor = instance_types.get_instance_type_by_flavor_id(id)
        except exception.NotFound, e:
            raise webob.exc.HTTPNotFound(explanation=str(e))
开发者ID:KarimAllah,项目名称:nova,代码行数:10,代码来源:flavormanage.py


示例9: show

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

        builder = self._get_view_builder(req)
        values = builder.build(flavor, is_detail=True)
        return dict(flavor=values)
开发者ID:dragonetail,项目名称:nova,代码行数:11,代码来源:flavors.py


示例10: stub_instance

def stub_instance(id, power_state=0, metadata=None,
                  image_ref="10", flavor_id="1", name=None):

    if metadata is not None:
        metadata_items = [{'key':k, 'value':v} for k, v in metadata.items()]
    else:
        metadata_items = [{'key':'seq', 'value':id}]

    inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))

    instance = {
        "id": int(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "admin_pass": "",
        "user_id": "fake",
        "project_id": "fake",
        "image_ref": image_ref,
        "kernel_id": "",
        "ramdisk_id": "",
        "launch_index": 0,
        "key_name": "",
        "key_data": "",
        "state": power_state,
        "state_description": "",
        "memory_mb": 0,
        "vcpus": 0,
        "local_gb": 0,
        "hostname": "",
        "host": "",
        "instance_type": dict(inst_type),
        "user_data": "",
        "reservation_id": "",
        "mac_address": "",
        "scheduled_at": utils.utcnow(),
        "launched_at": utils.utcnow(),
        "terminated_at": utils.utcnow(),
        "availability_zone": "",
        "display_name": name or "server%s" % id,
        "display_description": "",
        "locked": False,
        "metadata": metadata_items,
        "access_ip_v4": "",
        "access_ip_v6": "",
        "uuid": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
        "virtual_interfaces": [],
    }

    instance["fixed_ips"] = {
        "address": '192.168.0.1',
        "floating_ips": [],
    }

    return instance
开发者ID:YouthSun,项目名称:nova,代码行数:54,代码来源:test_server_actions.py


示例11: test_read_deleted_false_converting_flavorid

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

        instance_type = instance_types.get_instance_type_by_flavor_id("test1", read_deleted="no")
        self.assertEqual("instance_type1_redo", instance_type["name"])
开发者ID:jamesbjackson,项目名称:openstack-smartos-nova-grizzly,代码行数:12,代码来源:test_instance_types.py


示例12: show

    def show(self, req, resp_obj, id):
        context = req.environ['nova.context']
        if authorize(context):
            # Attach our slave template to the response object
            resp_obj.attach(xml=FlavorextradatumTemplate())

            try:
                flavor_ref = instance_types.get_instance_type_by_flavor_id(id)
            except exception.FlavorNotFound:
                explanation = _("Flavor not found.")
                raise exception.HTTPNotFound(explanation=explanation)

            self._extend_flavor(resp_obj.obj['flavor'], flavor_ref)
开发者ID:A7Zulu,项目名称:nova,代码行数:13,代码来源:flavorextradata.py


示例13: delete

    def delete(self, req, id):
        qs = req.environ.get('QUERY_STRING', '')
        env = urlparse.parse_qs(qs)

        purge = env.get('purge', False)

        flavor = instance_types.get_instance_type_by_flavor_id(id)
        if purge:
            instance_types.purge(flavor['name'])
        else:
            instance_types.destroy(flavor['name'])

        return exc.HTTPAccepted()
开发者ID:mgius,项目名称:openstackx,代码行数:13,代码来源:admin.py


示例14: test_can_read_deleted_types_using_flavor_id

    def test_can_read_deleted_types_using_flavor_id(self):
        # Ensure deleted instance types can be read when querying flavor_id.
        inst_type_name = "test"
        inst_type_flavor_id = "test1"

        inst_type = instance_types.create(inst_type_name, 256, 1, 120, 100, inst_type_flavor_id)
        self.assertEqual(inst_type_name, inst_type["name"])

        # NOTE(jk0): The deleted flavor will show up here because the context
        # in get_instance_type_by_flavor_id() is set to use read_deleted by
        # default.
        instance_types.destroy(inst_type["name"])
        deleted_inst_type = instance_types.get_instance_type_by_flavor_id(inst_type_flavor_id)
        self.assertEqual(inst_type_name, deleted_inst_type["name"])
开发者ID:jamesbjackson,项目名称:openstack-smartos-nova-grizzly,代码行数:14,代码来源:test_instance_types.py


示例15: fake_compute_api_create

def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
    inst_type = instance_types.get_instance_type_by_flavor_id(2)
    return [{'id': 1,
             'display_name': 'test_server',
             'uuid': fake_gen_uuid(),
             'instance_type': dict(inst_type),
             'access_ip_v4': '1.2.3.4',
             'access_ip_v6': 'fead::1234',
             'image_ref': 3,
             '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),
             }]
开发者ID:AsherBond,项目名称:dodai-compute,代码行数:14,代码来源:test_volumes.py


示例16: index

    def index(self, req, flavor_id):
        context = req.environ['nova.context']
        authorize(context)

        try:
            flavor = instance_types.get_instance_type_by_flavor_id(flavor_id)
        except exception.FlavorNotFound:
            explanation = _("Flavor not found.")
            raise webob.exc.HTTPNotFound(explanation=explanation)

        # public flavor to all projects
        if flavor['is_public']:
            explanation = _("Access list not available for public flavors.")
            raise webob.exc.HTTPNotFound(explanation=explanation)

        # private flavor to listed projects only
        return _marshall_flavor_access(flavor_id)
开发者ID:NetApp,项目名称:nova,代码行数:17,代码来源:flavor_access.py


示例17: _action_resize

    def _action_resize(self, input_dict, req, id):
        """ Resizes a given instance to the flavor size requested """
        try:
            flavor_ref = input_dict["resize"]["flavorRef"]
        except (KeyError, TypeError):
            msg = _("Resize requests require 'flavorRef' attribute.")
            raise exc.HTTPBadRequest(explanation=msg)

        try:
            i_type = instance_types.get_instance_type_by_flavor_id(flavor_ref)
        except exception.FlavorNotFound:
            msg = _("Unable to locate requested flavor.")
            raise exc.HTTPBadRequest(explanation=msg)

        context = req.environ["nova.context"]
        self.compute_api.resize(context, id, i_type["id"])

        return webob.Response(status_int=202)
开发者ID:cp16net,项目名称:reddwarf,代码行数:18,代码来源:servers.py


示例18: fake_compute_api_create

def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
    global _block_device_mapping_seen
    _block_device_mapping_seen = kwargs.get('block_device_mapping')

    inst_type = instance_types.get_instance_type_by_flavor_id(2)
    resv_id = None
    return ([{'id': 1,
             'display_name': 'test_server',
             'uuid': fake_gen_uuid(),
             'instance_type': dict(inst_type),
             'access_ip_v4': '1.2.3.4',
             'access_ip_v6': 'fead::1234',
             'image_ref': 3,
             '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
             }], resv_id)
开发者ID:Oneiroi,项目名称:nova,代码行数:19,代码来源:test_volumes.py


示例19: resize

    def resize(self, context, instance, *args, **kwargs):
        """Resize (ie, migrate) a running instance.

        If flavor_id is None, the process is considered a migration, keeping
        the original flavor_id. If flavor_id is not None, the instance should
        be migrated to a new host and resized to the new flavor_id.
        """
        super(ComputeCellsAPI, self).resize(context, instance, *args, **kwargs)

        # NOTE(johannes): If we get to this point, then we know the
        # specified flavor_id is valid and exists. We'll need to load
        # it again, but that should be safe.

        old_instance_type_id = instance['instance_type_id']
        old_instance_type = instance_types.get_instance_type(
                old_instance_type_id)

        flavor_id = kwargs.get('flavor_id')

        if not flavor_id:
            new_instance_type = old_instance_type
        else:
            new_instance_type = instance_types.get_instance_type_by_flavor_id(
                    flavor_id)

        # NOTE(johannes): Later, when the resize is confirmed or reverted,
        # the superclass implementations of those methods will need access
        # to a local migration record for quota reasons. We don't need
        # source and/or destination information, just the old and new
        # instance_types. Status is set to 'finished' since nothing else
        # will update the status along the way.
        self.db.migration_create(context.elevated(),
                    {'instance_uuid': instance['uuid'],
                     'old_instance_type_id': old_instance_type['id'],
                     'new_instance_type_id': new_instance_type['id'],
                     'status': 'finished'})

        # FIXME(comstud): pass new instance_type object down to a method
        # that'll unfold it
        self._cast_to_cells(context, instance, 'resize', *args, **kwargs)
开发者ID:bihicheng,项目名称:nova,代码行数:40,代码来源:cells_api.py


示例20: stub_instance

def stub_instance(id, user_id=None, project_id=None, host=None,
                  vm_state=None, task_state=None,
                  reservation_id="", uuid=FAKE_UUID, image_ref="10",
                  flavor_id="1", name=None, key_name='',
                  access_ipv4=None, access_ipv6=None, progress=0,
                  auto_disk_config=False, display_name=None,
                  include_fake_metadata=True, config_drive=None,
                  power_state=None, nw_cache=None, metadata=None,
                  security_groups=None, root_device_name=None,
                  limit=None, marker=None):

    if user_id is None:
        user_id = 'fake_user'
    if project_id is None:
        project_id = 'fake_project'

    if metadata:
        metadata = [{'key':k, 'value':v} for k, v in metadata.items()]
    elif include_fake_metadata:
        metadata = [models.InstanceMetadata(key='seq', value=str(id))]
    else:
        metadata = []

    inst_type = instance_types.get_instance_type_by_flavor_id(int(flavor_id))

    if host is not None:
        host = str(host)

    if key_name:
        key_data = 'FAKE'
    else:
        key_data = ''

    if security_groups is None:
        security_groups = [{"id": 1, "name": "test"}]

    # ReservationID isn't sent back, hack it in there.
    server_name = name or "server%s" % id
    if reservation_id != "":
        server_name = "reservation_%s" % (reservation_id, )

    info_cache = create_info_cache(nw_cache)

    instance = {
        "id": int(id),
        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
        "user_id": user_id,
        "project_id": project_id,
        "image_ref": image_ref,
        "kernel_id": "",
        "ramdisk_id": "",
        "launch_index": 0,
        "key_name": key_name,
        "key_data": key_data,
        "config_drive": config_drive,
        "vm_state": vm_state or vm_states.BUILDING,
        "task_state": task_state,
        "power_state": power_state,
        "memory_mb": 0,
        "vcpus": 0,
        "root_gb": 0,
        "ephemeral_gb": 0,
        "hostname": display_name or server_name,
        "host": host,
        "instance_type_id": 1,
        "instance_type": dict(inst_type),
        "user_data": "",
        "reservation_id": reservation_id,
        "mac_address": "",
        "scheduled_at": timeutils.utcnow(),
        "launched_at": timeutils.utcnow(),
        "terminated_at": timeutils.utcnow(),
        "availability_zone": "",
        "display_name": display_name or server_name,
        "display_description": "",
        "locked": False,
        "metadata": metadata,
        "access_ip_v4": access_ipv4,
        "access_ip_v6": access_ipv6,
        "uuid": uuid,
        "progress": progress,
        "auto_disk_config": auto_disk_config,
        "name": "instance-%s" % id,
        "shutdown_terminate": True,
        "disable_terminate": False,
        "security_groups": security_groups,
        "root_device_name": root_device_name}

    instance.update(info_cache)

    return instance
开发者ID:EE-NovRain,项目名称:nova,代码行数:92,代码来源:fakes.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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