~corey.bryant/charms/trusty/nova-compute/sync-charm-helpers

« back to all changes in this revision

Viewing changes to hooks/nova_compute_utils.py

  • Committer: James Page
  • Date: 2013-11-17 21:47:29 UTC
  • mfrom: (47.2.12 nova-compute)
  • Revision ID: james.page@canonical.com-20131117214729-g782k2u6bf52c64b
[gandelman-a] Merge of changes for ODS keynotes including NVP support and service restart on db changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
from subprocess import check_call, check_output
7
7
 
8
8
from charmhelpers.fetch import apt_update, apt_install
9
 
 
 
9
from charmhelpers.core.host import mkdir
10
10
from charmhelpers.core.hookenv import (
11
11
    config,
12
12
    log,
14
14
    relation_ids,
15
15
    relation_get,
16
16
    DEBUG,
 
17
    service_name
17
18
)
18
19
 
19
20
from charmhelpers.contrib.openstack.neutron import neutron_plugin_attribute
20
21
from charmhelpers.contrib.openstack import templating, context
 
22
from charmhelpers.contrib.openstack.alternatives import install_alternative
21
23
 
22
24
from charmhelpers.contrib.openstack.utils import (
23
25
    configure_installation_source,
72
74
}
73
75
 
74
76
CEPH_CONF = '/etc/ceph/ceph.conf'
 
77
CHARM_CEPH_CONF = '/var/lib/charm/{}/ceph.conf'
75
78
CEPH_SECRET = '/etc/ceph/secret.xml'
76
79
 
77
80
CEPH_RESOURCES = {
78
 
    CEPH_CONF: {
79
 
        'contexts': [NovaComputeCephContext()],
80
 
        'services': [],
81
 
    },
82
81
    CEPH_SECRET: {
83
82
        'contexts': [NovaComputeCephContext()],
84
83
        'services': [],
114
113
}
115
114
 
116
115
 
 
116
def ceph_config_file():
 
117
    return CHARM_CEPH_CONF.format(service_name())
 
118
 
 
119
 
117
120
def resource_map():
118
121
    '''
119
122
    Dynamically generate a map of resources that will be managed for a single
122
125
    # TODO: Cache this on first call?
123
126
    resource_map = deepcopy(BASE_RESOURCE_MAP)
124
127
    net_manager = network_manager()
 
128
    plugin = neutron_plugin()
125
129
 
126
130
    # Network manager gets set late by the cloud-compute interface.
127
131
    # FlatDHCPManager only requires some extra packages.
133
137
 
134
138
    # Neutron/quantum requires additional contexts, as well as new resources
135
139
    # depending on the plugin used.
 
140
    # NOTE(james-page): only required for ovs plugin right now
136
141
    if net_manager in ['neutron', 'quantum']:
137
 
        if net_manager == 'quantum':
138
 
            nm_rsc = QUANTUM_RESOURCES
139
 
        if net_manager == 'neutron':
140
 
            nm_rsc = NEUTRON_RESOURCES
141
 
        resource_map.update(nm_rsc)
142
 
 
143
 
        resource_map[NOVA_CONF]['contexts'].append(NeutronComputeContext())
144
 
 
145
 
        plugin = neutron_plugin()
146
 
        if plugin:
 
142
        if plugin == 'ovs':
 
143
            if net_manager == 'quantum':
 
144
                nm_rsc = QUANTUM_RESOURCES
 
145
            if net_manager == 'neutron':
 
146
                nm_rsc = NEUTRON_RESOURCES
 
147
            resource_map.update(nm_rsc)
 
148
 
147
149
            conf = neutron_plugin_attribute(plugin, 'config', net_manager)
148
150
            svcs = neutron_plugin_attribute(plugin, 'services', net_manager)
149
151
            ctxts = (neutron_plugin_attribute(plugin, 'contexts', net_manager)
156
158
            # associate the plugin agent with main network manager config(s)
157
159
            [resource_map[nmc]['services'].extend(svcs) for nmc in nm_rsc]
158
160
 
 
161
        resource_map[NOVA_CONF]['contexts'].append(NeutronComputeContext())
 
162
 
159
163
    if relation_ids('ceph'):
 
164
        # Add charm ceph configuration to resources and
 
165
        # ensure directory actually exists
 
166
        mkdir(os.path.dirname(ceph_config_file()))
 
167
        mkdir(os.path.dirname(CEPH_CONF))
 
168
        # Install ceph config as an alternative for co-location with
 
169
        # ceph and ceph-osd charms - nova-compute ceph.conf will be
 
170
        # lower priority that both of these but thats OK
 
171
        if not os.path.exists(ceph_config_file()):
 
172
            # touch file for pre-templated generation
 
173
            open(ceph_config_file(), 'w').close()
 
174
        install_alternative(os.path.basename(CEPH_CONF),
 
175
                            CEPH_CONF, ceph_config_file())
 
176
        CEPH_RESOURCES[ceph_config_file()] = {
 
177
            'contexts': [NovaComputeCephContext()],
 
178
            'services': [],
 
179
        }
160
180
        resource_map.update(CEPH_RESOURCES)
161
181
 
162
182
    return resource_map