Find the ODL owner of the BGP entity in the 71/63571/3
authordimitris.tsiolakis <dmts@intracom-telecom.com>
Tue, 16 Oct 2018 07:01:28 +0000 (10:01 +0300)
committerdimitris.tsiolakis <dmts@intracom-telecom.com>
Wed, 17 Oct 2018 13:37:42 +0000 (16:37 +0300)
cluster in TC 3

After new Apex release Opendaylight run in container.
This fix finds the ODL owner of the BGP entity in the cluster for
containerised installations.

SDNVPN-234

Change-Id: Iec1abfe3e0be899ab51fe52057b394a4fa15cc49
Signed-off-by: dimitris.tsiolakis <dmts@intracom-telecom.com>
sdnvpn/lib/utils.py

index 9a5e181..c508596 100644 (file)
@@ -909,6 +909,16 @@ def get_ovs_flows(compute_node_list, ovs_br_list, of_protocol="OpenFlow13"):
     return cmd_out_lines
 
 
+def get_node_ip_and_netmask(node, iface):
+    cmd = "ip a | grep {iface} | grep inet | awk '{{print $2}}'"\
+          .format(iface=iface)
+    mgmt_net_cidr = node.run_cmd(cmd).strip().split('\n')
+    mgmt_ip = mgmt_net_cidr[0].split('/')[0]
+    mgmt_netmask = mgmt_net_cidr[0].split('/')[1]
+
+    return mgmt_ip, mgmt_netmask
+
+
 def get_odl_bgp_entity_owner(controllers):
     """ Finds the ODL owner of the BGP entity in the cluster.
 
@@ -921,9 +931,18 @@ def get_odl_bgp_entity_owner(controllers):
     if len(controllers) == 1:
         return controllers[0]
     else:
-        url = ('http://admin:admin@{ip}:8081/restconf/'
+        installer_type = str(os.environ['INSTALLER_TYPE'].lower())
+        if installer_type in ['fuel']:
+            ip, _ = get_node_ip_and_netmask(controllers[0], 'br-ctl')
+            port = 8282
+            odl_pass = 'admin'
+        else:
+            ip = controllers[0].ip
+            port = 8081
+            odl_pass = os.environ['SDN_CONTROLLER_PASSWORD']
+        url = ('http://{user}:{password}@{ip}:{port}/restconf/'
                'operational/entity-owners:entity-owners/entity-type/bgp'
-               .format(ip=controllers[0].ip))
+               .format(user='admin', password=odl_pass, ip=ip, port=port))
 
         remote_odl_akka_conf = ('/opt/opendaylight/configuration/'
                                 'initial/akka.conf')
@@ -937,10 +956,13 @@ def get_odl_bgp_entity_owner(controllers):
             return None
         odl_bgp_owner = json_output['entity-type'][0]['entity'][0]['owner']
 
+        get_odl_id_cmd = "sudo docker ps -qf name=opendaylight_api"
         for controller in controllers:
-
-            controller.run_cmd('sudo cp {0} /home/heat-admin/'
-                               .format(remote_odl_akka_conf))
+            odl_id = controller.run_cmd(get_odl_id_cmd)
+            controller.run_cmd('sudo docker cp {container_id}:{odl_akka_conf} '
+                               '/home/heat-admin/'
+                               .format(container_id=odl_id,
+                                       odl_akka_conf=remote_odl_akka_conf))
             controller.run_cmd('sudo chmod 777 {0}'
                                .format(remote_odl_home_akka_conf))
             controller.get_file(remote_odl_home_akka_conf, local_tmp_akka_conf)