Reformatting RO
Change-Id: I86e6a102b5bf2e0221b29096bbb132ca656844c5
Signed-off-by: sousaedu <eduardo.sousa@canonical.com>
diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py
index 699655a..963f6cf 100644
--- a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py
+++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/rest_lib.py
@@ -43,7 +43,6 @@
class ContrailHttp(object):
-
def __init__(self, auth_info, logger):
self._logger = logger
# default don't verify client cert
@@ -62,57 +61,87 @@
def get_cmd(self, url, headers):
self._logger.debug("")
resp = self._request("GET", url, headers)
+
return resp.json()
def post_headers_cmd(self, url, headers, post_fields_dict=None):
self._logger.debug("")
+
# obfuscate password before logging dict
- if post_fields_dict.get('auth', {}).get('identity', {}).get('password', {}).get('user', {}).get('password'):
+ if (
+ post_fields_dict.get("auth", {})
+ .get("identity", {})
+ .get("password", {})
+ .get("user", {})
+ .get("password")
+ ):
post_fields_dict_copy = copy.deepcopy(post_fields_dict)
- post_fields_dict['auth']['identity']['password']['user']['password'] = '******'
+ post_fields_dict["auth"]["identity"]["password"]["user"][
+ "password"
+ ] = "******"
json_data_log = post_fields_dict_copy
else:
json_data_log = post_fields_dict
+
self._logger.debug("Request POSTFIELDS: {}".format(json.dumps(json_data_log)))
resp = self._request("POST_HEADERS", url, headers, data=post_fields_dict)
+
return resp.text
def post_cmd(self, url, headers, post_fields_dict=None):
self._logger.debug("")
+
# obfuscate password before logging dict
- if post_fields_dict.get('auth', {}).get('identity', {}).get('password', {}).get('user', {}).get('password'):
+ if (
+ post_fields_dict.get("auth", {})
+ .get("identity", {})
+ .get("password", {})
+ .get("user", {})
+ .get("password")
+ ):
post_fields_dict_copy = copy.deepcopy(post_fields_dict)
- post_fields_dict['auth']['identity']['password']['user']['password'] = '******'
+ post_fields_dict["auth"]["identity"]["password"]["user"][
+ "password"
+ ] = "******"
json_data_log = post_fields_dict_copy
else:
json_data_log = post_fields_dict
+
self._logger.debug("Request POSTFIELDS: {}".format(json.dumps(json_data_log)))
resp = self._request("POST", url, headers, data=post_fields_dict)
+
return resp.text
def delete_cmd(self, url, headers):
self._logger.debug("")
resp = self._request("DELETE", url, headers)
+
return resp.text
def _get_token(self, headers):
if self.auth_url:
- self._logger.debug('Current Token: {}'.format(self.token))
- auth_url = self.auth_url + 'auth/tokens'
+ self._logger.debug("Current Token: {}".format(self.token))
+ auth_url = self.auth_url + "auth/tokens"
+
if self.token is None or self._token_expired():
if not self.auth_url:
self.token = ""
- resp = self._request_noauth(url=auth_url, op="POST", headers=headers,
- data=self.auth_dict)
- self.token = resp.headers.get('x-subject-token')
+
+ resp = self._request_noauth(
+ url=auth_url, op="POST", headers=headers, data=self.auth_dict
+ )
+ self.token = resp.headers.get("x-subject-token")
self.last_token_time = time.time()
- self._logger.debug('Obtained token: {}'.format(self.token))
+ self._logger.debug("Obtained token: {}".format(self.token))
return self.token
def _token_expired(self):
current_time = time.time()
- if self.last_token_time and (current_time - self.last_token_time < self.token_timeout):
+
+ if self.last_token_time and (
+ current_time - self.last_token_time < self.token_timeout
+ ):
return False
else:
return True
@@ -124,14 +153,18 @@
# TODO add again token
# token = self._get_token(headers)
token = None
+
if token:
- headers['X-Auth-Token'] = token
+ headers["X-Auth-Token"] = token
+
try:
return self._request_noauth(op, url, headers, data)
except AuthError:
# If there is an auth error retry just once
if retry_auth_error:
- return self._request(self, op, url, headers, data, retry_auth_error=False)
+ return self._request(
+ self, op, url, headers, data, retry_auth_error=False
+ )
def _request_noauth(self, op, url, headers, data=None):
# Method to execute http requests with error control
@@ -158,6 +191,7 @@
resp = self._http_delete(url, headers, json_data=data)
else:
raise HttpException("Unsupported operation: {}".format(op))
+
self._logger.info("Response HTTPCODE: {}".format(resp.status_code))
# Check http return code
@@ -168,23 +202,42 @@
if status_code == 401:
# Auth Error - set token to None to reload it and raise AuthError
self.token = None
+
raise AuthError("Auth error executing operation")
elif status_code == 409:
- raise DuplicateFound("Duplicate resource url: {}, response: {}".format(url, resp.text))
+ raise DuplicateFound(
+ "Duplicate resource url: {}, response: {}".format(
+ url, resp.text
+ )
+ )
elif status_code == 404:
- raise NotFound("Not found resource url: {}, response: {}".format(url, resp.text))
+ raise NotFound(
+ "Not found resource url: {}, response: {}".format(
+ url, resp.text
+ )
+ )
elif resp.status_code in [502, 503]:
if not self.max_retries or retry >= self.max_retries:
- raise ServiceUnavailableException("Service unavailable error url: {}".format(url))
+ raise ServiceUnavailableException(
+ "Service unavailable error url: {}".format(url)
+ )
continue
else:
- raise HttpException("Error status_code: {}, error_text: {}".format(resp.status_code, resp.text))
+ raise HttpException(
+ "Error status_code: {}, error_text: {}".format(
+ resp.status_code, resp.text
+ )
+ )
except ConnectionError as e:
- self._logger.error("Connection error executing request: {}".format(repr(e)))
+ self._logger.error(
+ "Connection error executing request: {}".format(repr(e))
+ )
+
if not self.max_retries or retry >= self.max_retries:
raise ConnectionError
+
continue
except Exception as e:
self._logger.error("Error executing request: {}".format(repr(e)))
diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py
index 6c2f72b..0494393 100644
--- a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py
+++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_api.py
@@ -20,6 +20,7 @@
from osm_ro_plugin.sdnconn import SdnConnectorError
from osm_rosdn_juniper_contrail.rest_lib import ContrailHttp
from osm_rosdn_juniper_contrail.rest_lib import NotFound
+
# from osm_rosdn_juniper_contrail.rest_lib import DuplicateFound
# from osm_rosdn_juniper_contrail.rest_lib import HttpException
@@ -28,23 +29,25 @@
""" Class with CRUD operations for the underlay API """
def __init__(self, url, config=None, user=None, password=None, logger=None):
-
self.logger = logger or logging.getLogger("ro.sdn.junipercontrail.sdnapi")
self.controller_url = url
if not url:
raise SdnConnectorError("'url' must be provided")
+
if not url.startswith("http"):
url = "http://" + url
+
if not url.endswith("/"):
url = url + "/"
- self.url = url
+ self.url = url
self.auth_url = None
self.project = None
self.domain = None
self.asn = None
self.fabric = None
+
if config:
self.auth_url = config.get("auth_url")
self.project = config.get("project")
@@ -53,32 +56,36 @@
self.fabric = config.get("fabric")
# Init http headers for all requests
- self.http_header = {'Content-Type': 'application/json'}
+ self.http_header = {"Content-Type": "application/json"}
if user:
self.user = user
+
if password:
self.password = password
- self.logger.debug("Config parameters for the underlay controller: auth_url: {}, project: {},"
- " domain: {}, user: {}, password: {}".format(self.auth_url, self.project,
- self.domain, self.user, self.password))
+ self.logger.debug(
+ "Config parameters for the underlay controller: auth_url: {}, project: {},"
+ " domain: {}, user: {}, password: {}".format(
+ self.auth_url, self.project, self.domain, self.user, self.password
+ )
+ )
auth_dict = {}
- auth_dict['auth'] = {}
- auth_dict['auth']['scope'] = {}
- auth_dict['auth']['scope']['project'] = {}
- auth_dict['auth']['scope']['project']['domain'] = {}
- auth_dict['auth']['scope']['project']['domain']["id"] = self.domain
- auth_dict['auth']['scope']['project']['name'] = self.project
- auth_dict['auth']['identity'] = {}
- auth_dict['auth']['identity']['methods'] = ['password']
- auth_dict['auth']['identity']['password'] = {}
- auth_dict['auth']['identity']['password']['user'] = {}
- auth_dict['auth']['identity']['password']['user']['name'] = self.user
- auth_dict['auth']['identity']['password']['user']['password'] = self.password
- auth_dict['auth']['identity']['password']['user']['domain'] = {}
- auth_dict['auth']['identity']['password']['user']['domain']['id'] = self.domain
+ auth_dict["auth"] = {}
+ auth_dict["auth"]["scope"] = {}
+ auth_dict["auth"]["scope"]["project"] = {}
+ auth_dict["auth"]["scope"]["project"]["domain"] = {}
+ auth_dict["auth"]["scope"]["project"]["domain"]["id"] = self.domain
+ auth_dict["auth"]["scope"]["project"]["name"] = self.project
+ auth_dict["auth"]["identity"] = {}
+ auth_dict["auth"]["identity"]["methods"] = ["password"]
+ auth_dict["auth"]["identity"]["password"] = {}
+ auth_dict["auth"]["identity"]["password"]["user"] = {}
+ auth_dict["auth"]["identity"]["password"]["user"]["name"] = self.user
+ auth_dict["auth"]["identity"]["password"]["user"]["password"] = self.password
+ auth_dict["auth"]["identity"]["password"]["user"]["domain"] = {}
+ auth_dict["auth"]["identity"]["password"]["user"]["domain"]["id"] = self.domain
self.auth_dict = auth_dict
# Init http lib
@@ -87,18 +94,21 @@
def check_auth(self):
response = self.http.get_cmd(url=self.auth_url, headers=self.http_header)
+
return response
# Helper methods for CRUD operations
def get_all_by_type(self, controller_url, type):
endpoint = controller_url + type
response = self.http.get_cmd(url=endpoint, headers=self.http_header)
+
return response.get(type)
def get_by_uuid(self, type, uuid):
try:
endpoint = self.controller_url + type + "/{}".format(uuid)
response = self.http.get_cmd(url=endpoint, headers=self.http_header)
+
return response.get(type)
except NotFound:
return None
@@ -113,15 +123,14 @@
Returns: If resource not found returns None
In case of error raises an Exception
"""
- payload = {
- "type": type,
- "fq_name": fq_name
- }
+ payload = {"type": type, "fq_name": fq_name}
+
try:
endpoint = self.controller_url + "fqname-to-id"
- resp = self.http.post_cmd(url=endpoint,
- headers=self.http_header,
- post_fields_dict=payload)
+ resp = self.http.post_cmd(
+ url=endpoint, headers=self.http_header, post_fields_dict=payload
+ )
+
return json.loads(resp).get("uuid")
except NotFound:
return None
@@ -129,6 +138,7 @@
def get_by_fq_name(self, type, fq_name):
# Obtain uuid by fqdn and then get data by uuid
uuid = self.get_uuid_from_fqname(type, fq_name)
+
if uuid:
return self.get_by_uuid(type, uuid)
else:
@@ -140,10 +150,13 @@
"uuid": uuid,
"ref-type": ref_type,
"ref-fq-name": ref_fq_name,
- "operation": "DELETE"
+ "operation": "DELETE",
}
endpoint = self.controller_url + "ref-update"
- resp = self.http.post_cmd(url=endpoint, headers=self.http_header, post_fields_dict=payload)
+ resp = self.http.post_cmd(
+ url=endpoint, headers=self.http_header, post_fields_dict=payload
+ )
+
return resp
# Aux methods to avoid code duplication of name conventions
@@ -157,92 +170,93 @@
def create_virtual_network(self, name, vni):
self.logger.debug("create vname, name: {}, vni: {}".format(name, vni))
- routetarget = '{}:{}'.format(self.asn, vni)
+ routetarget = "{}:{}".format(self.asn, vni)
vnet_dict = {
"virtual-network": {
"virtual_network_properties": {
"vxlan_network_identifier": vni,
},
"parent_type": "project",
- "fq_name": [
- self.domain,
- self.project,
- name
- ],
- "route_target_list": {
- "route_target": [
- "target:" + routetarget
- ]
- }
+ "fq_name": [self.domain, self.project, name],
+ "route_target_list": {"route_target": ["target:" + routetarget]},
}
}
- endpoint = self.controller_url + 'virtual-networks'
- resp = self.http.post_cmd(url=endpoint,
- headers=self.http_header,
- post_fields_dict=vnet_dict)
+ endpoint = self.controller_url + "virtual-networks"
+ resp = self.http.post_cmd(
+ url=endpoint, headers=self.http_header, post_fields_dict=vnet_dict
+ )
+
if not resp:
- raise SdnConnectorError('Error creating virtual network: empty response')
+ raise SdnConnectorError("Error creating virtual network: empty response")
+
vnet_info = json.loads(resp)
self.logger.debug("created vnet, vnet_info: {}".format(vnet_info))
- return vnet_info.get("virtual-network").get('uuid'), vnet_info.get("virtual-network")
+
+ return vnet_info.get("virtual-network").get("uuid"), vnet_info.get(
+ "virtual-network"
+ )
def get_virtual_networks(self):
- return self.get_all_by_type('virtual-networks')
+ return self.get_all_by_type("virtual-networks")
def get_virtual_network(self, network_id):
- return self.get_by_uuid('virtual-network', network_id)
+ return self.get_by_uuid("virtual-network", network_id)
def delete_virtual_network(self, network_id):
self.logger.debug("delete vnet uuid: {}".format(network_id))
- self.delete_by_uuid(self.controller_url, 'virtual-network', network_id)
+ self.delete_by_uuid(self.controller_url, "virtual-network", network_id)
self.logger.debug("deleted vnet uuid: {}".format(network_id))
# Vpg operations
def create_vpg(self, switch_id, switch_port):
- self.logger.debug("create vpg, switch_id: {}, switch_port: {}".format(switch_id, switch_port))
+ self.logger.debug(
+ "create vpg, switch_id: {}, switch_port: {}".format(switch_id, switch_port)
+ )
vpg_name = self.get_vpg_name(switch_id, switch_port)
vpg_dict = {
"virtual-port-group": {
"parent_type": "fabric",
- "fq_name": [
- "default-global-system-config",
- self.fabric,
- vpg_name
- ]
+ "fq_name": ["default-global-system-config", self.fabric, vpg_name],
}
}
- endpoint = self.controller_url + 'virtual-port-groups'
- resp = self.http.post_cmd(url=endpoint,
- headers=self.http_header,
- post_fields_dict=vpg_dict)
+ endpoint = self.controller_url + "virtual-port-groups"
+ resp = self.http.post_cmd(
+ url=endpoint, headers=self.http_header, post_fields_dict=vpg_dict
+ )
+
if not resp:
- raise SdnConnectorError('Error creating virtual port group: empty response')
+ raise SdnConnectorError("Error creating virtual port group: empty response")
+
vpg_info = json.loads(resp)
self.logger.debug("created vpg, vpg_info: {}".format(vpg_info))
- return vpg_info.get("virtual-port-group").get('uuid'), vpg_info.get("virtual-port-group")
+
+ return vpg_info.get("virtual-port-group").get("uuid"), vpg_info.get(
+ "virtual-port-group"
+ )
def get_vpgs(self):
- return self.get_all_by_type(self.controller_url, 'virtual-port-groups')
+ return self.get_all_by_type(self.controller_url, "virtual-port-groups")
def get_vpg(self, vpg_id):
return self.get_by_uuid(self.controller_url, "virtual-port-group", vpg_id)
def get_vpg_by_name(self, vpg_name):
- fq_name = ["default-global-system-config",
- self.fabric,
- vpg_name
- ]
+ fq_name = ["default-global-system-config", self.fabric, vpg_name]
+
return self.get_by_fq_name("virtual-port-group", fq_name)
def delete_vpg(self, vpg_id):
self.logger.debug("delete vpg, uuid: {}".format(vpg_id))
- self.delete_by_uuid(self.controller_url, 'virtual-port-group', vpg_id)
+ self.delete_by_uuid(self.controller_url, "virtual-port-group", vpg_id)
self.logger.debug("deleted vpg, uuid: {}".format(vpg_id))
def create_vmi(self, switch_id, switch_port, network, vlan):
- self.logger.debug("create vmi, switch_id: {}, switch_port: {}, network: {}, vlan: {}".format(
- switch_id, switch_port, network, vlan))
+ self.logger.debug(
+ "create vmi, switch_id: {}, switch_port: {}, network: {}, vlan: {}".format(
+ switch_id, switch_port, network, vlan
+ )
+ )
vmi_name = self.get_vmi_name(switch_id, switch_port, vlan)
vpg_name = self.get_vpg_name(switch_id, switch_port)
profile_dict = {
@@ -251,71 +265,61 @@
"port_id": switch_port.replace(":", "_"),
"switch_id": switch_port.replace(":", "_"),
"switch_info": switch_id,
- "fabric": self.fabric
+ "fabric": self.fabric,
}
]
-
}
vmi_dict = {
"virtual-machine-interface": {
"parent_type": "project",
- "fq_name": [
- self.domain,
- self.project,
- vmi_name
- ],
- "virtual_network_refs": [
- {
- "to": [
- self.domain,
- self.project,
- network
- ]
- }
- ],
+ "fq_name": [self.domain, self.project, vmi_name],
+ "virtual_network_refs": [{"to": [self.domain, self.project, network]}],
"virtual_machine_interface_properties": {
"sub_interface_vlan_tag": vlan
},
"virtual_machine_interface_bindings": {
"key_value_pair": [
- {
- "key": "vnic_type",
- "value": "baremetal"
- },
- {
- "key": "vif_type",
- "value": "vrouter"
- },
- {
- "key": "vpg",
- "value": vpg_name
- },
- {
- "key": "profile",
- "value": json.dumps(profile_dict)
- }
+ {"key": "vnic_type", "value": "baremetal"},
+ {"key": "vif_type", "value": "vrouter"},
+ {"key": "vpg", "value": vpg_name},
+ {"key": "profile", "value": json.dumps(profile_dict)},
]
- }
+ },
}
}
- endpoint = self.controller_url + 'virtual-machine-interfaces'
+ endpoint = self.controller_url + "virtual-machine-interfaces"
self.logger.debug("vmi_dict: {}".format(vmi_dict))
- resp = self.http.post_cmd(url=endpoint,
- headers=self.http_header,
- post_fields_dict=vmi_dict)
+ resp = self.http.post_cmd(
+ url=endpoint,
+ headers=self.http_header,
+ post_fields_dict=vmi_dict,
+ )
+
if not resp:
- raise SdnConnectorError('Error creating vmi: empty response')
+ raise SdnConnectorError("Error creating vmi: empty response")
+
vmi_info = json.loads(resp)
self.logger.debug("created vmi, info: {}".format(vmi_info))
- return vmi_info.get("virtual-machine-interface").get('uuid'), vmi_info.get("virtual-machine-interface")
+
+ return vmi_info.get("virtual-machine-interface").get("uuid"), vmi_info.get(
+ "virtual-machine-interface"
+ )
def get_vmi(self, vmi_uuid):
- return self.get_by_uuid(self.controller_url, 'virtual-machine-interface', vmi_uuid)
+ return self.get_by_uuid(
+ self.controller_url, "virtual-machine-interface", vmi_uuid
+ )
def delete_vmi(self, uuid):
self.logger.debug("delete vmi uuid: {}".format(uuid))
- self.delete_by_uuid(self.controller_url, 'virtual-machine-interface', uuid)
+ self.delete_by_uuid(self.controller_url, "virtual-machine-interface", uuid)
self.logger.debug("deleted vmi: {}".format(uuid))
def unref_vmi_vpg(self, vpg_id, vmi_id, vmi_fq_name):
- self.delete_ref("virtual-port-group", vpg_id, "virtual-machine-interface", vmi_id, vmi_fq_name)
+ self.delete_ref(
+ "virtual-port-group",
+ vpg_id,
+ "virtual-machine-interface",
+ vmi_id,
+ vmi_fq_name,
+ )
diff --git a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py
index a1cc3de..29b187b 100644
--- a/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py
+++ b/RO-SDN-juniper_contrail/osm_rosdn_juniper_contrail/sdn_assist_juniper_contrail.py
@@ -22,6 +22,7 @@
import random
from osm_ro_plugin.sdnconn import SdnConnectorBase, SdnConnectorError
+
# from osm_rosdn_juniper_contrail.rest_lib import ContrailHttp
# from osm_rosdn_juniper_contrail.rest_lib import NotFound
from osm_rosdn_juniper_contrail.rest_lib import DuplicateFound
@@ -39,6 +40,7 @@
tutorial_with_rest.html
- https://github.com/tonyliu0592/contrail-toolbox/blob/master/sriov/sriov
"""
+
_WIM_LOGGER = "ro.sdn.junipercontrail"
def __init__(self, wim, wim_account, config=None, logger=None):
@@ -65,7 +67,9 @@
:param logger (logging.Logger): optional logger object. If none is passed 'ro.sdn.sdnconn' is used.
"""
self.logger = logger or logging.getLogger(self._WIM_LOGGER)
- self.logger.debug('wim: {}, wim_account: {}, config: {}'.format(wim, wim_account, config))
+ self.logger.debug(
+ "wim: {}, wim_account: {}, config: {}".format(wim, wim_account, config)
+ )
super().__init__(wim, wim_account, config, logger)
self.user = wim_account.get("user")
@@ -79,6 +83,7 @@
self.fabric = None
overlay_url = None
self.vni_range = None
+
if config:
auth_url = config.get("auth_url")
self.project = config.get("project")
@@ -90,41 +95,56 @@
if not url:
raise SdnConnectorError("'url' must be provided")
+
if not url.startswith("http"):
url = "http://" + url
+
if not url.endswith("/"):
url = url + "/"
+
self.url = url
if not self.vni_range:
- self.vni_range = ['1000001-2000000']
+ self.vni_range = ["1000001-2000000"]
self.logger.info("No vni_range was provided. Using ['1000001-2000000']")
+
self.used_vni = set()
if auth_url:
if not auth_url.startswith("http"):
auth_url = "http://" + auth_url
+
if not auth_url.endswith("/"):
auth_url = auth_url + "/"
+
self.auth_url = auth_url
if overlay_url:
if not overlay_url.startswith("http"):
overlay_url = "http://" + overlay_url
+
if not overlay_url.endswith("/"):
overlay_url = overlay_url + "/"
+
self.overlay_url = overlay_url
if not self.project:
raise SdnConnectorError("'project' must be provided")
+
if not self.asn:
# TODO: Get ASN from controller config; otherwise raise ERROR for the moment
- raise SdnConnectorError("'asn' was not provided and it was not possible to obtain it")
+ raise SdnConnectorError(
+ "'asn' was not provided and it was not possible to obtain it"
+ )
+
if not self.fabric:
# TODO: Get FABRIC from controller config; otherwise raise ERROR for the moment
- raise SdnConnectorError("'fabric' was not provided and was not possible to obtain it")
+ raise SdnConnectorError(
+ "'fabric' was not provided and was not possible to obtain it"
+ )
+
if not self.domain:
- self.domain = 'default-domain'
+ self.domain = "default-domain"
self.logger.info("No domain was provided. Using 'default-domain'")
underlay_api_config = {
@@ -132,16 +152,22 @@
"project": self.project,
"domain": self.domain,
"asn": self.asn,
- "fabric": self.fabric
+ "fabric": self.fabric,
}
- self.underlay_api = UnderlayApi(url, underlay_api_config, user=self.user, password=self.password, logger=logger)
+ self.underlay_api = UnderlayApi(
+ url,
+ underlay_api_config,
+ user=self.user,
+ password=self.password,
+ logger=logger,
+ )
self._max_duplicate_retry = 2
self.logger.info("Juniper Contrail Connector Initialized.")
def _generate_vni(self):
"""
- Method to get unused VxLAN Network Identifier (VNI)
+ Method to get unused VxLAN Network Identifier (VNI)
Args:
None
Returns:
@@ -151,15 +177,21 @@
for vlanID_range in self.vni_range:
try:
start_vni, end_vni = map(int, vlanID_range.replace(" ", "").split("-"))
+
for i in range(start_vni, end_vni + 1):
vni = random.randrange(start_vni, end_vni, 1)
+
if vni not in self.used_vni:
return vni
except Exception as exp:
- raise SdnConnectorError("Exception {} occurred while searching a free VNI.".format(exp))
+ raise SdnConnectorError(
+ "Exception {} occurred while searching a free VNI.".format(exp)
+ )
else:
- raise SdnConnectorError("Unable to create the virtual network."
- " All VNI in VNI range {} are in use.".format(self.vni_range))
+ raise SdnConnectorError(
+ "Unable to create the virtual network."
+ " All VNI in VNI range {} are in use.".format(self.vni_range)
+ )
# Aux functions for testing
def get_url(self):
@@ -174,12 +206,16 @@
2 - It the virtual port group does not exist, create it
3 - Create virtual machine interface for the indicated network and vlan
"""
- self.logger.debug("create_port: switch_id: {}, switch_port: {}, network: {}, vlan: {}".format(
- switch_id, switch_port, network, vlan))
+ self.logger.debug(
+ "create_port: switch_id: {}, switch_port: {}, network: {}, vlan: {}".format(
+ switch_id, switch_port, network, vlan
+ )
+ )
# 1 - Check if the vpg exists
vpg_name = self.underlay_api.get_vpg_name(switch_id, switch_port)
vpg = self.underlay_api.get_vpg_by_name(vpg_name)
+
if not vpg:
# 2 - If it does not exist create it
vpg_id, _ = self.underlay_api.create_vpg(switch_id, switch_port)
@@ -194,7 +230,11 @@
return vpg_id, vmi_id
def _delete_port(self, switch_id, switch_port, vlan):
- self.logger.debug("delete port, switch_id: {}, switch_port: {}, vlan: {}".format(switch_id, switch_port, vlan))
+ self.logger.debug(
+ "delete port, switch_id: {}, switch_port: {}, vlan: {}".format(
+ switch_id, switch_port, vlan
+ )
+ )
vpg_name = self.underlay_api.get_vpg_name(switch_id, switch_port)
vmi_name = self.underlay_api.get_vmi_name(switch_id, switch_port, vlan)
@@ -202,22 +242,30 @@
# 1 - Obtain vpg by id (if not vpg_id must have been error creating ig, nothing to be done)
vpg_fqdn = ["default-global-system-config", self.fabric, vpg_name]
vpg = self.underlay_api.get_by_fq_name("virtual-port-group", vpg_fqdn)
+
if not vpg:
self.logger.warning("vpg: {} to be deleted not found".format(vpg_name))
else:
# 2 - Get vmi interfaces from vpg
vmi_list = vpg.get("virtual_machine_interface_refs")
+
if not vmi_list:
# must have been an error during port creation when vmi is created
# may happen if there has been an error during creation
- self.logger.warning("vpg: {} has not vmi, will delete nothing".format(vpg))
+ self.logger.warning(
+ "vpg: {} has not vmi, will delete nothing".format(vpg)
+ )
else:
num_vmis = len(vmi_list)
+
for vmi in vmi_list:
fqdn = vmi.get("to")
# check by name
+
if fqdn[2] == vmi_name:
- self.underlay_api.unref_vmi_vpg(vpg.get("uuid"), vmi.get("uuid"), fqdn)
+ self.underlay_api.unref_vmi_vpg(
+ vpg.get("uuid"), vmi.get("uuid"), fqdn
+ )
self.underlay_api.delete_vmi(vmi.get("uuid"))
num_vmis = num_vmis - 1
@@ -234,13 +282,15 @@
external URLs, etc are detected.
"""
self.logger.debug("")
+
try:
resp = self.underlay_api.check_auth()
if not resp:
- raise SdnConnectorError('Empty response')
+ raise SdnConnectorError("Empty response")
except Exception as e:
- self.logger.error('Error checking credentials')
- raise SdnConnectorError('Error checking credentials: {}'.format(str(e)))
+ self.logger.error("Error checking credentials")
+
+ raise SdnConnectorError("Error checking credentials: {}".format(str(e)))
def get_connectivity_service_status(self, service_uuid, conn_info=None):
"""Monitor the status of the connectivity service established
@@ -280,28 +330,36 @@
new information available for the connectivity service.
"""
self.logger.debug("")
+
try:
resp = self.underlay_api.get_virtual_network(service_uuid)
if not resp:
- raise SdnConnectorError('Empty response')
+ raise SdnConnectorError("Empty response")
+
if resp:
vnet_info = resp
# Check if conn_info reports error
if conn_info.get("sdn_status") == "ERROR":
- return {'sdn_status': 'ERROR', 'sdn_info': conn_info}
+ return {"sdn_status": "ERROR", "sdn_info": conn_info}
else:
- return {'sdn_status': 'ACTIVE', 'sdn_info': vnet_info}
+ return {"sdn_status": "ACTIVE", "sdn_info": vnet_info}
else:
- return {'sdn_status': 'ERROR', 'sdn_info': 'not found'}
+ return {"sdn_status": "ERROR", "sdn_info": "not found"}
except SdnConnectorError:
raise
except HttpException as e:
self.logger.error("Error getting connectivity service: {}".format(e))
- raise SdnConnectorError("Exception deleting connectivity service: {}".format(str(e)))
+
+ raise SdnConnectorError(
+ "Exception deleting connectivity service: {}".format(str(e))
+ )
except Exception as e:
- self.logger.error('Exception getting connectivity service info: %s', e, exc_info=True)
- return {'sdn_status': 'ERROR', 'error_msg': str(e)}
+ self.logger.error(
+ "Exception getting connectivity service info: %s", e, exc_info=True
+ )
+
+ return {"sdn_status": "ERROR", "error_msg": str(e)}
def create_connectivity_service(self, service_type, connection_points, **kwargs):
"""
@@ -357,10 +415,16 @@
# name = 'osm-plugin-' + overlay_name
# Else:
# name = 'osm-plugin-' + VNI
- self.logger.info("create_connectivity_service, service_type: {}, connection_points: {}".
- format(service_type, connection_points))
- if service_type.lower() != 'elan':
- raise SdnConnectorError('Only ELAN network type is supported by Juniper Contrail.')
+ self.logger.info(
+ "create_connectivity_service, service_type: {}, connection_points: {}".format(
+ service_type, connection_points
+ )
+ )
+
+ if service_type.lower() != "elan":
+ raise SdnConnectorError(
+ "Only ELAN network type is supported by Juniper Contrail."
+ )
try:
# Initialize data
@@ -370,26 +434,37 @@
# This data will be returned even if no cp can be created if something is created
work_cps = {}
for cp in connection_points:
- switch_id = cp.get("service_endpoint_encapsulation_info").get("switch_dpid")
- switch_port = cp.get("service_endpoint_encapsulation_info").get("switch_port")
+ switch_id = cp.get("service_endpoint_encapsulation_info").get(
+ "switch_dpid"
+ )
+ switch_port = cp.get("service_endpoint_encapsulation_info").get(
+ "switch_port"
+ )
service_endpoint_id = cp.get("service_endpoint_id")
cp_name = self.underlay_api.get_vpg_name(switch_id, switch_port)
add_cp = work_cps.get(cp_name)
+
if not add_cp:
# check cp has vlan
vlan = cp.get("service_endpoint_encapsulation_info").get("vlan")
+
if vlan:
# add cp to dict
service_endpoint_ids = []
service_endpoint_ids.append(service_endpoint_id)
- add_cp = {"service_endpoint_ids": service_endpoint_ids,
- "switch_dpid": switch_id,
- "switch_port": switch_port,
- "vlan": vlan}
+ add_cp = {
+ "service_endpoint_ids": service_endpoint_ids,
+ "switch_dpid": switch_id,
+ "switch_port": switch_port,
+ "vlan": vlan,
+ }
work_cps[cp_name] = add_cp
else:
- self.logger.warning("cp service_endpoint_id : {} has no vlan, ignore".format(
- service_endpoint_id))
+ self.logger.warning(
+ "cp service_endpoint_id : {} has no vlan, ignore".format(
+ service_endpoint_id
+ )
+ )
else:
# add service_endpoint_id to list
service_endpoint_ids = add_cp["service_endpoint_ids"]
@@ -403,26 +478,32 @@
retry = 0
while retry < self._max_duplicate_retry:
try:
- vnet_name = 'osm-plugin-' + str(vni)
- vnet_id, _ = self.underlay_api.create_virtual_network(vnet_name, vni)
+ vnet_name = "osm-plugin-" + str(vni)
+ vnet_id, _ = self.underlay_api.create_virtual_network(
+ vnet_name, vni
+ )
self.used_vni.add(vni)
break
except DuplicateFound as e:
- self.logger.debug("Duplicate error for vnet_name: {}".format(vnet_name))
+ self.logger.debug(
+ "Duplicate error for vnet_name: {}".format(vnet_name)
+ )
self.used_vni.add(vni)
retry += 1
+
if retry >= self._max_duplicate_retry:
raise e
else:
# Try to obtain a new vni
vni = self._generate_vni()
continue
+
conn_info = {
"vnet": {
"uuid": vnet_id,
- "name": vnet_name
+ "name": vnet_name,
},
- "connection_points": work_cps # dict with port_name as key
+ "connection_points": work_cps, # dict with port_name as key
}
# 4 - Create a port for each endpoint
@@ -430,23 +511,33 @@
switch_id = cp.get("switch_dpid")
switch_port = cp.get("switch_port")
vlan = cp.get("vlan")
- vpg_id, vmi_id = self._create_port(switch_id, switch_port, vnet_name, vlan)
+ vpg_id, vmi_id = self._create_port(
+ switch_id, switch_port, vnet_name, vlan
+ )
cp["vpg_id"] = vpg_id
cp["vmi_id"] = vmi_id
- self.logger.info("created connectivity service, uuid: {}, name: {}".format(vnet_id, vnet_name))
- return vnet_id, conn_info
+ self.logger.info(
+ "created connectivity service, uuid: {}, name: {}".format(
+ vnet_id, vnet_name
+ )
+ )
+ return vnet_id, conn_info
except Exception as e:
# Log error
if isinstance(e, SdnConnectorError) or isinstance(e, HttpException):
self.logger.error("Error creating connectivity service: {}".format(e))
else:
- self.logger.error("Error creating connectivity service: {}".format(e), exc_info=True)
+ self.logger.error(
+ "Error creating connectivity service: {}".format(e), exc_info=True
+ )
# If nothing is created raise error else return what has been created and mask as error
if not conn_info:
- raise SdnConnectorError("Exception create connectivity service: {}".format(str(e)))
+ raise SdnConnectorError(
+ "Exception create connectivity service: {}".format(str(e))
+ )
else:
conn_info["sdn_status"] = "ERROR"
conn_info["sdn_info"] = repr(e)
@@ -454,6 +545,7 @@
for cp in work_cps.values():
if not cp.get("vmi_id") or not cp.get("vpg_id"):
cp["sdn_status"] = "ERROR"
+
return vnet_id, conn_info
def delete_connectivity_service(self, service_uuid, conn_info=None):
@@ -466,34 +558,54 @@
:return: None
:raises: SdnConnectorException: In case of error. The parameter http_code must be filled
"""
- self.logger.info("delete_connectivity_service vnet_name: {}, connection_points: {}".
- format(service_uuid, conn_info))
+ self.logger.info(
+ "delete_connectivity_service vnet_name: {}, connection_points: {}".format(
+ service_uuid, conn_info
+ )
+ )
try:
vnet_uuid = service_uuid
- # vnet_name = conn_info["vnet"]["name"] # always should exist as the network is the first thing created
+ # vnet_name = conn_info["vnet"]["name"]
+ # always should exist as the network is the first thing created
work_cps = conn_info["connection_points"]
# 1: For each connection point delete vlan from vpg and it is is the
# last one, delete vpg
for cp in work_cps.values():
- self._delete_port(cp.get("switch_dpid"), cp.get("switch_port"), cp.get("vlan"))
+ self._delete_port(
+ cp.get("switch_dpid"), cp.get("switch_port"), cp.get("vlan")
+ )
# 2: Delete vnet
self.underlay_api.delete_virtual_network(vnet_uuid)
- self.logger.info("deleted connectivity_service vnet_uuid: {}, connection_points: {}".
- format(service_uuid, conn_info))
+ self.logger.info(
+ "deleted connectivity_service vnet_uuid: {}, connection_points: {}".format(
+ service_uuid, conn_info
+ )
+ )
except SdnConnectorError:
raise
except HttpException as e:
self.logger.error("Error deleting connectivity service: {}".format(e))
- raise SdnConnectorError("Exception deleting connectivity service: {}".format(str(e)))
- except Exception as e:
- self.logger.error("Error deleting connectivity service: {}".format(e), exc_info=True)
- raise SdnConnectorError("Exception deleting connectivity service: {}".format(str(e)))
- def edit_connectivity_service(self, service_uuid, conn_info=None, connection_points=None, **kwargs):
- """ Change an existing connectivity service.
+ raise SdnConnectorError(
+ "Exception deleting connectivity service: {}".format(str(e))
+ )
+ except Exception as e:
+ self.logger.error(
+ "Error deleting connectivity service: {}".format(e),
+ exc_info=True,
+ )
+
+ raise SdnConnectorError(
+ "Exception deleting connectivity service: {}".format(str(e))
+ )
+
+ def edit_connectivity_service(
+ self, service_uuid, conn_info=None, connection_points=None, **kwargs
+ ):
+ """Change an existing connectivity service.
This method's arguments and return value follow the same convention as
:meth:`~.create_connectivity_service`.
@@ -517,8 +629,10 @@
# 2 - Obtain network: Check vnet exists and obtain name
# 3 - Delete unnecesary ports
# 4 - Add new ports
- self.logger.info("edit connectivity service, service_uuid: {}, conn_info: {}, "
- "connection points: {} ".format(service_uuid, conn_info, connection_points))
+ self.logger.info(
+ "edit connectivity service, service_uuid: {}, conn_info: {}, "
+ "connection points: {} ".format(service_uuid, conn_info, connection_points)
+ )
# conn_info should always exist and have connection_points and vnet elements
old_cp = conn_info.get("connection_points", {})
@@ -534,7 +648,9 @@
switch_port = cp.get("switch_port")
old_vlan = cp.get("vlan")
self._delete_port(switch_id, switch_port, old_vlan)
- deleted_ports.append(self.underlay_api.get_vpg_name(switch_id, switch_port))
+ deleted_ports.append(
+ self.underlay_api.get_vpg_name(switch_id, switch_port)
+ )
for port in deleted_ports:
del old_cp[port]
@@ -543,41 +659,63 @@
if conn_info.get("vnet", {}).get("sdn_status"):
del conn_info["vnet"]["sdn_status"]
except HttpException as e:
- self.logger.error("Error trying to delete old ports marked as error: {}".format(e))
+ self.logger.error(
+ "Error trying to delete old ports marked as error: {}".format(e)
+ )
+
raise SdnConnectorError(e)
except SdnConnectorError as e:
- self.logger.error("Error trying to delete old ports marked as error: {}".format(e))
+ self.logger.error(
+ "Error trying to delete old ports marked as error: {}".format(e)
+ )
+
raise
except Exception as e:
- self.logger.error("Error trying to delete old ports marked as error: {}".format(e), exc_info=True)
- raise SdnConnectorError("Error trying to delete old ports marked as error: {}".format(e))
+ self.logger.error(
+ "Error trying to delete old ports marked as error: {}".format(e),
+ exc_info=True,
+ )
+
+ raise SdnConnectorError(
+ "Error trying to delete old ports marked as error: {}".format(e)
+ )
if connection_points:
-
# Check and obtain what should be added and deleted, if there is an error here raise an exception
try:
work_cps = {}
for cp in connection_points:
- switch_id = cp.get("service_endpoint_encapsulation_info").get("switch_dpid")
- switch_port = cp.get("service_endpoint_encapsulation_info").get("switch_port")
+ switch_id = cp.get("service_endpoint_encapsulation_info").get(
+ "switch_dpid"
+ )
+ switch_port = cp.get("service_endpoint_encapsulation_info").get(
+ "switch_port"
+ )
service_endpoint_id = cp.get("service_endpoint_id")
cp_name = self.underlay_api.get_vpg_name(switch_id, switch_port)
add_cp = work_cps.get(cp_name)
+
if not add_cp:
# add cp to dict
# check cp has vlan
vlan = cp.get("service_endpoint_encapsulation_info").get("vlan")
+
if vlan:
service_endpoint_ids = []
service_endpoint_ids.append(service_endpoint_id)
- add_cp = {"service_endpoint_ids": service_endpoint_ids,
- "switch_dpid": switch_id,
- "switch_port": switch_port,
- "vlan": vlan}
+ add_cp = {
+ "service_endpoint_ids": service_endpoint_ids,
+ "switch_dpid": switch_id,
+ "switch_port": switch_port,
+ "vlan": vlan,
+ }
work_cps[cp_name] = add_cp
else:
- self.logger.warning("cp service_endpoint_id : {} has no vlan, ignore".
- format(service_endpoint_id))
+ self.logger.warning(
+ "cp service_endpoint_id : {} has no vlan, ignore".format(
+ service_endpoint_id
+ )
+ )
else:
# add service_endpoint_id to list
service_endpoint_ids = add_cp["service_endpoint_ids"]
@@ -595,13 +733,19 @@
if vnet:
vnet_name = vnet["name"]
else:
- raise SdnConnectorError("vnet uuid: {} not found".format(service_uuid))
-
+ raise SdnConnectorError(
+ "vnet uuid: {} not found".format(service_uuid)
+ )
except SdnConnectorError:
raise
except Exception as e:
- self.logger.error("Error edit connectivity service: {}".format(e), exc_info=True)
- raise SdnConnectorError("Exception edit connectivity service: {}".format(str(e)))
+ self.logger.error(
+ "Error edit connectivity service: {}".format(e), exc_info=True
+ )
+
+ raise SdnConnectorError(
+ "Exception edit connectivity service: {}".format(str(e))
+ )
# Delete unneeded ports and add new ones: if there is an error return conn_info
try:
@@ -616,7 +760,11 @@
cp = conn_info_cp[port_name]
switch_id = cp.get("switch_dpid")
switch_port = cp.get("switch_port")
- self.logger.debug("delete port switch_id={}, switch_port={}".format(switch_id, switch_port))
+ self.logger.debug(
+ "delete port switch_id={}, switch_port={}".format(
+ switch_id, switch_port
+ )
+ )
self._delete_port(switch_id, switch_port, vlan)
deleted_ports.append(port_name)
@@ -630,14 +778,23 @@
switch_id = cp.get("switch_dpid")
switch_port = cp.get("switch_port")
vlan = cp.get("vlan")
- self.logger.debug("add port switch_id={}, switch_port={}".format(switch_id, switch_port))
- vpg_id, vmi_id = self._create_port(switch_id, switch_port, vnet_name, vlan)
+ self.logger.debug(
+ "add port switch_id={}, switch_port={}".format(
+ switch_id, switch_port
+ )
+ )
+ vpg_id, vmi_id = self._create_port(
+ switch_id, switch_port, vnet_name, vlan
+ )
cp_added = cp.copy()
cp_added["vpg_id"] = vpg_id
cp_added["vmi_id"] = vmi_id
conn_info_cp[port_name] = cp_added
+
# replace endpoints in case they have changed
- conn_info_cp[port_name]["service_endpoint_ids"] = cp["service_endpoint_ids"]
+ conn_info_cp[port_name]["service_endpoint_ids"] = cp[
+ "service_endpoint_ids"
+ ]
conn_info["connection_points"] = conn_info_cp
return conn_info
@@ -645,7 +802,9 @@
except Exception as e:
# Log error
if isinstance(e, SdnConnectorError) or isinstance(e, HttpException):
- self.logger.error("Error edit connectivity service: {}".format(e), exc_info=True)
+ self.logger.error(
+ "Error edit connectivity service: {}".format(e), exc_info=True
+ )
else:
self.logger.error("Error edit connectivity service: {}".format(e))
@@ -657,60 +816,71 @@
for port_name, cp in work_cps.items():
curr_cp = conn_info_cp.get(port_name)
+
if not curr_cp:
cp_error = work_cps.get(port_name).copy()
cp_error["sdn_status"] = "ERROR"
conn_info_cp[port_name] = cp_error
- conn_info_cp[port_name]["service_endpoint_ids"] = cp["service_endpoint_ids"]
+
+ conn_info_cp[port_name]["service_endpoint_ids"] = cp[
+ "service_endpoint_ids"
+ ]
conn_info["sdn_status"] = "ERROR"
conn_info["sdn_info"] = repr(e)
conn_info["connection_points"] = conn_info_cp
- return conn_info
+ return conn_info
else:
# Connection points have not changed, so do nothing
self.logger.info("no new connection_points provided, nothing to be done")
+
return
-if __name__ == '__main__':
+if __name__ == "__main__":
# Init logger
log_format = "%(asctime)s %(levelname)s %(name)s %(filename)s:%(lineno)s %(funcName)s(): %(message)s"
- log_formatter = logging.Formatter(log_format, datefmt='%Y-%m-%dT%H:%M:%S')
+ log_formatter = logging.Formatter(log_format, datefmt="%Y-%m-%dT%H:%M:%S")
handler = logging.StreamHandler()
handler.setFormatter(log_formatter)
- logger = logging.getLogger('ro.sdn.junipercontrail')
+ logger = logging.getLogger("ro.sdn.junipercontrail")
# logger.setLevel(level=logging.ERROR)
# logger.setLevel(level=logging.INFO)
logger.setLevel(level=logging.DEBUG)
logger.addHandler(handler)
# Read config
- with open('test.yaml') as f:
+ with open("test.yaml") as f:
config = yaml.safe_load(f.read())
- wim = {'wim_url': config.pop('wim_url')}
- wim_account = {'user': config.pop('user'), 'password': config.pop('password')}
- logger.info('wim: {}, wim_account: {}, config: {}'.format(wim, wim_account, config))
+
+ wim = {"wim_url": config.pop("wim_url")}
+ wim_account = {"user": config.pop("user"), "password": config.pop("password")}
+ logger.info("wim: {}, wim_account: {}, config: {}".format(wim, wim_account, config))
# Init controller
- juniper_contrail = JuniperContrail(wim=wim, wim_account=wim_account, config=config, logger=logger)
+ juniper_contrail = JuniperContrail(
+ wim=wim, wim_account=wim_account, config=config, logger=logger
+ )
# Tests
# Generate VNI
for i in range(5):
vni = juniper_contrail._generate_vni()
juniper_contrail.used_vni.add(vni)
+
print(juniper_contrail.used_vni)
# juniper_contrail.used_vni.remove(1000003)
print(juniper_contrail.used_vni)
+
for i in range(2):
vni = juniper_contrail._generate_vni()
juniper_contrail.used_vni.add(vni)
+
print(juniper_contrail.used_vni)
# 0. Check credentials
- print('0. Check credentials')
+ print("0. Check credentials")
# juniper_contrail.check_credentials()
# 1 - Create and delete connectivity service
@@ -720,8 +890,8 @@
"service_endpoint_encapsulation_info": {
"switch_dpid": "LEAF-1",
"switch_port": "xe-0/0/17",
- "vlan": "501"
- }
+ "vlan": "501",
+ },
}
conn_point_1 = {
"service_endpoint_id": "0000:81:10.3",
@@ -729,8 +899,8 @@
"service_endpoint_encapsulation_info": {
"switch_dpid": "LEAF-2",
"switch_port": "xe-0/0/16",
- "vlan": "501"
- }
+ "vlan": "501",
+ },
}
conn_point_2 = {
"service_endpoint_id": "0000:08:11.7",
@@ -738,8 +908,8 @@
"service_endpoint_encapsulation_info": {
"switch_dpid": "LEAF-2",
"switch_port": "xe-0/0/16",
- "vlan": "502"
- }
+ "vlan": "502",
+ },
}
conn_point_3 = {
"service_endpoint_id": "0000:83:10.4",
@@ -747,15 +917,17 @@
"service_endpoint_encapsulation_info": {
"switch_dpid": "LEAF-1",
"switch_port": "xe-0/0/17",
- "vlan": "502"
- }
+ "vlan": "502",
+ },
}
# 1 - Define connection points
logger.debug("create first connection service")
print("Create connectivity service")
connection_points = [conn_point_0, conn_point_1]
- service_id, conn_info = juniper_contrail.create_connectivity_service("ELAN", connection_points)
+ service_id, conn_info = juniper_contrail.create_connectivity_service(
+ "ELAN", connection_points
+ )
logger.info("Created connectivity service 1")
logger.info(service_id)
logger.info(yaml.safe_dump(conn_info, indent=4, default_flow_style=False))
@@ -763,7 +935,9 @@
logger.debug("create second connection service")
print("Create connectivity service")
connection_points = [conn_point_2, conn_point_3]
- service_id2, conn_info2 = juniper_contrail.create_connectivity_service("ELAN", connection_points)
+ service_id2, conn_info2 = juniper_contrail.create_connectivity_service(
+ "ELAN", connection_points
+ )
logger.info("Created connectivity service 2")
logger.info(service_id2)
logger.info(yaml.safe_dump(conn_info2, indent=4, default_flow_style=False))
diff --git a/RO-SDN-juniper_contrail/setup.py b/RO-SDN-juniper_contrail/setup.py
index fef5905..4f158e5 100644
--- a/RO-SDN-juniper_contrail/setup.py
+++ b/RO-SDN-juniper_contrail/setup.py
@@ -30,27 +30,31 @@
setup(
name=_name,
- description='OSM RO SDN plugin for Juniper Contrail',
+ description="OSM RO SDN plugin for Juniper Contrail",
long_description=README,
- version_command=('git describe --match v* --tags --long --dirty', 'pep440-git-full'),
+ version_command=(
+ "git describe --match v* --tags --long --dirty",
+ "pep440-git-full",
+ ),
# version=VERSION,
# python_requires='>3.5.0',
- author='ETSI OSM',
- author_email='OSM_TECH@list.etsi.org',
- maintainer='ETSI OSM',
- maintainer_email='OSM_TECH@list.etsi.org',
- url='https://osm.etsi.org/gitweb/?p=osm/RO.git;a=summary',
- license='Apache 2.0',
-
+ author="ETSI OSM",
+ author_email="OSM_TECH@list.etsi.org",
+ maintainer="ETSI OSM",
+ maintainer_email="OSM_TECH@list.etsi.org",
+ url="https://osm.etsi.org/gitweb/?p=osm/RO.git;a=summary",
+ license="Apache 2.0",
packages=[_name],
include_package_data=True,
- #dependency_links=["git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro"],
+ # dependency_links=["git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro"],
install_requires=[
"requests",
- "osm-ro-plugin @ git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro-plugin&subdirectory=RO-plugin"
+ "osm-ro-plugin @ git+https://osm.etsi.org/gerrit/osm/RO.git#egg=osm-ro-plugin&subdirectory=RO-plugin",
],
- setup_requires=['setuptools-version-command'],
+ setup_requires=["setuptools-version-command"],
entry_points={
- 'osm_rosdn.plugins': ['rosdn_juniper_contrail = osm_rosdn_juniper_contrail.sdn_assist_juniper_contrail:JuniperContrail'],
+ "osm_rosdn.plugins": [
+ "rosdn_juniper_contrail = osm_rosdn_juniper_contrail.sdn_assist_juniper_contrail:JuniperContrail"
+ ],
},
)
diff --git a/RO-SDN-juniper_contrail/tox.ini b/RO-SDN-juniper_contrail/tox.ini
index 4ecb427..32a1610 100644
--- a/RO-SDN-juniper_contrail/tox.ini
+++ b/RO-SDN-juniper_contrail/tox.ini
@@ -27,7 +27,7 @@
basepython = python3
deps = flake8
commands = flake8 osm_rosdn_juniper_contrail --max-line-length 120 \
- --exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp --ignore W291,W293,E226,W504
+ --exclude .svn,CVS,.gz,.git,__pycache__,.tox,local,temp --ignore W291,W293,W503,W605,E123,E125,E203,E226,E241
[testenv:unittest]
basepython = python3