~openstack-charmers/charms/precise/quantum-gateway/trunk

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: James Page
  • Date: 2012-10-26 15:56:42 UTC
  • Revision ID: james.page@canonical.com-20121026155642-bkr1oiu1n26h8zlv
BaselineĀ eodĀ pre-UDS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import utils
 
4
import sys
 
5
import quantum_utils
 
6
 
 
7
 
 
8
PLUGIN_PKGS = {
 
9
    "ovs": [  # TODO: Assumes Quantum Provider Gateway
 
10
        "quantum-plugin-openvswitch",
 
11
        "quantum-plugin-openvswitch-agent",
 
12
        "quantum-l3-agent",
 
13
        "quantum-dhcp-agent"
 
14
        ],
 
15
    "nvp": ["quantum-plugin-nicira"]  # No agent required
 
16
    }
 
17
 
 
18
 
 
19
def install():
 
20
    utils.configure_source()
 
21
    # TODO: when using the nicira plugin /etc/default/quantum-server
 
22
    # will also need to be updated to point to the correct configuration
 
23
    plugin = utils.config_get('plugin')
 
24
    if plugin in PLUGIN_PKGS.keys():
 
25
        if plugin == "ovs":
 
26
            # Install OVS DKMS first to ensure that the ovs module
 
27
            # loaded supports GRE tunnels
 
28
            utils.install('openvswitch-datapath-dkms')
 
29
        utils.install(['quantum-server'].extend(PLUGIN_PKGS[plugin]))
 
30
    else:
 
31
        utils.juju_log('ERROR', 'Please provide a valid plugin config')
 
32
        sys.exit(1)
 
33
 
 
34
 
 
35
def config_changed():
 
36
    plugin = utils.config_get('plugin')
 
37
    if plugin in PLUGIN_PKGS.keys():
 
38
        if plugin == "ovs":
 
39
            # TODO: Defaults to Quantum Provider Router
 
40
            quantum_utils.add_bridge('br-int')
 
41
            quantum_utils.add_bridge('br-ext')
 
42
            ext_port = utils.config_get('ext-port')
 
43
            if ext_port:
 
44
                quantum_utils.add_bridge_port('br-ex', ext_port)
 
45
            quantum_utils.configure_core_plugin(plugin)
 
46
            quantum_utils.configure_local_ip(plugin,
 
47
                                             utils.unit_get('private-address'))
 
48
    else:
 
49
        utils.juju_log('ERROR',
 
50
                       'Please provide a valid plugin config')
 
51
        sys.exit(1)
 
52
 
 
53
 
 
54
def keystone_joined():
 
55
    url = "http://{}:9696/".format(utils.unit_get('private-address'))
 
56
    utils.relation_set(service="quantum",
 
57
                       region="RegionOne",
 
58
                       public_url=url,
 
59
                       admin_url=url,
 
60
                       internal_url=url)
 
61
 
 
62
 
 
63
def keystone_changed():
 
64
    token = utils.relation_get('admin_token')
 
65
    service_port = utils.relation_get('service_port')
 
66
    auth_port = utils.relation_get('auth_port')
 
67
    service_username = utils.relation_get('service_username')
 
68
    service_password = utils.relation_get('service_password')
 
69
    service_tenant = utils.relation_get('service_tenant')
 
70
    if not (token and
 
71
            service_port and
 
72
            auth_port and
 
73
            service_username and
 
74
            service_password and
 
75
            service_tenant):
 
76
        utils.juju_log('INFO',
 
77
                       'keystone peer not ready yet')
 
78
        return
 
79
    if token == "-1":
 
80
        utils.juju_log('ERROR',
 
81
                       'Admin token error')
 
82
        sys.exit(1)
 
83
    keystone_host = utils.relation_get('private-address')
 
84
    utils.juju_log('INFO', 'Configuring quantum for keystone authentication')
 
85
    quantum_utils.configure_keystone(keystone_host,
 
86
                                     token,
 
87
                                     service_port,
 
88
                                     auth_port,
 
89
                                     service_username,
 
90
                                     service_password,
 
91
                                     service_tenant)
 
92
 
 
93
 
 
94
def db_joined():
 
95
    utils.relation_set(username=quantum_utils.DB_USER,
 
96
                       database=quantum_utils.QUANTUM_DB,
 
97
                       hostname=utils.unit_get('private-address'))
 
98
 
 
99
 
 
100
def db_changed():
 
101
    host = utils.relation_get('private-address')
 
102
    password = utils.relation_get('password')
 
103
    if not (host and password):
 
104
        return
 
105
    else:
 
106
        quantum_utils.configure_db_connection(utils.config_get('plugin'),
 
107
                                              host, password)
 
108
 
 
109
 
 
110
def amqp_joined():
 
111
    pass
 
112
 
 
113
 
 
114
def amqp_changed():
 
115
    pass
 
116
 
 
117
 
 
118
utils.do_hooks({
 
119
    "install": install,
 
120
    "config-changed": config_changed,
 
121
    "identity-service-relation-joined": keystone_joined,
 
122
    "identity-service-relation-changed": keystone_changed,
 
123
    "shared-db-relation-joined": db_joined,
 
124
    "shared-db-relation-changed": db_changed,
 
125
    "amqp-relation-joined": amqp_joined,
 
126
    "amqp-relation-changed": amqp_changed
 
127
    })
 
128
 
 
129
sys.exit(0)