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

Python utils.is_volume_backed_instance函数代码示例

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

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



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

示例1: resources_from_flavor

def resources_from_flavor(instance, flavor):
    """Convert a flavor into a set of resources for placement, taking into
    account boot-from-volume instances.

    This takes an instance and a flavor and returns a dict of
    resource_class:amount based on the attributes of the flavor, accounting for
    any overrides that are made in extra_specs.
    """
    is_bfv = compute_utils.is_volume_backed_instance(instance._context,
                                                     instance)
    swap_in_gb = compute_utils.convert_mb_to_ceil_gb(flavor.swap)
    disk = ((0 if is_bfv else flavor.root_gb) +
            swap_in_gb + flavor.ephemeral_gb)

    resources = {
        orc.VCPU: flavor.vcpus,
        orc.MEMORY_MB: flavor.memory_mb,
        orc.DISK_GB: disk,
    }
    if "extra_specs" in flavor:
        # TODO(efried): This method is currently only used from places that
        # assume the compute node is the only resource provider.  So for now,
        # we just merge together all the resources specified in the flavor and
        # pass them along.  This will need to be adjusted when nested and/or
        # shared RPs are in play.
        rreq = ResourceRequest.from_extra_specs(flavor.extra_specs)
        resources = rreq.merged_resources(flavor_resources=resources)

    return resources
开发者ID:openstack,项目名称:nova,代码行数:29,代码来源:utils.py


示例2: _action_create_image

    def _action_create_image(self, req, id, body):
        """Snapshot a server instance."""
        context = req.environ['nova.context']
        entity = body.get("createImage", {})

        image_name = entity.get("name")

        if not image_name:
            msg = _("createImage entity requires name attribute")
            raise exc.HTTPBadRequest(explanation=msg)

        props = {}
        metadata = entity.get('metadata', {})
        common.check_img_metadata_properties_quota(context, metadata)
        try:
            props.update(metadata)
        except ValueError:
            msg = _("Invalid metadata")
            raise exc.HTTPBadRequest(explanation=msg)

        instance = self._get_server(context, req, id)

        bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
                    context, instance.uuid)

        try:
            if compute_utils.is_volume_backed_instance(context, instance,
                                                          bdms):
                policy.enforce(context,
                        'compute:snapshot_volume_backed',
                        {'project_id': context.project_id,
                        'user_id': context.user_id})
                image = self.compute_api.snapshot_volume_backed(
                                                       context,
                                                       instance,
                                                       image_name,
                                                       extra_properties=props)
            else:
                image = self.compute_api.snapshot(context,
                                                  instance,
                                                  image_name,
                                                  extra_properties=props)
        except exception.InstanceInvalidState as state_error:
            common.raise_http_conflict_for_instance_invalid_state(state_error,
                        'createImage', id)
        except exception.Invalid as err:
            raise exc.HTTPBadRequest(explanation=err.format_message())

        # build location of newly-created image entity
        image_id = str(image['id'])
        url_prefix = self._view_builder._update_glance_link_prefix(
                req.application_url)
        image_ref = common.url_join(url_prefix,
                                    context.project_id,
                                    'images',
                                    image_id)

        resp = webob.Response(status_int=202)
        resp.headers['Location'] = image_ref
        return resp
开发者ID:bigswitch,项目名称:nova,代码行数:60,代码来源:servers.py


示例3: test_is_volume_backed_instance_bdm_local_no_image

 def test_is_volume_backed_instance_bdm_local_no_image(self):
     # if the root device is local the instance is not volume backed, even
     # if no image_ref is set.
     ctxt = self.context
     instance = create_instance(ctxt, params={
         'root_device_name': 'vda',
         'image_ref': ''
     })
     bdms = block_device_obj.block_device_make_list(ctxt,
            [fake_block_device.FakeDbBlockDeviceDict(
             {'source_type': 'volume',
              'device_name': '/dev/vda',
              'volume_id': uuids.volume_id,
              'destination_type': 'local',
              'instance_uuid': 'f8000000-0000-0000-0000-000000000000',
              'boot_index': 0,
              'snapshot_id': None}),
             fake_block_device.FakeDbBlockDeviceDict(
             {'source_type': 'volume',
              'device_name': '/dev/vdb',
              'instance_uuid': 'f8000000-0000-0000-0000-000000000000',
              'boot_index': 1,
              'destination_type': 'volume',
              'volume_id': 'c2ec2156-d75e-11e2-985b-5254009297d6',
              'snapshot_id': None})])
     self.assertFalse(
         compute_utils.is_volume_backed_instance(ctxt, instance, bdms))
开发者ID:binarycode,项目名称:nova,代码行数:27,代码来源:test_compute_utils.py


示例4: test_is_volume_backed_instance_empty_bdm_by_uuid

 def test_is_volume_backed_instance_empty_bdm_by_uuid(self, mock_bdms):
     ctxt = self.context
     instance = create_instance(ctxt)
     mock_bdms.return_value = block_device_obj.block_device_make_list(
         ctxt, [])
     self.assertFalse(
         compute_utils.is_volume_backed_instance(ctxt, instance, None))
     mock_bdms.assert_called_with(ctxt, instance.uuid)
开发者ID:binarycode,项目名称:nova,代码行数:8,代码来源:test_compute_utils.py


示例5: _instance_to_allocations_dict

def _instance_to_allocations_dict(instance):
    """Given an `objects.Instance` object, return a dict, keyed by resource
    class of the amount used by the instance.

    :param instance: `objects.Instance` object to translate
    """
    # NOTE(danms): Boot-from-volume instances consume no local disk
    is_bfv = compute_utils.is_volume_backed_instance(instance._context, instance)
    disk = (0 if is_bfv else instance.flavor.root_gb) + instance.flavor.swap + instance.flavor.ephemeral_gb
    return {MEMORY_MB: instance.flavor.memory_mb, VCPU: instance.flavor.vcpus, DISK_GB: disk}
开发者ID:alaski,项目名称:nova,代码行数:10,代码来源:report.py


示例6: test_is_volume_backed_instance_empty_bdm_with_image

 def test_is_volume_backed_instance_empty_bdm_with_image(self):
     ctxt = self.context
     instance = create_instance(ctxt, params={
         'root_device_name': 'vda',
         'image_ref': FAKE_IMAGE_REF
     })
     self.assertFalse(
         compute_utils.is_volume_backed_instance(
             ctxt, instance,
             block_device_obj.block_device_make_list(ctxt, [])))
开发者ID:binarycode,项目名称:nova,代码行数:10,代码来源:test_compute_utils.py


示例7: _allocations

 def _allocations(self, instance):
     # NOTE(danms): Boot-from-volume instances consume no local disk
     is_bfv = compute_utils.is_volume_backed_instance(instance._context,
                                                      instance)
     disk = ((0 if is_bfv else instance.flavor.root_gb) +
             instance.flavor.swap +
             instance.flavor.ephemeral_gb)
     return {
         'MEMORY_MB': instance.flavor.memory_mb,
         'VCPU': instance.flavor.vcpus,
         'DISK_GB': disk,
     }
开发者ID:taget,项目名称:nova,代码行数:12,代码来源:report.py


示例8: test_is_volume_backed_instance_bdm_volume_with_image

 def test_is_volume_backed_instance_bdm_volume_with_image(self):
     ctxt = self.context
     instance = create_instance(ctxt, params={
         'root_device_name': 'vda',
         'image_ref': FAKE_IMAGE_REF
     })
     bdms = block_device_obj.block_device_make_list(ctxt,
                         [fake_block_device.FakeDbBlockDeviceDict(
                             {'source_type': 'volume',
                              'device_name': '/dev/vda',
                              'volume_id': uuids.volume_id,
                              'boot_index': 0,
                              'destination_type': 'volume'})])
     self.assertTrue(
         compute_utils.is_volume_backed_instance(ctxt, instance, bdms))
开发者ID:binarycode,项目名称:nova,代码行数:15,代码来源:test_compute_utils.py


示例9: test_is_volume_backed_instance_bdm_snapshot

 def test_is_volume_backed_instance_bdm_snapshot(self):
     ctxt = self.context
     instance = create_instance(ctxt, params={
         'root_device_name': 'vda'
     })
     bdms = block_device_obj.block_device_make_list(ctxt,
            [fake_block_device.FakeDbBlockDeviceDict(
             {'source_type': 'volume',
              'device_name': '/dev/vda',
              'snapshot_id': 'de8836ac-d75e-11e2-8271-5254009297d6',
              'instance_uuid': 'f8000000-0000-0000-0000-000000000000',
              'destination_type': 'volume',
              'boot_index': 0,
              'volume_id': None})])
     self.assertTrue(
         compute_utils.is_volume_backed_instance(ctxt, instance, bdms))
开发者ID:binarycode,项目名称:nova,代码行数:16,代码来源:test_compute_utils.py


示例10: _action_create_image

    def _action_create_image(self, req, id, body):
        """Snapshot a server instance."""
        context = req.environ['nova.context']
        context.can(server_policies.SERVERS % 'create_image')

        entity = body["createImage"]
        image_name = common.normalize_name(entity["name"])
        metadata = entity.get('metadata', {})

        common.check_img_metadata_properties_quota(context, metadata)

        instance = self._get_server(context, req, id)

        bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(
                    context, instance.uuid)

        try:
            if compute_utils.is_volume_backed_instance(context, instance,
                                                          bdms):
                context.can(server_policies.SERVERS %
                    'create_image:allow_volume_backed')
                image = self.compute_api.snapshot_volume_backed(
                                                       context,
                                                       instance,
                                                       image_name,
                                                       extra_properties=
                                                       metadata)
            else:
                image = self.compute_api.snapshot(context,
                                                  instance,
                                                  image_name,
                                                  extra_properties=metadata)
        except exception.InstanceUnknownCell as e:
            raise exc.HTTPNotFound(explanation=e.format_message())
        except exception.InstanceInvalidState as state_error:
            common.raise_http_conflict_for_instance_invalid_state(state_error,
                        'createImage', id)
        except exception.Invalid as err:
            raise exc.HTTPBadRequest(explanation=err.format_message())

        # build location of newly-created image entity
        image_id = str(image['id'])
        image_ref = glance.generate_image_url(image_id)

        resp = webob.Response(status_int=202)
        resp.headers['Location'] = image_ref
        return resp
开发者ID:krsacme,项目名称:nova,代码行数:47,代码来源:servers.py


示例11: _instance_to_allocations_dict

def _instance_to_allocations_dict(instance):
    """Given an `objects.Instance` object, return a dict, keyed by resource
    class of the amount used by the instance.

    :param instance: `objects.Instance` object to translate
    """
    # NOTE(danms): Boot-from-volume instances consume no local disk
    is_bfv = compute_utils.is_volume_backed_instance(instance._context,
                                                     instance)
    # TODO(johngarbutt) we have to round up swap MB to the next GB.
    # It would be better to claim disk in MB, but that is hard now.
    swap_in_gb = _convert_mb_to_ceil_gb(instance.flavor.swap)
    disk = ((0 if is_bfv else instance.flavor.root_gb) +
            swap_in_gb + instance.flavor.ephemeral_gb)
    alloc_dict = {
        MEMORY_MB: instance.flavor.memory_mb,
        VCPU: instance.flavor.vcpus,
        DISK_GB: disk,
    }
    # Remove any zero allocations.
    return {key: val for key, val in alloc_dict.items() if val}
开发者ID:vmturbo,项目名称:nova,代码行数:21,代码来源:report.py


示例12: _instance_to_allocations_dict

def _instance_to_allocations_dict(instance):
    """Given an `objects.Instance` object, return a dict, keyed by resource
    class of the amount used by the instance.

    :param instance: `objects.Instance` object to translate
    """
    # NOTE(danms): Boot-from-volume instances consume no local disk
    is_bfv = compute_utils.is_volume_backed_instance(instance._context,
                                                     instance)
    # TODO(johngarbutt) we have to round up swap MB to the next GB.
    # It would be better to claim disk in MB, but that is hard now.
    swap_in_gb = convert_mb_to_ceil_gb(instance.flavor.swap)
    disk = ((0 if is_bfv else instance.flavor.root_gb) +
            swap_in_gb + instance.flavor.ephemeral_gb)
    alloc_dict = {
        MEMORY_MB: instance.flavor.memory_mb,
        VCPU: instance.flavor.vcpus,
        DISK_GB: disk,
    }

    # Pull out any resource overrides, which are in the format
    # "resources:FOO" and generate a dict of FOO=value candidates
    # for overriding the resources in the allocation.
    overrides = {k.split(':', 1)[1]: v for k, v in
                 instance.flavor.extra_specs.items()
                 if k.startswith('resources:')}

    # Any resource overrides which are properly namespaced as custom,
    # or are standard resource class values override the alloc_dict
    # already constructed from the base flavor values above. Since
    # extra_specs are string values and resource counts are always
    # integers, we convert them here too for any that we find.
    overrides = {k: int(v) for k, v in overrides.items()
            if (k.startswith(objects.ResourceClass.CUSTOM_NAMESPACE) or
                k in fields.ResourceClass.STANDARD)}

    alloc_dict.update(overrides)

    # Remove any zero allocations.
    return {key: val for key, val in alloc_dict.items() if val}
开发者ID:Juniper,项目名称:nova,代码行数:40,代码来源:report.py


示例13: resources_from_flavor

def resources_from_flavor(instance, flavor):
    """Convert a flavor into a set of resources for placement, taking into
    account boot-from-volume instances.

    This takes an instance and a flavor and returns a dict of
    resource_class:amount based on the attributes of the flavor, accounting for
    any overrides that are made in extra_specs.
    """
    is_bfv = compute_utils.is_volume_backed_instance(instance._context,
                                                     instance)
    swap_in_gb = compute_utils.convert_mb_to_ceil_gb(flavor.swap)
    disk = ((0 if is_bfv else flavor.root_gb) +
            swap_in_gb + flavor.ephemeral_gb)

    resources = {
        fields.ResourceClass.VCPU: flavor.vcpus,
        fields.ResourceClass.MEMORY_MB: flavor.memory_mb,
        fields.ResourceClass.DISK_GB: disk,
    }
    if "extra_specs" in flavor:
        _process_extra_specs(flavor.extra_specs, resources)
    return resources
开发者ID:sapcc,项目名称:nova,代码行数:22,代码来源:utils.py


示例14: test_is_volume_backed_instance_no_bdm_no_image

    def test_is_volume_backed_instance_no_bdm_no_image(self):
        ctxt = self.context

        instance = create_instance(ctxt, params={'image_ref': ''})
        self.assertTrue(
            compute_utils.is_volume_backed_instance(ctxt, instance, None))
开发者ID:binarycode,项目名称:nova,代码行数:6,代码来源:test_compute_utils.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python utils.notify_about_aggregate_update函数代码示例发布时间:2022-05-27
下一篇:
Python utils.get_reboot_type函数代码示例发布时间: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