aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/opera_adapter.py
diff options
context:
space:
mode:
authorHarry Huang <huangxiangyu5@huawei.com>2017-01-17 14:45:57 +0800
committerHarry Huang <huangxiangyu5@huawei.com>2017-02-04 09:57:41 +0800
commit613ff10892793546146bd7e9d08054788f823609 (patch)
tree99c710e58c483df532cbb37111fb3f123e5ed04e /deploy/opera_adapter.py
parent7173757a6190f4528d36053d82467c74dbf16b3f (diff)
Add opera support
JIRA: COMPASS-504 JIRA: OPERA-1 Function: support open-o deployment by calling opera project. open-o deployment will start at the end of normal compass4nfv deployment. Changes: 1. add scenario and network yaml for opera 2. add opera_adapter.py for calling opera Attention: The git URL for opera will change after opera patch OPERA-2 is meraged. This patch should be modifed before meraged. Change-Id: Id0afcece920c4107bb23f42b460c46eec3ca97e6 Signed-off-by: Harry Huang <huangxiangyu5@huawei.com>
Diffstat (limited to 'deploy/opera_adapter.py')
-rw-r--r--deploy/opera_adapter.py93
1 files changed, 93 insertions, 0 deletions
diff --git a/deploy/opera_adapter.py b/deploy/opera_adapter.py
new file mode 100644
index 00000000..bccbfce1
--- /dev/null
+++ b/deploy/opera_adapter.py
@@ -0,0 +1,93 @@
+import os
+import yaml
+import sys
+import subprocess
+import traceback
+import ipaddress
+
+
+def load_file(file):
+ with open(file) as fd:
+ try:
+ return yaml.load(fd)
+ except:
+ traceback.print_exc()
+ return None
+
+
+def dump_file(data, file):
+ with open(file, 'w') as fd:
+ try:
+ return yaml.dump(data, fd, default_flow_style=False)
+ except:
+ traceback.print_exc()
+ 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]
+
+ 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
+
+ for i in net_config["juju_net"].keys():
+ net_config["juju_net"][i] = network["juju_net"][i]
+
+
+if __name__ == "__main__":
+ if len(sys.argv) != 3:
+ print("parameter wrong%d %s" % (len(sys.argv), sys.argv))
+ sys.exit(1)
+
+ _, dha_file, network_file = sys.argv
+
+ if not os.path.exists(dha_file):
+ print("DHA file doesn't exit")
+ sys.exit(1)
+ if not os.path.exists(network_file):
+ print("NETWORK file doesn't exit")
+ sys.exit(1)
+
+ dha = load_file(dha_file)
+ network = load_file(network_file)
+
+ if not dha:
+ print('format error in DHA: %s' % dha_file)
+ sys.exit(1)
+ if not network:
+ 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')
+
+ 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')
+ sys.exit(1)
+
+ net_config = load_file(net_config_file)
+ sync_openo_network_yml(network, net_config)
+ dump_file(net_config, net_config_file)
+
+ p2 = subprocess.Popen("./opera_launch.sh", cwd=opera_dir, shell=True)
+ p2.communicate()