~wuwenbin2/onosfw/onos-controller

« back to all changes in this revision

Viewing changes to hooks/onos_controller_utils.py

  • Committer: zhangyuanyou
  • Date: 2016-05-25 06:46:19 UTC
  • Revision ID: git-v1:a1d04354fa04b68322897b1dfb89cf5d4b8645f1
add soft link and add config install-url,profile

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import subprocess
 
2
from os import environ
 
3
import urlparse
 
4
 
 
5
from charmhelpers.core.templating import render
 
6
from charmhelpers.core.hookenv import config
 
7
from charmhelpers.core.decorators import retry_on_exception
 
8
 
 
9
 
 
10
PROFILES = {
 
11
    "openvswitch-onos": {
 
12
        "feature:install": ["onos-app-vtn-onosfw", "onos-openflow-base",
 
13
                            "onos-openflow"],
 
14
        "port": 8080
 
15
    },
 
16
    "openvswitch-onos-goldeneye": {
 
17
        "feature:install": ["onos-ovsdatabase",
 
18
                            "onos-ovsdb-base",
 
19
                            "onos-drivers-ovsdb",
 
20
                            "onos-ovsdb-provider-host",
 
21
                            "onos-app-vtn-onosfw",
 
22
                            "onos-openflow-base",
 
23
                            "onos-openflow"],
 
24
        "port": 8080
 
25
    },
 
26
}
 
27
PROFILES["default"] = PROFILES["openvswitch-onos"]
 
28
 
 
29
 
 
30
@retry_on_exception(5, base_delay=10, exc_type=subprocess.CalledProcessError)
 
31
def run_onos(cmds):
 
32
    run_cmd = ["/opt/onos/bin/onos"]
 
33
    run_cmd.extend(cmds)
 
34
    output = subprocess.check_output(run_cmd)
 
35
    return output
 
36
 
 
37
 
 
38
def installed_features():
 
39
    installed = []
 
40
    out = run_onos(["feature:list"])
 
41
    for line in out.split("\n"):
 
42
        columns = line.split("|")
 
43
        if len(columns) > 2:
 
44
            install_flag = columns[2].replace(" ", "")
 
45
            if install_flag == "x":
 
46
                installed.append(columns[0].replace(" ", ""))
 
47
    return installed
 
48
 
 
49
 
 
50
def filter_installed(features):
 
51
    installed = installed_features()
 
52
    whitelist = [feature for feature in features if feature not in installed]
 
53
    return whitelist
 
54
 
 
55
 
 
56
def process_onos_cmds(onos_cmds):
 
57
    features = filter_installed(onos_cmds.get("feature:install", []))
 
58
    if features:
 
59
        run_onos(["feature:install"] + features)