本文整理汇总了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))
示例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)
示例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)
示例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)
示例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))
示例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))