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


Python Helpers.format_url方法代码示例

本文整理汇总了Python中helpers.Helpers.format_url方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.format_url方法的具体用法?Python Helpers.format_url怎么用?Python Helpers.format_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在helpers.Helpers的用法示例。


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

示例1: delete_record

# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import format_url [as 别名]
    def delete_record(self, o):

        if hasattr(o, 'service'):
            # this is a ServiceAttribute model
            if 'ONOSService' in o.service.leaf_model.class_names:
                print "sync ONOSService Attribute", o.service.leaf_model

                log.info("Deleting config %s" % o.name)
                # getting onos url and auth
                onos_service = o.service.leaf_model
                onos_url = "%s:%s" % (
                    Helpers.format_url(onos_service.rest_hostname), onos_service.rest_port)
                onos_basic_auth = HTTPBasicAuth(onos_service.rest_username,
                                                onos_service.rest_password)

                url = o.name
                if url[0] == "/":
                    # strip initial /
                    url = url[1:]

                url = '%s/%s' % (onos_url, url)
                request = requests.delete(url, auth=onos_basic_auth)

                if request.status_code != 204:
                    log.error("Request failed", response=request.text)
                    raise Exception("Failed to remove config %s from ONOS:  %s" % (url, request.text))
开发者ID:opencord,项目名称:onos-service,代码行数:28,代码来源:sync_onos_service.py

示例2: sync_record

# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import format_url [as 别名]
    def sync_record(self, o):
        if hasattr(o, 'service'):
            # this is a ServiceAttribute model
            if 'ONOSService' in o.service.leaf_model.class_names:
                print "sync ONOSService Attribute", o.service.leaf_model
                return self.sync_record(o.service.leaf_model)
            return  # if it's not related to an ONOSService do nothing

        onos_url = "%s:%s" % (Helpers.format_url(o.rest_hostname), o.rest_port)
        onos_basic_auth = HTTPBasicAuth(o.rest_username, o.rest_password)

        configs = self.get_service_attribute(o)
        for url, value in configs.iteritems():

            if url[0] == "/":
                # strip initial /
                url = url[1:]

            url = '%s/%s' % (onos_url, url)
            value = json.loads(value)
            request = requests.post(url, json=value, auth=onos_basic_auth)

            if request.status_code != 200:
                log.error("Request failed", response=request.text)
                raise Exception("Failed to add config %s in ONOS" % url)
开发者ID:opencord,项目名称:onos-service,代码行数:27,代码来源:sync_onos_service.py

示例3: delete_record

# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import format_url [as 别名]
    def delete_record(self, o):

        if hasattr(o, 'service_instance'):
            # this is a ServiceInstanceAttribute model
            if 'ONOSApp' in o.service_instance.leaf_model.class_names:
                return self.delete_config(o)
            return  # if it's not related to an ONOSApp do nothing

        # NOTE if it is an ONOSApp we don't care about the ServiceInstanceAttribute
        # as the reaper will delete it

        # getting onos url and auth
        onos_url = "%s:%s" % (Helpers.format_url(o.owner.leaf_model.rest_hostname), o.owner.leaf_model.rest_port)
        onos_basic_auth = HTTPBasicAuth(o.owner.leaf_model.rest_username, o.owner.leaf_model.rest_password)

        # deactivate an app (bundled in onos)
        if not o.url or o.url is None:
            self.deactivate_app(o, onos_url, onos_basic_auth)
        # uninstall an app from a remote source, only if it has been activated before
        if o.url and o.url is not None:
            self.uninstall_app(o, onos_url, onos_basic_auth)
开发者ID:opencord,项目名称:onos-service,代码行数:23,代码来源:sync_onos_app.py

示例4: sync_record

# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import format_url [as 别名]
    def sync_record(self, o):
        log.info("Sync'ing", model=o.tologdict())
        if hasattr(o, 'service_instance'):
            # this is a ServiceInstanceAttribute model just push the config
            if 'ONOSApp' in o.service_instance.leaf_model.class_names:
                return self.add_config(o)
            return  # if it's not an ONOSApp do nothing

        if not self.check_app_dependencies(o.dependencies):
            raise DeferredException('Deferring installation of ONOSApp with id %s as dependencies are not met' % o.id)

        # getting onos url and auth
        onos_url = "%s:%s" % (Helpers.format_url(o.owner.leaf_model.rest_hostname), o.owner.leaf_model.rest_port)
        onos_basic_auth = HTTPBasicAuth(o.owner.leaf_model.rest_username, o.owner.leaf_model.rest_password)

        # activate app (bundled in onos)
        if not o.url or o.url is None:
            self.activate_app(o, onos_url, onos_basic_auth)
        # install an app from a remote source
        if o.url and o.url is not None:
            self.install_app(o, onos_url, onos_basic_auth)
开发者ID:opencord,项目名称:onos-service,代码行数:23,代码来源:sync_onos_app.py

示例5: delete_config

# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import format_url [as 别名]
    def delete_config(self, o):
        log.info("Deleting config %s" % o.name)
        # getting onos url and auth
        onos_app = o.service_instance.leaf_model
        onos_url = "%s:%s" % (Helpers.format_url(
            onos_app.owner.leaf_model.rest_hostname),
            onos_app.owner.leaf_model.rest_port)
        onos_basic_auth = HTTPBasicAuth(
            onos_app.owner.leaf_model.rest_username,
            onos_app.owner.leaf_model.rest_password)

        url = o.name
        if url[0] == "/":
            # strip initial /
            url = url[1:]

        url = '%s/%s' % (onos_url, url)
        request = requests.delete(url, auth=onos_basic_auth)

        if request.status_code != 204:
            log.error("Request failed", response=request.text)
            raise Exception("Failed to remove config %s from ONOS:  %s" % (url, request.text))
开发者ID:opencord,项目名称:onos-service,代码行数:24,代码来源:sync_onos_app.py

示例6: add_config

# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import format_url [as 别名]
    def add_config(self, o):
        log.info("Adding config %s" % o.name, model=o.tologdict())
        # getting onos url and auth
        onos_url = "%s:%s" % (Helpers.format_url(
            o.service_instance.leaf_model.owner.leaf_model.rest_hostname),
            o.service_instance.leaf_model.owner.leaf_model.rest_port)
        onos_basic_auth = HTTPBasicAuth(
            o.service_instance.leaf_model.owner.leaf_model.rest_username,
            o.service_instance.leaf_model.owner.leaf_model.rest_password)

        # push configs (if any)
        url = o.name
        if url[0] == "/":
            # strip initial /
            url = url[1:]

        url = '%s/%s' % (onos_url, url)
        value = json.loads(o.value)
        request = requests.post(url, json=value, auth=onos_basic_auth)

        if request.status_code != 200:
            log.error("Request failed", response=request.text)
            raise Exception("Failed to add config %s in ONOS:  %s" % (url, request.text))
开发者ID:opencord,项目名称:onos-service,代码行数:25,代码来源:sync_onos_app.py


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