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


Python base.ec2_md_print函数代码示例

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


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

示例1: __call__

    def __call__(self, req):
        remote_address = req.remote_addr
        if CONF.use_forwarded_for:
            remote_address = req.headers.get('X-Forwarded-For', remote_address)

        if os.path.normpath("/" + req.path_info) == "/":
            return(base.ec2_md_print(base.VERSIONS + ["latest"]))

        try:
            meta_data = self.get_metadata(remote_address)
        except Exception:
            LOG.exception(_('Failed to get metadata for ip: %s'),
                          remote_address)
            msg = _('An unknown error has occurred. '
                    'Please try your request again.')
            exc = webob.exc.HTTPInternalServerError(explanation=unicode(msg))
            return exc
        if meta_data is None:
            LOG.error(_('Failed to get metadata for ip: %s'), remote_address)
            raise webob.exc.HTTPNotFound()

        try:
            data = meta_data.lookup(req.path_info)
        except base.InvalidMetadataPath:
            raise webob.exc.HTTPNotFound()

        return base.ec2_md_print(data)
开发者ID:EE-NovRain,项目名称:nova,代码行数:27,代码来源:handler.py

示例2: __call__

    def __call__(self, req):
        if os.path.normpath(req.path_info) == "/":
            return(base.ec2_md_print(base.VERSIONS + ["latest"]))

        if CONF.service_neutron_metadata_proxy:
            meta_data = self._handle_instance_id_request(req)
        else:
            if req.headers.get('X-Instance-ID'):
                LOG.warn(
                    _("X-Instance-ID present in request headers. The "
                      "'service_neutron_metadata_proxy' option must be enabled"
                      " to process this header."))
            meta_data = self._handle_remote_ip_request(req)

        if meta_data is None:
            raise webob.exc.HTTPNotFound()

        try:
            data = meta_data.lookup(req.path_info)
        except base.InvalidMetadataPath:
            raise webob.exc.HTTPNotFound()

        if callable(data):
            return data(req, meta_data)

        return base.ec2_md_print(data)
开发者ID:Redosen,项目名称:nova,代码行数:26,代码来源:handler.py

示例3: __call__

    def __call__(self, req):
        if os.path.normpath(req.path_info) == "/":
            resp = base.ec2_md_print(base.VERSIONS + ["latest"])
            req.response.body = resp
            req.response.content_type = base.MIME_TYPE_TEXT_PLAIN
            return req.response

        if CONF.neutron.service_metadata_proxy:
            meta_data = self._handle_instance_id_request(req)
        else:
            if req.headers.get('X-Instance-ID'):
                LOG.warn(
                    _LW("X-Instance-ID present in request headers. The "
                        "'service_metadata_proxy' option must be "
                        "enabled to process this header."))
            meta_data = self._handle_remote_ip_request(req)

        if meta_data is None:
            raise webob.exc.HTTPNotFound()

        try:
            data = meta_data.lookup(req.path_info)
        except base.InvalidMetadataPath:
            raise webob.exc.HTTPNotFound()

        if callable(data):
            return data(req, meta_data)

        resp = base.ec2_md_print(data)
        req.response.body = resp
        req.response.content_type = meta_data.get_mimetype()
        return req.response
开发者ID:AsherBond,项目名称:nova,代码行数:32,代码来源:handler.py

示例4: test_pubkey

    def test_pubkey(self):
        md = fake_InstanceMetadata(self.stubs, self.instance.obj_clone())
        pubkey_ent = md.lookup("/2009-04-04/meta-data/public-keys")

        self.assertEqual(base.ec2_md_print(pubkey_ent),
            "0=%s" % self.instance['key_name'])
        self.assertEqual(base.ec2_md_print(pubkey_ent['0']['openssh-key']),
            self.instance['key_data'])
开发者ID:apporc,项目名称:nova,代码行数:8,代码来源:test_metadata.py

示例5: test_pubkey

    def test_pubkey(self):
        md = fake_InstanceMetadata(self.stubs, copy(self.instance))
        data = md.get_ec2_metadata(version='2009-04-04')
        pubkey_ent = data['meta-data']['public-keys']

        self.assertEqual(base.ec2_md_print(pubkey_ent),
            "0=%s" % self.instance['key_name'])
        self.assertEqual(base.ec2_md_print(pubkey_ent['0']['openssh-key']),
            self.instance['key_data'])
开发者ID:jdaymont,项目名称:nova,代码行数:9,代码来源:test_metadata.py

示例6: __call__

    def __call__(self, req):
        remote_address = req.remote_addr

        if req.method == 'PUT' and req.path_info == '/heartbeat':
            try:
                return base.update_vm_stat(req.params, remote_address)
            except exception.FixedIpNotFoundForAddress:
                msg = _('Instance fixed ip not fount with address %s') % \
                        remote_address
                raise webob.exc.HTTPNotFound(explanation=msg)
            except exception.NotFound:
                msg = _('Instance does not need heartbeat')
                raise webob.exc.HTTPNotFound(explanation=msg)
            except exception.NovaException:
                msg = _('Heartbeat store error')
                raise webob.exc.HTTPServerError(explanation=msg)

        if FLAGS.use_forwarded_for:
            remote_address = req.headers.get('X-Forwarded-For', remote_address)

        if os.path.normpath("/" + req.path_info) == "/":
            return(base.ec2_md_print(base.VERSIONS + ["latest"]))

        try:
            meta_data = self.get_metadata(remote_address)
        except Exception:
            LOG.exception(_('Failed to get metadata for ip: %s'),
                          remote_address)
            msg = _('An unknown error has occurred. '
                    'Please try your request again.')
            exc = webob.exc.HTTPInternalServerError(explanation=unicode(msg))
            return exc
        if meta_data is None:
            LOG.error(_('Failed to get metadata for ip: %s'), remote_address)
            raise webob.exc.HTTPNotFound()

        try:
            data = meta_data.lookup(req.path_info)
        except base.InvalidMetadataPath:
            raise webob.exc.HTTPNotFound()

        return base.ec2_md_print(data)
开发者ID:xww,项目名称:nova-old,代码行数:42,代码来源:handler.py

示例7: __call__

    def __call__(self, req):
        if os.path.normpath(req.path_info) == "/":
            resp = base.ec2_md_print(base.VERSIONS + ["latest"])
            req.response.body = encodeutils.to_utf8(resp)
            req.response.content_type = base.MIME_TYPE_TEXT_PLAIN
            return req.response

        # Convert webob.headers.EnvironHeaders to a dict and mask any sensitive
        # details from the logs.
        if CONF.debug:
            headers = {k: req.headers[k] for k in req.headers}
            LOG.debug('Metadata request headers: %s',
                      strutils.mask_dict_password(headers))
        if CONF.neutron.service_metadata_proxy:
            if req.headers.get('X-Metadata-Provider'):
                meta_data = self._handle_instance_id_request_from_lb(req)
            else:
                meta_data = self._handle_instance_id_request(req)
        else:
            if req.headers.get('X-Instance-ID'):
                LOG.warning(
                    "X-Instance-ID present in request headers. The "
                    "'service_metadata_proxy' option must be "
                    "enabled to process this header.")
            meta_data = self._handle_remote_ip_request(req)

        if meta_data is None:
            raise webob.exc.HTTPNotFound()

        try:
            data = meta_data.lookup(req.path_info)
        except base.InvalidMetadataPath:
            raise webob.exc.HTTPNotFound()

        if callable(data):
            return data(req, meta_data)

        resp = base.ec2_md_print(data)
        req.response.body = encodeutils.to_utf8(resp)

        req.response.content_type = meta_data.get_mimetype()
        return req.response
开发者ID:mahak,项目名称:nova,代码行数:42,代码来源:handler.py

示例8: test_pubkey

    def test_pubkey(self):
        md = fake_InstanceMetadata(self.stubs, copy(self.instance))
        pubkey_ent = md.lookup("/2009-04-04/meta-data/public-keys")

        self.assertEqual(base.ec2_md_print(pubkey_ent), "0=%s" % self.instance["key_name"])
        self.assertEqual(base.ec2_md_print(pubkey_ent["0"]["openssh-key"]), self.instance["key_data"])
开发者ID:pramod5480,项目名称:nova,代码行数:6,代码来源:test_metadata.py


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