~hopem/charms/trusty/nova-cloud-controller/lp1499435

« back to all changes in this revision

Viewing changes to hooks/nova_cc_hooks.py

  • Committer: Liam Young
  • Date: 2015-06-04 08:45:01 UTC
  • mfrom: (163 nova-cloud-controller)
  • mto: This revision was merged to the branch mainline in revision 164.
  • Revision ID: liam.young@canonical.com-20150604084501-113hnbchy3qdht8o
Resync le charm helpers

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
 
125
125
from charmhelpers.contrib.charmsupport import nrpe
126
126
 
 
127
try:
 
128
    FileNotFoundError
 
129
except NameError:
 
130
    # python3 compatibility
 
131
    FileNotFoundError = IOError
 
132
 
127
133
hooks = Hooks()
128
134
CONFIGS = register_configs()
 
135
COLO_CONSOLEAUTH = 'inf: res_nova_consoleauth grp_nova_vips'
 
136
AGENT_CONSOLEAUTH = 'ocf:openstack:nova-consoleauth'
 
137
AGENT_CA_PARAMS = 'op monitor interval="5s"'
 
138
NOVA_CONSOLEAUTH_OVERRIDE = '/etc/init/nova-consoleauth.override'
129
139
 
130
140
 
131
141
@hooks.hook()
179
189
    [cluster_joined(rid) for rid in relation_ids('cluster')]
180
190
    update_nrpe_config()
181
191
 
 
192
    update_nova_consoleauth_config()
 
193
 
182
194
 
183
195
@hooks.hook('amqp-relation-joined')
184
196
def amqp_joined(relation_id=None):
649
661
        'res_nova_haproxy': 'lsb:haproxy',
650
662
    }
651
663
    resource_params = {
652
 
        'res_nova_haproxy': 'op monitor interval="5s"'
 
664
        'res_nova_haproxy': 'op monitor interval="5s"',
653
665
    }
654
666
 
655
667
    vip_group = []
687
699
    clones = {
688
700
        'cl_nova_haproxy': 'res_nova_haproxy'
689
701
    }
 
702
    colocations = {}
 
703
 
 
704
    if config('single-nova-consoleauth') and console_attributes('protocol'):
 
705
        colocations['vip_consoleauth'] = COLO_CONSOLEAUTH
 
706
        init_services['res_nova_consoleauth'] = 'nova-consoleauth'
 
707
        resources['res_nova_consoleauth'] = AGENT_CONSOLEAUTH
 
708
        resource_params['res_nova_consoleauth'] = AGENT_CA_PARAMS
 
709
 
690
710
    relation_set(init_services=init_services,
691
711
                 corosync_bindiface=cluster_config['ha-bindiface'],
692
712
                 corosync_mcastport=cluster_config['ha-mcastport'],
693
713
                 resources=resources,
694
714
                 resource_params=resource_params,
695
 
                 clones=clones)
 
715
                 clones=clones,
 
716
                 colocations=colocations)
696
717
 
697
718
 
698
719
@hooks.hook('ha-relation-changed')
714
735
    for rid in relation_ids('identity-service'):
715
736
        identity_joined(rid=rid)
716
737
 
 
738
    update_nova_consoleauth_config()
 
739
 
717
740
 
718
741
@hooks.hook('shared-db-relation-broken',
719
742
            'pgsql-nova-db-relation-broken')
801
824
        for unit in related_units(r_id):
802
825
            compute_changed(r_id, unit)
803
826
    update_nrpe_config()
 
827
    update_nova_consoleauth_config()
804
828
 
805
829
 
806
830
# remote_restart is defaulted to true as nova-cells may have started the
912
936
    CONFIGS.write(NOVA_CONF)
913
937
 
914
938
 
 
939
def update_nova_consoleauth_config():
 
940
    """
 
941
    Configure nova-consoleauth pacemaker resources
 
942
    """
 
943
    relids = relation_ids('ha')
 
944
    if len(relids) == 0:
 
945
        log('Related to {} ha services'.format(len(relids)), level='DEBUG')
 
946
        ha_relid = None
 
947
        data = {}
 
948
    else:
 
949
        ha_relid = relids[0]
 
950
        data = relation_get(rid=ha_relid) or {}
 
951
 
 
952
    # initialize keys in case this is a new dict
 
953
    data.setdefault('delete_resources', [])
 
954
    for k in ['colocations', 'init_services', 'resources', 'resource_params']:
 
955
        data.setdefault(k, {})
 
956
 
 
957
    if config('single-nova-consoleauth') and console_attributes('protocol'):
 
958
        for item in ['vip_consoleauth', 'res_nova_consoleauth']:
 
959
            try:
 
960
                data['delete_resources'].remove(item)
 
961
            except ValueError:
 
962
                pass  # nothing to remove, we are good
 
963
 
 
964
        # the new pcmkr resources have to be added to the existing ones
 
965
        data['colocations']['vip_consoleauth'] = COLO_CONSOLEAUTH
 
966
        data['init_services']['res_nova_consoleauth'] = 'nova-consoleauth'
 
967
        data['resources']['res_nova_consoleauth'] = AGENT_CONSOLEAUTH
 
968
        data['resource_params']['res_nova_consoleauth'] = AGENT_CA_PARAMS
 
969
 
 
970
        for rid in relation_ids('ha'):
 
971
            relation_set(rid, **data)
 
972
 
 
973
        # nova-consoleauth will be managed by pacemaker, so mark it as manual
 
974
        if relation_ids('ha'):
 
975
            with open(NOVA_CONSOLEAUTH_OVERRIDE, 'w') as fp:
 
976
                fp.write('manual\n')
 
977
                fp.flush()
 
978
 
 
979
    elif (not config('single-nova-consoleauth')
 
980
          and console_attributes('protocol')):
 
981
        for item in ['vip_consoleauth', 'res_nova_consoleauth']:
 
982
            if item not in data['delete_resources']:
 
983
                data['delete_resources'].append(item)
 
984
 
 
985
        # remove them from the rel, so they aren't recreated when the hook
 
986
        # is recreated
 
987
        data['colocations'].pop('vip_consoleauth', None)
 
988
        data['init_services'].pop('res_nova_consoleauth', None)
 
989
        data['resources'].pop('res_nova_consoleauth', None)
 
990
        data['resource_params'].pop('res_nova_consoleauth', None)
 
991
 
 
992
        for rid in relation_ids('ha'):
 
993
            relation_set(rid, **data)
 
994
 
 
995
        try:
 
996
            os.remove(NOVA_CONSOLEAUTH_OVERRIDE)
 
997
        except FileNotFoundError as e:
 
998
            log(str(e), level='DEBUG')
 
999
 
 
1000
 
915
1001
def main():
916
1002
    try:
917
1003
        hooks.execute(sys.argv)