diff options
Diffstat (limited to 'deploy/opera_adapter.py')
-rw-r--r-- | deploy/opera_adapter.py | 84 |
1 files changed, 54 insertions, 30 deletions
diff --git a/deploy/opera_adapter.py b/deploy/opera_adapter.py index d040999f..f83638d7 100644 --- a/deploy/opera_adapter.py +++ b/deploy/opera_adapter.py @@ -8,11 +8,11 @@ ############################################################################## import os -import yaml import sys +import yaml +import re import subprocess import traceback -import ipaddress def load_file(file): @@ -33,23 +33,38 @@ def dump_file(data, file): return None -def sync_openo_network_yml(network, net_config): - """sync opera/conf/network.yml according to Network file""" - for i in net_config["openo_net"].keys(): - net_config["openo_net"][i] = network["openo_net"][i] +def sync_openo_config(openo_config, dha, network): + """sync opera/conf/open-o.yml according to DHA and Network file""" + deploy_opts = dha.get('deploy_options') + openo_net = network.get('openo_net') + if deploy_opts['orchestrator']['type'] != 'open-o': + print("orchestrator is not openo") + sys.exit(1) + + openo_config['openo_version'] = deploy_opts['orchestrator']['version'] + openo_config['vnf_type'] = deploy_opts['vnf']['type'] + openo_config['openo_net']['openo_ip'] = openo_net['openo_ip'] + + +def sync_admin_openrc(network, admin_openrc_file): + ssh_opts = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" + vip = network['public_vip']['ip'] + cmd = 'sshpass -p"root" ssh %s root@%s "cat /opt/admin-openrc.sh"' \ + % (ssh_opts, vip) + ssh = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) + if ssh.stdout is None: + print("fetch openrc fail") + sys.exit(1) - sorted_ips = sorted(net_config["openo_docker_net"].items(), - key=lambda item: item[1]) - docker_ips = [i[0] for i in sorted_ips] - docker_start_ip = unicode(network["openo_docker_net"]["docker_ip_start"], - "utf-8") - docker_start_ip = ipaddress.IPv4Address(docker_start_ip) - for i in docker_ips: - net_config["openo_docker_net"][i] = str(docker_start_ip) - docker_start_ip += 1 + rcdata = ssh.stdout.readlines() + with open(admin_openrc_file, 'w') as fd: + ip = re.compile("\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}") + for i in rcdata: + if 'OS_AUTH_URL' in i: + i = re.sub(ip, vip, i) + fd.write(i) - for i in net_config["juju_net"].keys(): - net_config["juju_net"][i] = network["juju_net"][i] + fd.write('export OS_REGION_NAME=RegionOne') if __name__ == "__main__": @@ -58,12 +73,17 @@ if __name__ == "__main__": sys.exit(1) _, dha_file, network_file = sys.argv + compass_dir = os.getenv('COMPASS_DIR') + + if not compass_dir: + print("env var COMPASS_DIR doesn't exist") + sys.exit(1) if not os.path.exists(dha_file): - print("DHA file doesn't exit") + print("DHA file doesn't exist") sys.exit(1) if not os.path.exists(network_file): - print("NETWORK file doesn't exit") + print("NETWORK file doesn't exist") sys.exit(1) dha = load_file(dha_file) @@ -76,27 +96,31 @@ if __name__ == "__main__": print('format error in NETWORK: %s' % network_file) sys.exit(1) - if dha["deploy_options"][0]["orchestrator"] != "open-o": - sys.exit(0) - - compass_dir = os.getenv('COMPASS_DIR') work_dir = os.path.join(compass_dir, 'work') opera_dir = os.path.join(work_dir, 'opera') conf_dir = os.path.join(opera_dir, 'conf') - net_config_file = os.path.join(conf_dir, 'network.yml') + openo_config_file = os.path.join(conf_dir, 'open-o.yml') + admin_openrc_file = os.path.join(conf_dir, 'admin-openrc.sh') p1 = subprocess.Popen( "git clone https://gerrit.opnfv.org/gerrit/opera", cwd=work_dir, shell=True) p1.communicate() - if not os.path.exists(net_config_file): - print('file opera/conf/network.yml not found') + if not os.path.exists(openo_config_file): + print('file opera/conf/open-o.yml not found') + sys.exit(1) + if not os.path.exists(admin_openrc_file): + print('file opera/conf/admin-openrc.sh not found') sys.exit(1) - net_config = load_file(net_config_file) - sync_openo_network_yml(network, net_config) - dump_file(net_config, net_config_file) + openo_config = load_file(openo_config_file) + sync_openo_config(openo_config, dha, network) + dump_file(openo_config, openo_config_file) + sync_admin_openrc(network, admin_openrc_file) - p2 = subprocess.Popen("./opera_launch.sh", cwd=opera_dir, shell=True) + p2 = subprocess.Popen("sudo ./opera_launch.sh", cwd=opera_dir, shell=True) p2.communicate() + if p2.returncode != 0: + print('./opera_launch.sh fail') + sys.exit(1) |