~sdn-charmers/charms/trusty/odl-controller/trunk

« back to all changes in this revision

Viewing changes to hooks/odl_controller_utils.py

  • Committer: james.page at ubuntu
  • Date: 2015-07-15 07:48:43 UTC
  • mfrom: (4.1.2 odl-controller)
  • Revision ID: james.page@ubuntu.com-20150715074843-ughkmxtae3aod2g0
Add support for SDN profiles

Add support for explicit proxy configuration of ODL components only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import subprocess
1
2
from os import environ
2
3
import urlparse
3
4
 
4
5
from charmhelpers.core.templating import render
 
6
from charmhelpers.core.hookenv import config
 
7
 
 
8
 
 
9
PROFILES = {
 
10
    "cisco-vpp": {
 
11
        "feature:install": ["cosc-cvpn-ovs-rest",
 
12
                            "odl-netconf-connector-all"],
 
13
        "log:set": {
 
14
            "TRACE": ["cosc-cvpn-ovs-rest",
 
15
                      "odl-netconf-connector-all"],
 
16
        },
 
17
        "port": 8181
 
18
    },
 
19
    "openvswitch-odl": {
 
20
        "feature:install": ["odl-base-all", "odl-aaa-authn",
 
21
                            "odl-restconf", "odl-nsf-all",
 
22
                            "odl-adsal-northbound",
 
23
                            "odl-mdsal-apidocs",
 
24
                            "odl-ovsdb-openstack",
 
25
                            "odl-ovsdb-northbound",
 
26
                            "odl-dlux-core"],
 
27
        "port": 8080
 
28
    }
 
29
}
 
30
PROFILES["default"] = PROFILES["openvswitch-odl"]
 
31
 
5
32
 
6
33
def mvn_ctx():
7
34
    ctx = {}
9
36
    ctx.update(mvn_proxy_ctx("https"))
10
37
    return ctx
11
38
 
 
39
 
12
40
def mvn_proxy_ctx(protocol):
13
41
    ctx = {}
 
42
    proxy = config("{}-proxy".format(protocol))
14
43
    key = protocol + "_proxy"
15
 
    if key in environ:
 
44
    if proxy:
 
45
        url = urlparse.urlparse(proxy)
 
46
    elif key in environ:
16
47
        url = urlparse.urlparse(environ[key])
 
48
    else:
 
49
        url = None
 
50
 
 
51
    if url:
17
52
        hostname = url.hostname
18
53
        if hostname:
19
54
            ctx[key] = True
32
67
            ctx[protocol + "_noproxy"] = no_proxy
33
68
    return ctx
34
69
 
 
70
 
35
71
def write_mvn_config():
36
72
    ctx = mvn_ctx()
37
73
    render("settings.xml", "/home/opendaylight/.m2/settings.xml", ctx,
38
74
           "opendaylight", "opendaylight", 0400)
 
75
 
 
76
 
 
77
def run_odl(cmds, host="localhost", port=8101, retries=20):
 
78
    run_cmd = ["/opt/opendaylight-karaf/bin/client", "-r", str(retries),
 
79
               "-h", host, "-a", str(port)]
 
80
    run_cmd.extend(cmds)
 
81
    output = subprocess.check_output(run_cmd)
 
82
    return output
 
83
 
 
84
 
 
85
def installed_features():
 
86
    installed = []
 
87
    out = run_odl(["feature:list"])
 
88
    for line in out.split("\n"):
 
89
        columns = line.split("|")
 
90
        if len(columns) > 2:
 
91
            install_flag = columns[2].replace(" ", "")
 
92
            if install_flag == "x":
 
93
                installed.append(columns[0].replace(" ", ""))
 
94
    return installed
 
95
 
 
96
 
 
97
def filter_installed(features):
 
98
    installed = installed_features()
 
99
    whitelist = [feature for feature in features if feature not in installed]
 
100
    return whitelist
 
101
 
 
102
 
 
103
def process_odl_cmds(odl_cmds):
 
104
    features = filter_installed(odl_cmds.get("feature:install", []))
 
105
    if features:
 
106
        run_odl(["feature:install"] + features)
 
107
    logging = odl_cmds.get("log:set")
 
108
    if logging:
 
109
        for log_level in logging.keys():
 
110
            for target in logging[log_level]:
 
111
                run_odl(["log:set", log_level, target])