aboutsummaryrefslogtreecommitdiffstats
path: root/process_conf.py
blob: 976cf1971e79666b3902b6e9b4bdf75f7157e452 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import yaml
import sys
import subprocess
import traceback


def load_file(file):
    with open(file) as fd:
        try:
            return yaml.load(fd)
        except:
            traceback.print_exc()
            return None


def generate_openo_conf(openo_config, scripts_dir):
    """generate opera/work/scripts_dir/open-o.conf"""
    with open(scripts_dir + "/open-o.conf", "w") as fd:
        for i in openo_config["openo_net"].keys():
            fd.write('{0}={1}\n'.format(i.upper(), openo_config["openo_net"][i]))

        for i in openo_config["openo_docker_net"]:
            fd.write('{0}={1}\n'.format(i.upper(), openo_config["openo_docker_net"][i]))

        fd.write('{0}={1}\n'.format('OPENO_VERSION', openo_config["openo_version"]))
        fd.write('{0}={1}'.format('ENABLE_SDNO', openo_config["enable_sdno"]))


def generate_app_conf(openo_config, vnf_config, scripts_dir):
    """generate opera/work/scripts_dir/vnf.conf"""
    with open(scripts_dir + "/vnf.conf", "w") as fd:
        for i in vnf_config["vIMS"]:
            if i["type"] == openo_config["vnf_type"]:
                fd.write('{0}={1}\n'.format('VNF_TYPE', i["type"]))
                fd.write('{0}={1}\n'.format('NS_PKG', i["ns_pkg"]))
                fd.write('{0}={1}\n'.format('VNF_PKG', i["vnf_pkg"]))
                fd.write('{0}={1}'.format('NSDID', i["nsdId"]))
            break


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("parameter wrong%d %s" % (len(sys.argv), sys.argv))
        sys.exit(1)

    _, openo_file, vnf_file = sys.argv

    if not os.path.exists(openo_file):
        print("network.yml doesn't exit")
        sys.exit(1)

    if not os.path.exists(vnf_file):
        print("application.yml doesn't exit")
        sys.exit(1)

    openo_config = load_file(openo_file)
    if not openo_config:
        print('format error in %s' % openo_file)
        sys.exit(1)

    vnf_config = load_file(vnf_file)
    if not vnf_config:
        print('format error in %s' % vnf_file)
        sys.exit(1)

    opera_dir = os.getenv('OPERA_DIR')
    scripts_dir = os.path.join(opera_dir, 'work/scripts')
    if not os.path.exists(scripts_dir):
        print("dir opera/work/scripts doesn't exit")
        sys.exit(1)

    generate_openo_conf(openo_config, scripts_dir)
    generate_app_conf(openo_config, vnf_config, scripts_dir)