From 9d550e5108399bc1f85186956dabc6cbe3a3ec85 Mon Sep 17 00:00:00 2001 From: "dimitris.tsiolakis" Date: Tue, 16 Oct 2018 10:01:28 +0300 Subject: Find the ODL owner of the BGP entity in the 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 --- sdnvpn/lib/utils.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/sdnvpn/lib/utils.py b/sdnvpn/lib/utils.py index 9a5e181..c508596 100644 --- a/sdnvpn/lib/utils.py +++ b/sdnvpn/lib/utils.py @@ -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) -- cgit 1.2.3-korg