Add support for profiles and explicit proxy configuration
This commit is contained in:
commit
ad3ce251b5
20
config.yaml
20
config.yaml
|
@ -1,5 +1,23 @@
|
||||||
options:
|
options:
|
||||||
|
profile:
|
||||||
|
type: string
|
||||||
|
default: default
|
||||||
|
description: |
|
||||||
|
SDN controller profile to configure OpenDayLight for; supported values include
|
||||||
|
|
||||||
|
cisco-vpp: Cisco VPP for OpenStack
|
||||||
|
openvswitch-odl: Open vSwitch OpenDayLight for OpenStack
|
||||||
|
|
||||||
|
Only a single profile is supported at any one time.
|
||||||
install-url:
|
install-url:
|
||||||
type: string
|
type: string
|
||||||
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"
|
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"
|
||||||
description: Install binaries location
|
description: Web addressable location of OpenDayLight binaries to install
|
||||||
|
http-proxy:
|
||||||
|
type: string
|
||||||
|
default:
|
||||||
|
description: Proxy to use for http connections for OpenDayLight
|
||||||
|
https-proxy:
|
||||||
|
type: string
|
||||||
|
default:
|
||||||
|
description: Proxy to use for https connections for OpenDayLight
|
||||||
|
|
|
@ -12,34 +12,43 @@ from charmhelpers.core.hookenv import (
|
||||||
UnregisteredHookError,
|
UnregisteredHookError,
|
||||||
config,
|
config,
|
||||||
log,
|
log,
|
||||||
relation_set
|
relation_set,
|
||||||
|
relation_ids,
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
adduser,
|
adduser,
|
||||||
mkdir,
|
mkdir,
|
||||||
restart_on_change,
|
restart_on_change,
|
||||||
service_restart,
|
|
||||||
service_start
|
service_start
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.fetch import apt_install, install_remote
|
from charmhelpers.fetch import apt_install, install_remote
|
||||||
|
|
||||||
from odl_controller_utils import write_mvn_config
|
from odl_controller_utils import write_mvn_config, process_odl_cmds
|
||||||
|
from odl_controller_utils import PROFILES
|
||||||
|
|
||||||
PACKAGES = [ "default-jre-headless", "python-jinja2" ]
|
PACKAGES = ["default-jre-headless", "python-jinja2"]
|
||||||
|
|
||||||
hooks = Hooks()
|
hooks = Hooks()
|
||||||
config = config()
|
config = config()
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook("config-changed")
|
@hooks.hook("config-changed")
|
||||||
@restart_on_change({"/home/opendaylight/.m2/settings.xml": ["odl-controller"]})
|
@restart_on_change({"/home/opendaylight/.m2/settings.xml": ["odl-controller"]})
|
||||||
def config_changed():
|
def config_changed():
|
||||||
|
process_odl_cmds(PROFILES[config['profile']])
|
||||||
|
for r_id in relation_ids('controller-api'):
|
||||||
|
controller_api_joined(r_id)
|
||||||
write_mvn_config()
|
write_mvn_config()
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook("controller-api-relation-joined")
|
@hooks.hook("controller-api-relation-joined")
|
||||||
def controller_api_joined():
|
def controller_api_joined(r_id=None):
|
||||||
relation_set(port=8181, username="admin", password="admin")
|
relation_set(relation_id=r_id,
|
||||||
|
port=PROFILES[config['profile']]['port'],
|
||||||
|
username="admin", password="admin")
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook()
|
@hooks.hook()
|
||||||
def install():
|
def install():
|
||||||
|
@ -51,21 +60,20 @@ def install():
|
||||||
install_remote(install_url, dest="/opt")
|
install_remote(install_url, dest="/opt")
|
||||||
filename = re.sub("^.*/", "", urlparse.urlparse(install_url)[2])
|
filename = re.sub("^.*/", "", urlparse.urlparse(install_url)[2])
|
||||||
name = re.sub("\.tar\.gz$|\.tar$|\.gz$|\.zip$", "", filename)
|
name = re.sub("\.tar\.gz$|\.tar$|\.gz$|\.zip$", "", filename)
|
||||||
os.symlink(name, "/opt/opendaylight-karaf")
|
if not os.path.exists("/opt/opendaylight-karaf"):
|
||||||
|
os.symlink(name, "/opt/opendaylight-karaf")
|
||||||
shutil.copy("files/odl-controller.conf", "/etc/init")
|
shutil.copy("files/odl-controller.conf", "/etc/init")
|
||||||
adduser("opendaylight", system_user=True)
|
adduser("opendaylight", system_user=True)
|
||||||
mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
|
mkdir("/home/opendaylight", owner="opendaylight", group="opendaylight",
|
||||||
|
perms=0755)
|
||||||
check_call(["chown", "-R", "opendaylight:opendaylight", "/opt/" + name])
|
check_call(["chown", "-R", "opendaylight:opendaylight", "/opt/" + name])
|
||||||
mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight", perms=0755)
|
mkdir("/var/log/opendaylight", owner="opendaylight", group="opendaylight",
|
||||||
|
perms=0755)
|
||||||
|
|
||||||
# install features
|
# install features
|
||||||
write_mvn_config()
|
write_mvn_config()
|
||||||
service_start("odl-controller")
|
service_start("odl-controller")
|
||||||
check_call(["/opt/opendaylight-karaf/bin/client", "-r", "61",
|
|
||||||
"feature:install", "odl-base-all", "odl-aaa-authn",
|
|
||||||
"odl-restconf", "odl-nsf-all", "odl-adsal-northbound",
|
|
||||||
"odl-mdsal-apidocs", "odl-ovsdb-openstack",
|
|
||||||
"odl-ovsdb-northbound", "odl-dlux-core"])
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
|
@ -73,10 +81,12 @@ def main():
|
||||||
except UnregisteredHookError as e:
|
except UnregisteredHookError as e:
|
||||||
log("Unknown hook {} - skipping.".format(e))
|
log("Unknown hook {} - skipping.".format(e))
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook("ovsdb-manager-relation-joined")
|
@hooks.hook("ovsdb-manager-relation-joined")
|
||||||
def ovsdb_manager_joined():
|
def ovsdb_manager_joined():
|
||||||
relation_set(port=6640, protocol="tcp")
|
relation_set(port=6640, protocol="tcp")
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook("upgrade-charm")
|
@hooks.hook("upgrade-charm")
|
||||||
def upgrade_charm():
|
def upgrade_charm():
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,7 +1,34 @@
|
||||||
|
import subprocess
|
||||||
from os import environ
|
from os import environ
|
||||||
import urlparse
|
import urlparse
|
||||||
|
|
||||||
from charmhelpers.core.templating import render
|
from charmhelpers.core.templating import render
|
||||||
|
from charmhelpers.core.hookenv import config
|
||||||
|
|
||||||
|
|
||||||
|
PROFILES = {
|
||||||
|
'cisco-vpp': {
|
||||||
|
'feature:install': ['cosc-cvpn-ovs-rest',
|
||||||
|
'odl-netconf-connector-all'],
|
||||||
|
'log:set': {
|
||||||
|
'TRACE': ['cosc-cvpn-ovs-rest',
|
||||||
|
'odl-netconf-connector-all'],
|
||||||
|
},
|
||||||
|
'port': 8181
|
||||||
|
},
|
||||||
|
'openvswitch-odl': {
|
||||||
|
'feature:install': ["odl-base-all", "odl-aaa-authn",
|
||||||
|
"odl-restconf", "odl-nsf-all",
|
||||||
|
"odl-adsal-northbound",
|
||||||
|
"odl-mdsal-apidocs",
|
||||||
|
"odl-ovsdb-openstack",
|
||||||
|
"odl-ovsdb-northbound",
|
||||||
|
"odl-dlux-core"],
|
||||||
|
'port': 8080
|
||||||
|
}
|
||||||
|
}
|
||||||
|
PROFILES['default'] = PROFILES['openvswitch-odl']
|
||||||
|
|
||||||
|
|
||||||
def mvn_ctx():
|
def mvn_ctx():
|
||||||
ctx = {}
|
ctx = {}
|
||||||
|
@ -9,11 +36,19 @@ def mvn_ctx():
|
||||||
ctx.update(mvn_proxy_ctx("https"))
|
ctx.update(mvn_proxy_ctx("https"))
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
def mvn_proxy_ctx(protocol):
|
def mvn_proxy_ctx(protocol):
|
||||||
ctx = {}
|
ctx = {}
|
||||||
|
proxy = config('%s-proxy' % protocol)
|
||||||
key = protocol + "_proxy"
|
key = protocol + "_proxy"
|
||||||
if key in environ:
|
if proxy:
|
||||||
|
url = urlparse.urlparse(proxy)
|
||||||
|
elif key in environ:
|
||||||
url = urlparse.urlparse(environ[key])
|
url = urlparse.urlparse(environ[key])
|
||||||
|
else:
|
||||||
|
url = None
|
||||||
|
|
||||||
|
if url:
|
||||||
hostname = url.hostname
|
hostname = url.hostname
|
||||||
if hostname:
|
if hostname:
|
||||||
ctx[key] = True
|
ctx[key] = True
|
||||||
|
@ -32,7 +67,45 @@ def mvn_proxy_ctx(protocol):
|
||||||
ctx[protocol + "_noproxy"] = no_proxy
|
ctx[protocol + "_noproxy"] = no_proxy
|
||||||
return ctx
|
return ctx
|
||||||
|
|
||||||
|
|
||||||
def write_mvn_config():
|
def write_mvn_config():
|
||||||
ctx = mvn_ctx()
|
ctx = mvn_ctx()
|
||||||
render("settings.xml", "/home/opendaylight/.m2/settings.xml", ctx,
|
render("settings.xml", "/home/opendaylight/.m2/settings.xml", ctx,
|
||||||
"opendaylight", "opendaylight", 0400)
|
"opendaylight", "opendaylight", 0400)
|
||||||
|
|
||||||
|
|
||||||
|
def run_odl(cmds, host="localhost", port=8101, retries=20):
|
||||||
|
run_cmd = ["/opt/opendaylight-karaf/bin/client", "-r", str(retries),
|
||||||
|
"-h", host, "-a", str(port)]
|
||||||
|
run_cmd.extend(cmds)
|
||||||
|
output = subprocess.check_output(run_cmd)
|
||||||
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
def installed_features():
|
||||||
|
installed = []
|
||||||
|
out = run_odl(["feature:list"])
|
||||||
|
for line in out.split("\n"):
|
||||||
|
columns = line.split("|")
|
||||||
|
if len(columns) > 2:
|
||||||
|
install_flag = columns[2].replace(" ", "")
|
||||||
|
if install_flag == "x":
|
||||||
|
installed.append(columns[0].replace(" ", ""))
|
||||||
|
return installed
|
||||||
|
|
||||||
|
|
||||||
|
def filter_installed(features):
|
||||||
|
installed = installed_features()
|
||||||
|
whitelist = [feature for feature in features if feature not in installed]
|
||||||
|
return whitelist
|
||||||
|
|
||||||
|
|
||||||
|
def process_odl_cmds(odl_cmds):
|
||||||
|
features = filter_installed(odl_cmds.get("feature:install", []))
|
||||||
|
if features:
|
||||||
|
run_odl(["feature:install"] + features)
|
||||||
|
logging = odl_cmds.get("log:set")
|
||||||
|
if logging:
|
||||||
|
for log_level in logging.keys():
|
||||||
|
for target in logging[log_level]:
|
||||||
|
run_odl(["log:set", log_level, target])
|
||||||
|
|
Loading…
Reference in New Issue