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

Python common.remove_version_from_href函数代码示例

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

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



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

示例1: show

    def show(self, request, image):
        """Return a dictionary with image details."""
        image_dict = {
            "id": image.get("id"),
            "name": image.get("name"),
            "minRam": int(image.get("min_ram") or 0),
            "minDisk": int(image.get("min_disk") or 0),
            "metadata": image.get("properties", {}),
            "created": self._format_date(image.get("created_at")),
            "updated": self._format_date(image.get("updated_at")),
            "status": self._get_status(image),
            "progress": self._get_progress(image),
            "links": self._get_links(request, image["id"]),
        }

        instance_uuid = image.get("properties", {}).get("instance_uuid")

        if instance_uuid is not None:
            server_ref = os.path.join(request.application_url, 'servers',
                                      instance_uuid)
            image_dict["server"] = {
                "id": instance_uuid,
                "links": [{
                    "rel": "self",
                    "href": server_ref,
                },
                {
                    "rel": "bookmark",
                    "href": common.remove_version_from_href(server_ref),
                }],
            }

        return dict(image=image_dict)
开发者ID:KarimAllah,项目名称:nova,代码行数:33,代码来源:images.py


示例2: _build_server

 def _build_server(self, image, image_obj):
     try:
         serverRef = image_obj["properties"]["instance_ref"]
         image["server"] = {
             "id": common.get_id_from_href(serverRef),
             "links": [
                 {"rel": "self", "href": serverRef},
                 {"rel": "bookmark", "href": common.remove_version_from_href(serverRef)},
             ],
         }
     except KeyError:
         return
开发者ID:nicopal,项目名称:nova,代码行数:12,代码来源:images.py


示例3: _build_server

 def _build_server(self, image, image_obj):
     try:
         serverRef = image_obj['properties']['instance_ref']
         image['server'] = {
             "id": common.get_id_from_href(serverRef),
             "links": [
                 {
                     "rel": "self",
                     "href": serverRef,
                 },
                 {
                     "rel": "bookmark",
                     "href": common.remove_version_from_href(serverRef),
                 },
             ]
         }
     except KeyError:
         return
开发者ID:sateesh-chodapuneedi,项目名称:nova,代码行数:18,代码来源:images.py


示例4: test_remove_version_from_href_4

 def test_remove_version_from_href_4(self):
     fixture = 'http://www.testsite.com/v1.1/images/v10.5'
     expected = 'http://www.testsite.com/images/v10.5'
     actual = common.remove_version_from_href(fixture)
     self.assertEqual(actual, expected)
开发者ID:Charu-Sharma,项目名称:nova,代码行数:5,代码来源:test_common.py


示例5: generate_bookmark

 def generate_bookmark(self, image_id):
     """Create a URL that refers to a specific flavor id."""
     return os.path.join(common.remove_version_from_href(self.base_url),
         self.project_id, "images", str(image_id))
开发者ID:sateesh-chodapuneedi,项目名称:nova,代码行数:4,代码来源:images.py


示例6: generate_bookmark

 def generate_bookmark(self, server_id):
     """Create an url that refers to a specific flavor id."""
     return os.path.join(common.remove_version_from_href(self.base_url),
         "servers", str(server_id))
开发者ID:apowers,项目名称:openstack-nova,代码行数:4,代码来源:servers.py


示例7: test_remove_version_from_href_3

 def test_remove_version_from_href_3(self):
     fixture = "http://www.testsite.com/v10.10"
     expected = "http://www.testsite.com"
     actual = common.remove_version_from_href(fixture)
     self.assertEqual(actual, expected)
开发者ID:rackerlabs,项目名称:reddwarf,代码行数:5,代码来源:test_common.py


示例8: generate_bookmark

 def generate_bookmark(self, flavor_id):
     """Create an url that refers to a specific flavor id."""
     return "%s/flavors/%s" % (
         common.remove_version_from_href(self.base_url),
         flavor_id,
     )
开发者ID:apowers,项目名称:openstack-nova,代码行数:6,代码来源:flavors.py


示例9: test_remove_major_version_from_href

 def test_remove_major_version_from_href(self):
     fixture = "http://www.testsite.com/v1/images"
     expected = "http://www.testsite.com/images"
     actual = common.remove_version_from_href(fixture)
     self.assertEqual(actual, expected)
开发者ID:B-Rich,项目名称:nova-1,代码行数:5,代码来源:test_common.py


示例10: replace_with_links

def replace_with_links(xml_str, tag_dict_list, replace_dict_out):
    """ Replace entity nodes in input xml with entity references.
        tag_dict_list should contain tag dictionaries; each dict should
        contain the following keys:
        tag: element tag name
        tag_replacement : replacement tag in output xml, same as input tag
                          if None.
        tag_key: Key element tag, if entity does not contain any child
                 elements, this would be added as attribute with value as
                 element text.
        tag_attrib: list of child element tags that are used as attributes
                    in the replaced entity reference.
        tag_collection_url: collection url to be used for creation
                    of the link.
        If the child is an element containing only a single text node
        and tag_key is null, it's data is taken as the tag_key.
        :param xml_str: input xml with no default namespace prefixes
        :param tag_dict_list: list of tag dictionaries
        :param replace_dict_out: the xpath of elements replaced are put in the
                out parameter dict
        :returns: output xml containing entity references
        :raises TagDictionaryError: if resource references cannot be
        constructed using the given tag dictionary.
    """

    def _validate_tag_dict(tag_dict):
        if not tag_dict:
            return False
        try:
            tag_dict['tag']
            tag_dict['tag_key']
            tag_dict['tag_replacement']
            tag_dict['tag_attrib']
            tag_dict['tag_collection_url']
        except KeyError:
            return False
        return True

    def _get_tag_dict_values(tag_dict):
        return (tag_dict['tag'], tag_dict['tag_key'],
                tag_dict['tag_replacement'], tag_dict['tag_attrib'],
                tag_dict['tag_collection_url'])

    if not tag_dict_list:
        return xml_str

#    if (not replace_dict_out):
#        replace_dict_out = {}

    tree = etree.parse(StringIO.StringIO(xml_str),
                       etree.XMLParser(remove_blank_text=True))
    root = tree.getroot()
    rootNS = ''
    if not root.prefix and root.nsmap:
        rootNS = root.nsmap[None]
    elif root.nsmap and root.prefix is not None:
        rootNS = root.nsmap[root.prefix]
    ROOTNS = '{%s}' % rootNS
    for tag_dict in tag_dict_list:
        if _validate_tag_dict(tag_dict):
            try:
                (tag, tag_key, tag_replacement, tag_attrib_list,
                 tag_collection_url) = _get_tag_dict_values(tag_dict)
                elements_to_be_replaced = []
                for element in root.iter(ROOTNS + str(tag)):
                    nsmap = {'atom': constants.XMLNS_ATOM}
                    out_dict = {}
                    if not tag_replacement:
                        tag_replacement = tag
                    replace_element = Element(ROOTNS + tag_replacement,
                                              nsmap=nsmap)
                    if tag_attrib_list is not None:
                        for tag in tag_attrib_list:
                            if element.find(tag) is not None:
                                replace_element.attrib[ROOTNS + tag] = \
                                    element.find(tag).text
                                out_dict[tag] = element.find(tag).text
                    resource_key = None
                    if not tag_key or len(element) == 0:
                        resource_key = element.text
                    elif tag_key is not None and element.find(
                            ROOTNS + tag_key) is not None and \
                            element.find(ROOTNS + tag_key).text is not None:

                        resource_key = element.find(ROOTNS
                                                    + tag_key).text
                    if not resource_key:
                        raise TagDictionaryError(
                            'No resource key found from tag dictionary:',
                            tag_dict)
                    if tag_key is not None:
                        replace_element.attrib[ROOTNS + tag_key] = \
                            resource_key
                        out_dict[tag_key] = resource_key

                    href = os.path.join(tag_collection_url,
                                        str(resource_key))
                    bookmark = \
                        os.path.join(
                            common.remove_version_from_href(
#.........这里部分代码省略.........
开发者ID:jessegonzalez,项目名称:healthnmon,代码行数:101,代码来源:util.py



注:本文中的nova.api.openstack.common.remove_version_from_href函数示例由纯净天空整理自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