Merge "Update memcache backend"
diff --git a/horizon/files/horizon_settings/_local_settings.py b/horizon/files/horizon_settings/_local_settings.py
index 59fc1d2..cc8d0db 100644
--- a/horizon/files/horizon_settings/_local_settings.py
+++ b/horizon/files/horizon_settings/_local_settings.py
@@ -1,4 +1,4 @@
-{%- from "horizon/map.jinja" import server with context %}
+{%- from "horizon/map.jinja" import server,default_cache_backend with context %}
 
 {%- if server.app is defined %}
 {%- set app = salt['pillar.get']('horizon:server:app:'+app_name) %}
@@ -20,7 +20,7 @@
 
 CACHES = {
     'default': {
-        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
+        'BACKEND': "{{ app.cache.get('backend', default_cache_backend) }}",
         {%- if app.cache.members is defined %}
         'LOCATION': "{%- for member in app.cache.members %}{{ member.host }}:{{ member.port }}{% if not loop.last %};{% endif %}{%- endfor %}"
         {%- else %}
diff --git a/horizon/map.jinja b/horizon/map.jinja
index bac43f0..3779d69 100644
--- a/horizon/map.jinja
+++ b/horizon/map.jinja
@@ -2,13 +2,34 @@
 {%- set multidomain = salt['pillar.get']('horizon:server:multidomain', 'False') %}
 {%- set default_domain = salt['pillar.get']('horizon:server:default_domain', 'default') %}
 
+{%- set default_cache_backend = 'django.core.cache.backends.memcached.MemcachedCache' %}
+
+{%- if not salt['pillar.get']('horizon:server:cache:backend') %}
+  {%- if salt['pillar.get']('horizon:server:version') not in ['mitaka','newton'] %}
+    {%- set cache_pkgs = ['python-pylibmc'] %}
+    {%- set default_cache_backend = 'django.core.cache.backends.memcached.PyLibMCCache' %}
+  {%- else %}
+    {% if grains['os_family'] == 'RedHat' %}
+      {%- set cache_pkgs = ['python-memcached'] %}
+    {% elif grains['os_family'] == 'Debian' %}
+      {%- set cache_pkgs = ['python-memcache'] %}
+    {% endif %}
+  {%- endif %}
+{%- elif salt['pillar.get']('horizon:server:cache:backend') == 'django.core.cache.backends.memcached.MemcachedCache' %}
+  {% if grains['os_family'] == 'RedHat' %}
+    {%- set cache_pkgs = ['python-memcached'] %}
+  {% elif grains['os_family'] == 'Debian' %}
+    {%- set cache_pkgs = ['python-memcache'] %}
+  {% endif %}
+{%- endif %}
+
 {% set server = salt['grains.filter_by']({
     'Debian': {
-        'pkgs': [dashboard_package, 'python-lesscpy', 'python-memcache', 'gettext-base'],
-        'pkgs_multi': ['python-memcache', 'python-psycopg2', 'python-imaging',
+        'pkgs': [dashboard_package, 'python-lesscpy', 'gettext-base'] + cache_pkgs,
+        'pkgs_multi': ['python-psycopg2', 'python-imaging',
             'python-docutils', 'python-simplejson', 'build-essential',
             'libxslt1-dev', 'libxml2-dev', 'libffi-dev', 'libssl-dev',
-            'gettext', 'python-lesscpy'],
+            'gettext', 'python-lesscpy'] + cache_pkgs,
         'ssl_pkgs': [dashboard_package],
         'service': 'apache2',
         'policy_files_path': '/usr/share/openstack-dashboard/openstack_dashboard/conf',
@@ -22,11 +43,11 @@
         'cache': {'host': '127.0.0.1', 'port': 11211}
     },
     'RedHat': {
-        'pkgs': ['httpd', dashboard_package, 'python-lesscpy', 'python-memcached'],
-        'pkgs_multi': ['python-memcached', 'python-psycopg2', 'python-pillow',
+        'pkgs': ['httpd', dashboard_package, 'python-lesscpy'] + cache_pkgs,
+        'pkgs_multi': ['python-psycopg2', 'python-pillow',
             'python-docutils', 'python-simplejson', 'libxslt-devel', 'gcc',
             'libxml2-devel', 'libffi-devel', 'openssl-devel',
-            'gettext', 'python-lesscpy'],
+            'gettext', 'python-lesscpy'] + cache_pkgs,
         'ssl_pkgs': ['mod_ssl'],
         'service': 'httpd',
         'policy_files_path': '/usr/share/openstack-dashboard/openstack_dashboard/conf',
@@ -41,4 +62,4 @@
     },
 }, merge=salt['pillar.get']('horizon:server')) %}
 
-{% set upgrade = pillar.get('horizon', {}).get('upgrade', {}) %}
+{% set upgrade = pillar.get('horizon', {}).get('upgrade', {}) %}
\ No newline at end of file