~james-page/charms/trusty/odl-controller/doc-updates

« back to all changes in this revision

Viewing changes to hooks/odl_controller_hooks.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:
12
12
    UnregisteredHookError,
13
13
    config,
14
14
    log,
15
 
    relation_set
 
15
    relation_set,
 
16
    relation_ids,
16
17
)
17
18
 
18
19
from charmhelpers.core.host import (
19
20
    adduser,
20
21
    mkdir,
21
22
    restart_on_change,
22
 
    service_restart,
23
23
    service_start
24
24
)
25
25
 
26
26
from charmhelpers.fetch import apt_install, install_remote
27
27
 
28
 
from odl_controller_utils import write_mvn_config
 
28
from odl_controller_utils import write_mvn_config, process_odl_cmds
 
29
from odl_controller_utils import PROFILES
29
30
 
30
 
PACKAGES = [ "default-jre-headless", "python-jinja2" ]
 
31
PACKAGES = ["default-jre-headless", "python-jinja2"]
31
32
 
32
33
hooks = Hooks()
33
34
config = config()
34
35
 
 
36
 
35
37
@hooks.hook("config-changed")
36
38
@restart_on_change({"/home/opendaylight/.m2/settings.xml": ["odl-controller"]})
37
39
def config_changed():
 
40
    process_odl_cmds(PROFILES[config["profile"]])
 
41
    for r_id in relation_ids("controller-api"):
 
42
        controller_api_joined(r_id)
38
43
    write_mvn_config()
39
44
 
 
45
 
40
46
@hooks.hook("controller-api-relation-joined")
41
 
def controller_api_joined():
42
 
    relation_set(port=8181, username="admin", password="admin")
 
47
def controller_api_joined(r_id=None):
 
48
    relation_set(relation_id=r_id,
 
49
                 port=PROFILES[config["profile"]]["port"],
 
50
                 username="admin", password="admin")
 
51
 
43
52
 
44
53
@hooks.hook()
45
54
def install():
51
60
    install_remote(install_url, dest="/opt")
52
61
    filename = re.sub("^.*/", "", urlparse.urlparse(install_url)[2])
53
62
    name = re.sub("\.tar\.gz$|\.tar$|\.gz$|\.zip$", "", filename)
54
 
    os.symlink(name, "/opt/opendaylight-karaf")
 
63
    if not os.path.exists("/opt/opendaylight-karaf"):
 
64
        os.symlink(name, "/opt/opendaylight-karaf")
55
65
    shutil.copy("files/odl-controller.conf", "/etc/init")
56
66
    adduser("opendaylight", system_user=True)
57
 
    mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
 
67
    mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight",
 
68
          perms=0755)
58
69
    check_call(["chown", "-R", "opendaylight:opendaylight", "/opt/" + name])
59
 
    mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
 
70
    mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight",
 
71
          perms=0755)
60
72
 
61
73
    # install features
62
74
    write_mvn_config()
63
75
    service_start("odl-controller")
64
 
    check_call(["/opt/opendaylight-karaf/bin/client", "-r", "61",
65
 
                "feature:install", "odl-base-all", "odl-aaa-authn",
66
 
                "odl-restconf", "odl-nsf-all", "odl-adsal-northbound",
67
 
                "odl-mdsal-apidocs", "odl-ovsdb-openstack",
68
 
                "odl-ovsdb-northbound", "odl-dlux-core"])
 
76
 
69
77
 
70
78
def main():
71
79
    try:
73
81
    except UnregisteredHookError as e:
74
82
        log("Unknown hook {} - skipping.".format(e))
75
83
 
 
84
 
76
85
@hooks.hook("ovsdb-manager-relation-joined")
77
86
def ovsdb_manager_joined():
78
87
    relation_set(port=6640, protocol="tcp")
79
88
 
 
89
 
80
90
@hooks.hook("upgrade-charm")
81
91
def upgrade_charm():
82
92
    pass