~novaki/charms/precise/haproxy/hacluster-support

« back to all changes in this revision

Viewing changes to hooks/hooks.py

When the reverseproxy relation changes, the website proxy will likely need to be updated, so trigger a config-changed to notify the other side of the relation that it will need to update.

I'm not sure if this the appropriate way to handle this situation, but in practice it seems to work. Please let me know if there is a more accurate or correct way to do it.  LP:148605

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import sys
12
12
import yaml
13
13
import nrpe
 
14
import time
14
15
 
15
16
 
16
17
###############################################################################
84
85
    finally:
85
86
        return(relation_data)
86
87
 
 
88
def relation_set(arguments, relation_id=None):
 
89
    """
 
90
    Wrapper around relation-set
 
91
    @param arguments: list of command line arguments
 
92
    @param relation_id: optional relation-id (passed to -r parameter) to use
 
93
    """
 
94
    set_args = ["relation-set"]
 
95
    if relation_id is not None:
 
96
        set_args.extend(["-r", str(relation_id)])
 
97
    set_args.extend(arguments)
 
98
    subprocess.check_call(set_args)
87
99
 
88
100
#------------------------------------------------------------------------------
89
101
# apt_get_install( package ):  Installs a package
601
613
        else:
602
614
            return(False)
603
615
 
 
616
def website_notify():
 
617
    """
 
618
    Notify any webiste relations of any configuration changes.
 
619
    """
 
620
    juju_log("Notifying all website relations of change")
 
621
    all_relations = relation_get_all("website")
 
622
    if hasattr(all_relations, "iteritems"):
 
623
        for relid, reldata in all_relations.iteritems():
 
624
            relation_set(["time=%s" % time.time()], relation_id=relid)
 
625
 
604
626
 
605
627
###############################################################################
606
628
# Hook functions
652
674
def reverseproxy_interface(hook_name=None):
653
675
    if hook_name is None:
654
676
        return(None)
655
 
    if hook_name == "changed":
656
 
        config_changed()
657
 
    if hook_name=="departed":
658
 
        config_changed()
 
677
    elif hook_name == "changed":
 
678
        config_changed()
 
679
        website_notify()
 
680
    elif hook_name=="departed":
 
681
        config_changed()
 
682
        website_notify()
659
683
 
660
684
def website_interface(hook_name=None):
661
685
    if hook_name is None: