~tribaal/charms/trusty/odl-controller/retry-on-client-call-error

« back to all changes in this revision

Viewing changes to hooks/odl_controller_hooks.py

  • Committer: Christopher Glass
  • Date: 2015-08-12 07:20:57 UTC
  • mfrom: (3.2.5 trunk)
  • Revision ID: christopher.glass@canonical.com-20150812072057-g9saflz8sxpst495
MergeĀ ~sdn-charmers/charms/trusty/odl-controller/trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
3
 
import json
4
3
import os
5
 
import re
6
4
import shutil
7
5
from subprocess import check_call
8
6
import sys
9
 
import urlparse
10
7
 
11
8
from charmhelpers.core.hookenv import (
12
9
    Hooks,
13
10
    UnregisteredHookError,
14
11
    config,
15
12
    log,
16
 
    relation_get,
 
13
    relation_set,
17
14
    relation_ids,
18
 
    relation_set,
19
 
    related_units,
20
15
)
21
16
 
22
17
from charmhelpers.core.host import (
29
24
from charmhelpers.fetch import apt_install, install_remote
30
25
 
31
26
from odl_controller_utils import write_mvn_config, process_odl_cmds
 
27
from odl_controller_utils import PROFILES
32
28
 
33
29
PACKAGES = ["default-jre-headless", "python-jinja2"]
34
30
 
39
35
@hooks.hook("config-changed")
40
36
@restart_on_change({"/home/opendaylight/.m2/settings.xml": ["odl-controller"]})
41
37
def config_changed():
 
38
    process_odl_cmds(PROFILES[config["profile"]])
 
39
    for r_id in relation_ids("controller-api"):
 
40
        controller_api_joined(r_id)
42
41
    write_mvn_config()
43
42
 
44
43
 
45
44
@hooks.hook("controller-api-relation-joined")
46
 
def controller_api_joined():
47
 
    relation_set(port=8080, username="admin", password="admin")
48
 
 
49
 
 
50
 
@hooks.hook("controller-api-relation-changed")
51
 
def controller_api_changed():
52
 
    for rid in relation_ids("controller-api"):
53
 
        for unit in related_units(rid):
54
 
            odl_cmds_json = relation_get(rid=rid, unit=unit,
55
 
                                         attribute="odl-cmds")
56
 
            if odl_cmds_json:
57
 
                odl_cmds = json.loads(odl_cmds_json)
58
 
                process_odl_cmds(odl_cmds)
 
45
def controller_api_joined(r_id=None):
 
46
    relation_set(relation_id=r_id,
 
47
                 port=PROFILES[config["profile"]]["port"],
 
48
                 username="admin", password="admin")
59
49
 
60
50
 
61
51
@hooks.hook()
65
55
 
66
56
    # install opendaylight
67
57
    install_url = config["install-url"]
68
 
    install_remote(install_url, dest="/opt")
69
 
    filename = re.sub("^.*/", "", urlparse.urlparse(install_url)[2])
70
 
    name = re.sub("\.tar\.gz$|\.tar$|\.gz$|\.zip$", "", filename)
71
 
    os.symlink(name, "/opt/opendaylight-karaf")
 
58
    install_remote(install_url, dest="/opt")  # this extracts the archive too
 
59
 
 
60
    # The extracted dirname. Look at what's on disk instead of mangling, so
 
61
    # the distribution tar.gz's name doesn't matter.
 
62
    name = [f for f in os.listdir("/opt")
 
63
            if f.startswith("distribution-karaf")][0]
 
64
 
 
65
    if not os.path.exists("/opt/opendaylight-karaf"):
 
66
        os.symlink(name, "/opt/opendaylight-karaf")
 
67
 
72
68
    shutil.copy("files/odl-controller.conf", "/etc/init")
73
69
    adduser("opendaylight", system_user=True)
74
70
    mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight",