~landscape/landscape-charm/stable

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: Landscape Builder
  • Author(s): Free Ekanayaka
  • Date: 2015-02-05 16:07:10 UTC
  • mfrom: (217.1.2 no-combo-loader-support)
  • Revision ID: landscape_builder-20150205160710-jjl4nsa29v0orx24
Merge no-combo-loader-support [f=1417971] [r=danilo,tealeg] [a=Free Ekanayaka]
Support both LDS packages with and and without combo-loader.

Show diffs side-by-side

added added

removed removed

Lines of Context:
119
119
    haproxy_service = re.sub("\W", "", haproxy_service)
120
120
    return haproxy_service
121
121
 
 
122
COMBO_LOADER_VHOST_ENTRY = (
 
123
    "    RewriteRule ^/combo http://{{ haproxy_comboloader }}/ [P,L]\n")
 
124
 
 
125
NO_COMBO_LOADER_VHOST_ENTRY = (
 
126
    "    RewriteRule "
 
127
    "^/combo(.*) http://{{ haproxy_appserver }}/combo$1 [P,L]\n")
 
128
 
122
129
 
123
130
def _get_vhost_template(template_filename, haproxy_service_name):
124
131
    """Expand the template with the provided haproxy service name."""
125
132
    with open("%s/config/%s" % (ROOT, template_filename), "r") as handle:
126
133
        contents = handle.read()
 
134
        if not HAS_COMBO_LOADER:
 
135
            contents = contents.replace(
 
136
                COMBO_LOADER_VHOST_ENTRY, NO_COMBO_LOADER_VHOST_ENTRY)
127
137
        contents = re.sub(r"{{ haproxy_([^}]+) }}", r"{{ %s_\1 }}" %
128
138
                          haproxy_service_name, contents)
129
139
    return contents
654
664
        count = service_count
655
665
        if re.match(r"^.*:\d+$", service_count):
656
666
            (service, count) = service_count.split(":")
 
667
            if service == "combo-loader" and not HAS_COMBO_LOADER:
 
668
                continue
657
669
            result[service] = count
658
670
    return result
659
671
 
668
680
    result = {}
669
681
    requested = _get_requested_service_count()
670
682
    for service in _get_requested_services():
 
683
        if service == "combo-loader" and not HAS_COMBO_LOADER:
 
684
            continue
671
685
        args = [service]
672
686
        args.extend(SERVICE_COUNT[service])
673
687
        args.append(requested[service])
752
766
    config = juju.config_get()
753
767
    if "services" in config:
754
768
        for service in config["services"].split():
 
769
            if service == "combo-loader" and not HAS_COMBO_LOADER:
 
770
                continue
755
771
            if service not in SERVICE_DEFAULT:
756
772
                juju.juju_log("Invalid Service: %s" % service)
757
773
                raise Exception("Invalid Service: %s" % service)
857
873
    "pingserver": {
858
874
        "port": "8070", "httpchk": "HEAD /ping HTTP/1.0"
859
875
        },
860
 
    "combo-loader": {
861
 
        "port": "9070",
862
 
        "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
863
 
        },
864
876
    "async-frontend": {
865
877
        "port": "9090",
866
878
        "service_options": ["timeout client 300000",
869
881
    "package-upload": {"port": "9100"},
870
882
    "package-search": {"port": "9090"}}
871
883
 
 
884
HAS_COMBO_LOADER = os.path.exists("/etc/init.d/landscape-combo-loader")
 
885
if HAS_COMBO_LOADER:
 
886
    SERVICE_PROXY["combo-loader"] = {
 
887
        "port": "9070",
 
888
        "httpchk": "HEAD /?yui/scrollview/scrollview-min.js HTTP/1.0"
 
889
    }
 
890
 
 
891
 
872
892
# Format is:
873
893
#   [min, auto_max, hard_max]
874
894
#   min = minimum number of daemons to launch
879
899
    "msgserver": [2, 8, 9],
880
900
    "pingserver": [1, 4, 9],
881
901
    "apiserver": [1, 2, 9],
882
 
    "combo-loader": [1, 1, 1],
883
902
    "async-frontend": [1, 1, 1],
884
903
    "jobhandler": [1, 1, 1],
885
904
    "package-upload": [1, 1, 1],
887
906
    "juju-sync": [1, 1, 1],
888
907
    "cron": [1, 1, 1],
889
908
    "static": [1, 1, 1]}
890
 
 
 
909
if HAS_COMBO_LOADER:
 
910
    SERVICE_COUNT["combo-loader"] = [1, 1, 1]
891
911
 
892
912
SERVICE_DEFAULT = {
893
913
    "appserver": "RUN_APPSERVER",
894
914
    "msgserver": "RUN_MSGSERVER",
895
915
    "pingserver": "RUN_PINGSERVER",
896
 
    "combo-loader": "RUN_COMBO_LOADER",
897
916
    "async-frontend": "RUN_ASYNC_FRONTEND",
898
917
    "apiserver": "RUN_APISERVER",
899
918
    "package-upload": "RUN_PACKAGEUPLOADSERVER",
902
921
    "juju-sync": "RUN_JUJU_SYNC",
903
922
    "cron": "RUN_CRON",
904
923
    "static": None}
 
924
if HAS_COMBO_LOADER:
 
925
    SERVICE_DEFAULT["combo-loader"] = "RUN_COMBO_LOADER"
905
926
 
906
927
LANDSCAPE_DEFAULT_FILE = "/etc/default/landscape-server"
907
928
LANDSCAPE_APACHE_SITE = "/etc/apache2/sites-available/landscape.conf"