本文整理汇总了Python中helpers.Helpers.get_onos_fabric_service方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.get_onos_fabric_service方法的具体用法?Python Helpers.get_onos_fabric_service怎么用?Python Helpers.get_onos_fabric_service使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.Helpers
的用法示例。
在下文中一共展示了Helpers.get_onos_fabric_service方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync_record
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import get_onos_fabric_service [as 别名]
def sync_record(self, model):
log.info("Adding switch %s to onos-fabric" % model.name)
# Send device info to onos-fabric netcfg
data = {
"devices": {
model.ofId: {
"basic": {
"name": model.name,
"driver": model.driver
},
"segmentrouting": {
"name": model.name,
"ipv4NodeSid": model.ipv4NodeSid,
"ipv4Loopback": model.ipv4Loopback,
"routerMac": model.routerMac,
"isEdgeRouter": model.isEdgeRouter,
"adjacencySids": []
}
}
}
}
onos = Helpers.get_onos_fabric_service(model_accessor=self.model_accessor)
url = 'http://%s:%s/onos/v1/network/configuration/' % (onos.rest_hostname, onos.rest_port)
r = requests.post(url, json=data, auth=HTTPBasicAuth(onos.rest_username, onos.rest_password))
if r.status_code != 200:
log.error(r.text)
raise Exception("Failed to add device %s into ONOS" % model.name)
else:
try:
log.info("result", json=r.json())
except Exception:
log.info("result", text=r.text)
示例2: delete_netcfg_item
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import get_onos_fabric_service [as 别名]
def delete_netcfg_item(self, partial_url):
onos = Helpers.get_onos_fabric_service(self.model_accessor)
url = 'http://%s:%s/onos/v1/network/configuration/ports/%s' % (onos.rest_hostname, onos.rest_port, partial_url)
r = requests.delete(url, auth=HTTPBasicAuth(onos.rest_username, onos.rest_password))
if r.status_code != 204:
log.error(r.text)
raise Exception("Failed to %s port %s from ONOS" % url)
示例3: delete_record
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import get_onos_fabric_service [as 别名]
def delete_record(self, model):
log.info("Removing switch %s from onos-fabric" % model.name)
onos = Helpers.get_onos_fabric_service(model_accessor=self.model_accessor)
url = 'http://%s:%s/onos/v1/network/configuration/devices/%s' % (
onos.rest_hostname, onos.rest_port, model.ofId)
r = requests.delete(url, auth=HTTPBasicAuth(onos.rest_username, onos.rest_password))
if r.status_code != 204:
log.error(r.text)
raise Exception("Failed to remove switch %s from ONOS" % model.name)
示例4: sync_record
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import get_onos_fabric_service [as 别名]
def sync_record(self, model):
if model.leaf_model_name == "PortInterface":
log.info("Received update for PortInterface", port=model.port.portId, interface=model)
return self.sync_record(model.port)
if model.leaf_model_name == "FabricIpAddress":
log.info("Received update for FabricIpAddress",
port=model.interface.port.portId,
interface=model.interface.name,
ip=model.ip)
return self.sync_record(model.interface.port)
log.info("Adding port %s/%s to onos-fabric" % (model.switch.ofId, model.portId))
interfaces = []
for intf in model.interfaces.all():
i = {
"name": intf.name,
"ips": [i.ip for i in intf.ips.all()]
}
if intf.vlanUntagged:
i["vlan-untagged"] = intf.vlanUntagged
interfaces.append(i)
# Send port config to onos-fabric netcfg
data = {
"ports": {
"%s/%s" % (model.switch.ofId, model.portId): {
"interfaces": interfaces,
"hostLearning": {
"enabled": model.host_learning
}
}
}
}
log.debug("Port %s/%s data" % (model.switch.ofId, model.portId), data=data)
onos = Helpers.get_onos_fabric_service(self.model_accessor)
url = 'http://%s:%s/onos/v1/network/configuration/' % (onos.rest_hostname, onos.rest_port)
r = requests.post(url, json=data, auth=HTTPBasicAuth(onos.rest_username, onos.rest_password))
if r.status_code != 200:
log.error(r.text)
raise Exception("Failed to add port %s/%s into ONOS" % (model.switch.ofId, model.portId))
else:
try:
log.info("Port %s/%s response" % (model.switch.ofId, model.portId), json=r.json())
except Exception:
log.info("Port %s/%s response" % (model.switch.ofId, model.portId), text=r.text)
# Now set the port's administrative state.
# TODO(smbaker): See if netcfg allows us to specify the portstate instead of using a separate REST call
url = 'http://%s:%s/onos/v1/devices/%s/portstate/%s' % (onos.rest_hostname,
onos.rest_port,
model.switch.ofId,
model.portId)
data = {"enabled": True if model.admin_state == "enabled" else False}
log.debug("Sending portstate %s to %s/%s" % (data, model.switch.ofId, model.portId))
r = requests.post(url, json=data, auth=HTTPBasicAuth(onos.rest_username, onos.rest_password))
if r.status_code != 200:
log.error(r.text)
raise Exception("Failed to set portstate %s/%s into ONOS" % (model.switch.ofId, model.portId))
else:
try:
log.info("Portstate %s/%s response" % (model.switch.ofId, model.portId), json=r.json())
except Exception:
log.info("Portstate %s/%s response" % (model.switch.ofId, model.portId), text=r.text)