429
435
addr = unit_get('private-address')
431
cluster_hosts[l_unit] = get_address_in_network(config('os-internal-network'),
434
for rid in relation_ids('cluster'):
435
for unit in related_units(rid):
436
_unit = unit.replace('/', '-')
437
addr = relation_get('private-address', rid=rid, unit=unit)
438
cluster_hosts[_unit] = addr
439
# NOTE(jamespage): build out map of configured network endpoints
440
# and associated backends
441
for addr_type in ADDRESS_TYPES:
442
laddr = get_address_in_network(
443
config('os-{}-network'.format(addr_type)))
445
cluster_hosts[laddr] = {}
446
cluster_hosts[laddr]['network'] = "{}/{}".format(
448
get_netmask_for_address(laddr)
450
cluster_hosts[laddr]['backends'] = {}
451
cluster_hosts[laddr]['backends'][l_unit] = laddr
452
for rid in relation_ids('cluster'):
453
for unit in related_units(rid):
454
_unit = unit.replace('/', '-')
455
_laddr = relation_get('{}-address'.format(addr_type),
458
cluster_hosts[laddr]['backends'][_unit] = _laddr
460
# NOTE(jamespage) no split configurations found, just use
462
if not cluster_hosts:
463
cluster_hosts[addr] = {}
464
cluster_hosts[addr]['network'] = "{}/{}".format(
466
get_netmask_for_address(addr)
468
cluster_hosts[addr]['backends'] = {}
469
cluster_hosts[addr]['backends'][l_unit] = addr
470
for rid in relation_ids('cluster'):
471
for unit in related_units(rid):
472
_unit = unit.replace('/', '-')
473
_laddr = relation_get('private-address',
476
cluster_hosts[addr]['backends'][_unit] = _laddr
441
'units': cluster_hosts,
479
'frontends': cluster_hosts,
444
482
if config('haproxy-server-timeout'):
455
493
ctxt['haproxy_host'] = '0.0.0.0'
456
494
ctxt['stat_port'] = ':8888'
458
if len(cluster_hosts.keys()) > 1:
459
# Enable haproxy when we have enough peers.
460
log('Ensuring haproxy enabled in /etc/default/haproxy.')
461
with open('/etc/default/haproxy', 'w') as out:
462
out.write('ENABLED=1\n')
496
for frontend in cluster_hosts:
497
if len(cluster_hosts[frontend]['backends']) > 1:
498
# Enable haproxy when we have enough peers.
499
log('Ensuring haproxy enabled in /etc/default/haproxy.')
500
with open('/etc/default/haproxy', 'w') as out:
501
out.write('ENABLED=1\n')
464
503
log('HAProxy context is incomplete, this unit has no peers.')
616
655
def neutron_security_groups(self):
659
def neutron_type_drivers(self):
660
return 'gre,vxlan,vlan,flat'
663
def mechanism_drivers(self):
664
return "openvswitch,hyperv"
619
666
def _ensure_packages(self):
620
667
[ensure_packages(pkgs) for pkgs in self.packages]
727
def _snabb_init_zones_file(self, zones_file):
729
log("Configuring zones file '%s'" % (zones_file), level=INFO)
731
dirname = os.path.dirname(zones_file)
732
if dirname and not os.path.isdir(dirname):
735
encoded_defs = config('snabbswitch-zone-definitions')
737
# File is expected to be bzipped
738
out = bz2.decompress(base64.b64decode(encoded_defs))
739
with open(zones_file, 'w') as fd:
742
log("Created zones file '%s'" % (zones_file), level=INFO)
744
log("No zones definitions provided", level=INFO)
746
# Make sure a zones file exists if a path is set.
747
if not os.path.isfile(zones_file):
748
with open(zones_file, 'w') as fd:
751
# Make sure neutron user can read file.
752
user = pwd.getpwnam('neutron')
753
uid, gid = user.pw_uid, user.pw_gid
754
os.chown(zones_file, uid, gid)
756
def snabb_ctxt(self):
757
driver = neutron_plugin_attribute(self.plugin, 'driver',
758
self.network_manager)
759
snabb_config = neutron_plugin_attribute(self.plugin, 'config',
760
self.network_manager)
762
'core_plugin': driver,
763
'neutron_security_groups': self.neutron_security_groups,
764
'local_ip': unit_private_ip(),
765
'config': snabb_config,
768
zf = config('snabbswitch-zone-definitions-file')
770
snabb_ctxt['zone_definition_file'] = zf
771
self._snabb_init_zones_file(zf)
680
775
def neutron_ctxt(self):
710
807
ctxt.update(self.nvp_ctxt())
711
808
elif self.plugin == 'n1kv':
712
809
ctxt.update(self.n1kv_ctxt())
810
elif self.plugin == 'snabb':
811
ctxt.update(self.snabb_ctxt())
714
813
alchemy_flags = config('neutron-alchemy-flags')
715
814
if alchemy_flags:
723
822
class OSConfigFlagContext(OSContextGenerator):
726
Responsible for adding user-defined config-flags in charm config to a
729
NOTE: the value of config-flags may be a comma-separated list of
730
key=value pairs and some Openstack config files support
731
comma-separated lists as values.
735
config_flags = config('config-flags')
739
flags = config_flags_parser(config_flags)
740
return {'user_config_flags': flags}
825
Responsible for adding user-defined config-flags in charm config to a
828
NOTE: the value of config-flags may be a comma-separated list of
829
key=value pairs and some Openstack config files support
830
comma-separated lists as values.
834
config_flags = config('config-flags')
838
flags = config_flags_parser(config_flags)
839
return {'user_config_flags': flags}
743
842
class SubordinateConfigContext(OSContextGenerator):