X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=RO-SDN-juniper_contrail%2Fosm_rosdn_juniper_contrail%2Fsdn_api.py;h=6c2f72b0eab4d8d69828e4f63b3549ad8c3ae783;hb=e493e9b91720e5116e00b4c06cf66c767bccce2f;hp=1c5b5285e2fcbc17581db02fcac333ffd88de3bf;hpb=a5c26d8be1a5896675f7eb07c6afeb1aa26c7172;p=osm%2FRO.git 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 1c5b5285..6c2f72b0 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 @@ -17,18 +17,19 @@ import logging import json -from osm_ro.wim.sdnconn import SdnConnectorError +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 +# from osm_rosdn_juniper_contrail.rest_lib import DuplicateFound +# from osm_rosdn_juniper_contrail.rest_lib import HttpException + class UnderlayApi: """ 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("openmano.sdnconn.junipercontrail.sdnapi") + self.logger = logger or logging.getLogger("ro.sdn.junipercontrail.sdnapi") self.controller_url = url if not url: @@ -39,7 +40,7 @@ class UnderlayApi: url = url + "/" self.url = url - auth_url = None + self.auth_url = None self.project = None self.domain = None self.asn = None @@ -56,10 +57,13 @@ class UnderlayApi: 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)) + auth_dict = {} auth_dict['auth'] = {} auth_dict['auth']['scope'] = {} @@ -130,13 +134,24 @@ class UnderlayApi: else: return None + def delete_ref(self, type, uuid, ref_type, ref_uuid, ref_fq_name): + payload = { + "type": type, + "uuid": uuid, + "ref-type": ref_type, + "ref-fq-name": ref_fq_name, + "operation": "DELETE" + } + endpoint = self.controller_url + "ref-update" + 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 def get_vpg_name(self, switch_id, switch_port): - return "{}_{}".format(switch_id, switch_port) + return "{}_{}".format(switch_id, switch_port).replace(":", "_") def get_vmi_name(self, switch_id, switch_port, vlan): - return "{}_{}-{}".format(switch_id, switch_port, vlan) + return "{}_{}-{}".format(switch_id, switch_port, vlan).replace(":", "_") # Virtual network operations @@ -214,11 +229,10 @@ class UnderlayApi: 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): @@ -234,8 +248,8 @@ class UnderlayApi: profile_dict = { "local_link_information": [ { - "port_id": switch_port, - "switch_id": switch_port, + "port_id": switch_port.replace(":", "_"), + "switch_id": switch_port.replace(":", "_"), "switch_info": switch_id, "fabric": self.fabric } @@ -303,3 +317,5 @@ class UnderlayApi: 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)