Merge lp:~james-page/charms/trusty/odl-controller/profiles into lp:~sdn-charmers/charms/trusty/odl-controller/trunk

Proposed by James Page
Status: Merged
Merged at revision: 5
Proposed branch: lp:~james-page/charms/trusty/odl-controller/profiles
Merge into: lp:~sdn-charmers/charms/trusty/odl-controller/trunk
Diff against target: 230 lines (+117/-16)
3 files modified
config.yaml (+19/-1)
hooks/odl_controller_hooks.py (+24/-14)
hooks/odl_controller_utils.py (+74/-1)
To merge this branch: bzr merge lp:~james-page/charms/trusty/odl-controller/profiles
Reviewer Review Type Date Requested Status
Robert Ayres (community) Approve
Review via email: mp+264696@code.launchpad.net

Description of the change

Adds support for SDN profiles and http/https proxy configuration for ODL only.

To post a comment you must log in.
Revision history for this message
Robert Ayres (robert-ayres) wrote :

Minor comments:
* Use double quotes (") for strings everywhere.
* Use .format() over % for string formatting.
* Remove the empty 'default:' attributes from config.yaml where there is no default.

Otherwise, +1 to merge.

review: Approve
6. By James Page

Fixup niggles in review feedback

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2015-02-19 22:08:13 +0000
3+++ config.yaml 2015-07-15 07:48:36 +0000
4@@ -1,5 +1,23 @@
5 options:
6+ profile:
7+ type: string
8+ default: default
9+ description: |
10+ SDN controller profile to configure OpenDayLight for; supported values include
11+
12+ cisco-vpp: Cisco VPP for OpenStack
13+ openvswitch-odl: Open vSwitch OpenDayLight for OpenStack
14+
15+ Only a single profile is supported at any one time.
16 install-url:
17 type: string
18 default: "https://nexus.opendaylight.org/content/groups/public/org/opendaylight/integration/distribution-karaf/0.2.2-Helium-SR2/distribution-karaf-0.2.2-Helium-SR2.tar.gz"
19- description: Install binaries location
20+ description: Web addressable location of OpenDayLight binaries to install
21+ http-proxy:
22+ type: string
23+ default:
24+ description: Proxy to use for http connections for OpenDayLight
25+ https-proxy:
26+ type: string
27+ default:
28+ description: Proxy to use for https connections for OpenDayLight
29
30=== modified file 'hooks/odl_controller_hooks.py'
31--- hooks/odl_controller_hooks.py 2015-06-24 19:44:45 +0000
32+++ hooks/odl_controller_hooks.py 2015-07-15 07:48:36 +0000
33@@ -12,34 +12,43 @@
34 UnregisteredHookError,
35 config,
36 log,
37- relation_set
38+ relation_set,
39+ relation_ids,
40 )
41
42 from charmhelpers.core.host import (
43 adduser,
44 mkdir,
45 restart_on_change,
46- service_restart,
47 service_start
48 )
49
50 from charmhelpers.fetch import apt_install, install_remote
51
52-from odl_controller_utils import write_mvn_config
53+from odl_controller_utils import write_mvn_config, process_odl_cmds
54+from odl_controller_utils import PROFILES
55
56-PACKAGES = [ "default-jre-headless", "python-jinja2" ]
57+PACKAGES = ["default-jre-headless", "python-jinja2"]
58
59 hooks = Hooks()
60 config = config()
61
62+
63 @hooks.hook("config-changed")
64 @restart_on_change({"/home/opendaylight/.m2/settings.xml": ["odl-controller"]})
65 def config_changed():
66+ process_odl_cmds(PROFILES[config["profile"]])
67+ for r_id in relation_ids("controller-api"):
68+ controller_api_joined(r_id)
69 write_mvn_config()
70
71+
72 @hooks.hook("controller-api-relation-joined")
73-def controller_api_joined():
74- relation_set(port=8181, username="admin", password="admin")
75+def controller_api_joined(r_id=None):
76+ relation_set(relation_id=r_id,
77+ port=PROFILES[config["profile"]]["port"],
78+ username="admin", password="admin")
79+
80
81 @hooks.hook()
82 def install():
83@@ -51,21 +60,20 @@
84 install_remote(install_url, dest="/opt")
85 filename = re.sub("^.*/", "", urlparse.urlparse(install_url)[2])
86 name = re.sub("\.tar\.gz$|\.tar$|\.gz$|\.zip$", "", filename)
87- os.symlink(name, "/opt/opendaylight-karaf")
88+ if not os.path.exists("/opt/opendaylight-karaf"):
89+ os.symlink(name, "/opt/opendaylight-karaf")
90 shutil.copy("files/odl-controller.conf", "/etc/init")
91 adduser("opendaylight", system_user=True)
92- mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
93+ mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight",
94+ perms=0755)
95 check_call(["chown", "-R", "opendaylight:opendaylight", "/opt/" + name])
96- mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
97+ mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight",
98+ perms=0755)
99
100 # install features
101 write_mvn_config()
102 service_start("odl-controller")
103- check_call(["/opt/opendaylight-karaf/bin/client", "-r", "61",
104- "feature:install", "odl-base-all", "odl-aaa-authn",
105- "odl-restconf", "odl-nsf-all", "odl-adsal-northbound",
106- "odl-mdsal-apidocs", "odl-ovsdb-openstack",
107- "odl-ovsdb-northbound", "odl-dlux-core"])
108+
109
110 def main():
111 try:
112@@ -73,10 +81,12 @@
113 except UnregisteredHookError as e:
114 log("Unknown hook {} - skipping.".format(e))
115
116+
117 @hooks.hook("ovsdb-manager-relation-joined")
118 def ovsdb_manager_joined():
119 relation_set(port=6640, protocol="tcp")
120
121+
122 @hooks.hook("upgrade-charm")
123 def upgrade_charm():
124 pass
125
126=== modified file 'hooks/odl_controller_utils.py'
127--- hooks/odl_controller_utils.py 2015-02-19 22:08:13 +0000
128+++ hooks/odl_controller_utils.py 2015-07-15 07:48:36 +0000
129@@ -1,7 +1,34 @@
130+import subprocess
131 from os import environ
132 import urlparse
133
134 from charmhelpers.core.templating import render
135+from charmhelpers.core.hookenv import config
136+
137+
138+PROFILES = {
139+ "cisco-vpp": {
140+ "feature:install": ["cosc-cvpn-ovs-rest",
141+ "odl-netconf-connector-all"],
142+ "log:set": {
143+ "TRACE": ["cosc-cvpn-ovs-rest",
144+ "odl-netconf-connector-all"],
145+ },
146+ "port": 8181
147+ },
148+ "openvswitch-odl": {
149+ "feature:install": ["odl-base-all", "odl-aaa-authn",
150+ "odl-restconf", "odl-nsf-all",
151+ "odl-adsal-northbound",
152+ "odl-mdsal-apidocs",
153+ "odl-ovsdb-openstack",
154+ "odl-ovsdb-northbound",
155+ "odl-dlux-core"],
156+ "port": 8080
157+ }
158+}
159+PROFILES["default"] = PROFILES["openvswitch-odl"]
160+
161
162 def mvn_ctx():
163 ctx = {}
164@@ -9,11 +36,19 @@
165 ctx.update(mvn_proxy_ctx("https"))
166 return ctx
167
168+
169 def mvn_proxy_ctx(protocol):
170 ctx = {}
171+ proxy = config("{}-proxy".format(protocol))
172 key = protocol + "_proxy"
173- if key in environ:
174+ if proxy:
175+ url = urlparse.urlparse(proxy)
176+ elif key in environ:
177 url = urlparse.urlparse(environ[key])
178+ else:
179+ url = None
180+
181+ if url:
182 hostname = url.hostname
183 if hostname:
184 ctx[key] = True
185@@ -32,7 +67,45 @@
186 ctx[protocol + "_noproxy"] = no_proxy
187 return ctx
188
189+
190 def write_mvn_config():
191 ctx = mvn_ctx()
192 render("settings.xml", "/home/opendaylight/.m2/settings.xml", ctx,
193 "opendaylight", "opendaylight", 0400)
194+
195+
196+def run_odl(cmds, host="localhost", port=8101, retries=20):
197+ run_cmd = ["/opt/opendaylight-karaf/bin/client", "-r", str(retries),
198+ "-h", host, "-a", str(port)]
199+ run_cmd.extend(cmds)
200+ output = subprocess.check_output(run_cmd)
201+ return output
202+
203+
204+def installed_features():
205+ installed = []
206+ out = run_odl(["feature:list"])
207+ for line in out.split("\n"):
208+ columns = line.split("|")
209+ if len(columns) > 2:
210+ install_flag = columns[2].replace(" ", "")
211+ if install_flag == "x":
212+ installed.append(columns[0].replace(" ", ""))
213+ return installed
214+
215+
216+def filter_installed(features):
217+ installed = installed_features()
218+ whitelist = [feature for feature in features if feature not in installed]
219+ return whitelist
220+
221+
222+def process_odl_cmds(odl_cmds):
223+ features = filter_installed(odl_cmds.get("feature:install", []))
224+ if features:
225+ run_odl(["feature:install"] + features)
226+ logging = odl_cmds.get("log:set")
227+ if logging:
228+ for log_level in logging.keys():
229+ for target in logging[log_level]:
230+ run_odl(["log:set", log_level, target])

Subscribers

People subscribed via source and target branches

to all changes: