~openstack-charmers/charms/trusty/nova-cloud-controller/keystonev3

« back to all changes in this revision

Viewing changes to hooks/charmhelpers/contrib/openstack/context.py

  • Committer: Liam Young
  • Date: 2016-01-29 08:59:12 UTC
  • Revision ID: liam.young@canonical.com-20160129085912-nt5qbn1zyet3b6sq
CH sync

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# You should have received a copy of the GNU Lesser General Public License
15
15
# along with charm-helpers.  If not, see <http://www.gnu.org/licenses/>.
16
16
 
 
17
import glob
17
18
import json
18
19
import os
19
20
import re
56
57
    get_nic_hwaddr,
57
58
    mkdir,
58
59
    write_file,
 
60
    pwgen,
59
61
)
60
62
from charmhelpers.contrib.hahelpers.cluster import (
61
63
    determine_apache_port,
86
88
    is_bridge_member,
87
89
)
88
90
from charmhelpers.contrib.openstack.utils import get_host_ip
 
91
from charmhelpers.core.unitdata import kv
 
92
 
89
93
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
90
94
ADDRESS_TYPES = ['admin', 'internal', 'public']
91
95
 
627
631
        if config('haproxy-client-timeout'):
628
632
            ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout')
629
633
 
 
634
        if config('haproxy-queue-timeout'):
 
635
            ctxt['haproxy_queue_timeout'] = config('haproxy-queue-timeout')
 
636
 
 
637
        if config('haproxy-connect-timeout'):
 
638
            ctxt['haproxy_connect_timeout'] = config('haproxy-connect-timeout')
 
639
 
630
640
        if config('prefer-ipv6'):
631
641
            ctxt['ipv6'] = True
632
642
            ctxt['local_host'] = 'ip6-localhost'
633
643
            ctxt['haproxy_host'] = '::'
634
 
            ctxt['stat_port'] = ':::8888'
635
644
        else:
636
645
            ctxt['local_host'] = '127.0.0.1'
637
646
            ctxt['haproxy_host'] = '0.0.0.0'
638
 
            ctxt['stat_port'] = ':8888'
 
647
 
 
648
        ctxt['stat_port'] = '8888'
 
649
 
 
650
        db = kv()
 
651
        ctxt['stat_password'] = db.get('stat-password')
 
652
        if not ctxt['stat_password']:
 
653
            ctxt['stat_password'] = db.set('stat-password',
 
654
                                           pwgen(32))
 
655
            db.flush()
639
656
 
640
657
        for frontend in cluster_hosts:
641
658
            if (len(cluster_hosts[frontend]['backends']) > 1 or
953
970
                    'config': config}
954
971
        return ovs_ctxt
955
972
 
 
973
    def midonet_ctxt(self):
 
974
        driver = neutron_plugin_attribute(self.plugin, 'driver',
 
975
                                          self.network_manager)
 
976
        midonet_config = neutron_plugin_attribute(self.plugin, 'config',
 
977
                                                  self.network_manager)
 
978
        mido_ctxt = {'core_plugin': driver,
 
979
                     'neutron_plugin': 'midonet',
 
980
                     'neutron_security_groups': self.neutron_security_groups,
 
981
                     'local_ip': unit_private_ip(),
 
982
                     'config': midonet_config}
 
983
 
 
984
        return mido_ctxt
 
985
 
956
986
    def __call__(self):
957
987
        if self.network_manager not in ['quantum', 'neutron']:
958
988
            return {}
974
1004
            ctxt.update(self.nuage_ctxt())
975
1005
        elif self.plugin == 'plumgrid':
976
1006
            ctxt.update(self.pg_ctxt())
 
1007
        elif self.plugin == 'midonet':
 
1008
            ctxt.update(self.midonet_ctxt())
977
1009
 
978
1010
        alchemy_flags = config('neutron-alchemy-flags')
979
1011
        if alchemy_flags:
1074
1106
                config_flags_parser(config_flags)}
1075
1107
 
1076
1108
 
 
1109
class LibvirtConfigFlagsContext(OSContextGenerator):
 
1110
    """
 
1111
    This context provides support for extending
 
1112
    the libvirt section through user-defined flags.
 
1113
    """
 
1114
    def __call__(self):
 
1115
        ctxt = {}
 
1116
        libvirt_flags = config('libvirt-flags')
 
1117
        if libvirt_flags:
 
1118
            ctxt['libvirt_flags'] = config_flags_parser(
 
1119
                libvirt_flags)
 
1120
        return ctxt
 
1121
 
 
1122
 
1077
1123
class SubordinateConfigContext(OSContextGenerator):
1078
1124
 
1079
1125
    """
1106
1152
 
1107
1153
        ctxt = {
1108
1154
            ... other context ...
1109
 
            'subordinate_config': {
 
1155
            'subordinate_configuration': {
1110
1156
                'DEFAULT': {
1111
1157
                    'key1': 'value1',
1112
1158
                },
1147
1193
                    try:
1148
1194
                        sub_config = json.loads(sub_config)
1149
1195
                    except:
1150
 
                        log('Could not parse JSON from subordinate_config '
1151
 
                            'setting from %s' % rid, level=ERROR)
 
1196
                        log('Could not parse JSON from '
 
1197
                            'subordinate_configuration setting from %s'
 
1198
                            % rid, level=ERROR)
1152
1199
                        continue
1153
1200
 
1154
1201
                    for service in self.services:
1155
1202
                        if service not in sub_config:
1156
 
                            log('Found subordinate_config on %s but it contained'
1157
 
                                'nothing for %s service' % (rid, service),
1158
 
                                level=INFO)
 
1203
                            log('Found subordinate_configuration on %s but it '
 
1204
                                'contained nothing for %s service'
 
1205
                                % (rid, service), level=INFO)
1159
1206
                            continue
1160
1207
 
1161
1208
                        sub_config = sub_config[service]
1162
1209
                        if self.config_file not in sub_config:
1163
 
                            log('Found subordinate_config on %s but it contained'
1164
 
                                'nothing for %s' % (rid, self.config_file),
1165
 
                                level=INFO)
 
1210
                            log('Found subordinate_configuration on %s but it '
 
1211
                                'contained nothing for %s'
 
1212
                                % (rid, self.config_file), level=INFO)
1166
1213
                            continue
1167
1214
 
1168
1215
                        sub_config = sub_config[self.config_file]
1365
1412
            normalized.update({port: port for port in resolved
1366
1413
                               if port in ports})
1367
1414
            if resolved:
1368
 
                return {bridge: normalized[port] for port, bridge in
 
1415
                return {normalized[port]: bridge for port, bridge in
1369
1416
                        six.iteritems(portmap) if port in normalized.keys()}
1370
1417
 
1371
1418
        return None
1376
1423
    def __call__(self):
1377
1424
        ctxt = {}
1378
1425
        mappings = super(PhyNICMTUContext, self).__call__()
1379
 
        if mappings and mappings.values():
1380
 
            ports = mappings.values()
 
1426
        if mappings and mappings.keys():
 
1427
            ports = sorted(mappings.keys())
1381
1428
            napi_settings = NeutronAPIContext()()
1382
1429
            mtu = napi_settings.get('network_device_mtu')
 
1430
            all_ports = set()
 
1431
            # If any of ports is a vlan device, its underlying device must have
 
1432
            # mtu applied first.
 
1433
            for port in ports:
 
1434
                for lport in glob.glob("/sys/class/net/%s/lower_*" % port):
 
1435
                    lport = os.path.basename(lport)
 
1436
                    all_ports.add(lport.split('_')[1])
 
1437
 
 
1438
            all_ports = list(all_ports)
 
1439
            all_ports.extend(ports)
1383
1440
            if mtu:
1384
 
                ctxt["devs"] = '\\n'.join(ports)
 
1441
                ctxt["devs"] = '\\n'.join(all_ports)
1385
1442
                ctxt['mtu'] = mtu
1386
1443
 
1387
1444
        return ctxt