Add ability to set custom base_uri

In cases when designate-api is deployed under proxy,
we need custom uri to be returned to end user.

Change-Id: I89552c0d861eb702579e406f446f12f4637427cd
Related-Prod: OSCORE-398
diff --git a/README.rst b/README.rst
index 48cb5ff..d0b267e 100644
--- a/README.rst
+++ b/README.rst
@@ -22,6 +22,8 @@
           bind9:
             rndc_key: 4pc+X4PDqb2q+5o72dISm72LM1Ds9X2EYZjqg+nmsS7FhdTwzFFY8l/iEDmHxnyjkA33EQC8H+z0fLLBunoitw==
             rndc_algorithm: hmac-sha512
+        api:
+          base_uri: 'http://127.0.0.1:9001'
         bind:
           api:
             address: 127.0.0.1
@@ -79,6 +81,11 @@
    is deployed and zone is created, this parameter should be updated accordingly to UUID of
    newly created zone. Then designate state should be reapplied.
 
+.. note::
+   *server:api:base_uri* allows to set URL which is returned in designate-api responses, it is
+   useful in cases when, designate-api is deployed under proxy server. If not overriden in reclass,
+   it defaults to http://*server:bind:api:address*:9001/.
+
 Pools pillar for BIND9 master and multiple slaves setup:
 
 .. code:: yaml
diff --git a/designate/files/liberty/designate.conf.Debian b/designate/files/liberty/designate.conf.Debian
index aee8b6d..f284672 100644
--- a/designate/files/liberty/designate.conf.Debian
+++ b/designate/files/liberty/designate.conf.Debian
@@ -105,7 +105,7 @@
 #enable_host_header = False
 
 # The base uri used in responses
-api_base_uri = http://{{ server.bind.api.address }}:9001/
+api_base_uri = {{ server.api.base_uri }}
 
 # Address to bind the API server
 api_host = {{ server.bind.api.address }}
diff --git a/designate/files/mitaka/designate.conf.Debian b/designate/files/mitaka/designate.conf.Debian
index c14eec2..90d4f8b 100644
--- a/designate/files/mitaka/designate.conf.Debian
+++ b/designate/files/mitaka/designate.conf.Debian
@@ -122,7 +122,7 @@
 
 # The base uri used in responses
 #api_base_uri = 'http://127.0.0.1:9001/'
-api_base_uri = http://{{ server.bind.api.address }}:9001/
+api_base_uri = {{ server.api.base_uri }}
 
 # Address to bind the API server
 #api_host = 0.0.0.0
diff --git a/designate/files/ocata/designate.conf.Debian b/designate/files/ocata/designate.conf.Debian
index 6c3ded3..834a5f6 100644
--- a/designate/files/ocata/designate.conf.Debian
+++ b/designate/files/ocata/designate.conf.Debian
@@ -122,7 +122,7 @@
 
 # The base uri used in responses
 #api_base_uri = 'http://127.0.0.1:9001/'
-api_base_uri = http://{{ server.bind.api.address }}:9001/
+api_base_uri = {{ server.api.base_uri }}
 
 # API bind host+port pairs, comma separated
 listen = {{ server.bind.api.address }}:9001
diff --git a/designate/map.jinja b/designate/map.jinja
index bf08f5d..6d161ec 100644
--- a/designate/map.jinja
+++ b/designate/map.jinja
@@ -1,8 +1,13 @@
 {%- set version = salt['pillar.get']('designate:server:version') -%}
+{%- set api_address = salt['pillar.get']('designate:server:bind:api:address', '127.0.0.1') -%}
+{%- set api_port = salt['pillar.get']('designate:server:bind:api:port', '9001') -%}
 {%- if version not in ['mitaka','liberty', 'juno', 'kilo'] %}
 {% set server = salt['grains.filter_by']({
     'default': {
-        'pool_manager': {}
+        'pool_manager': {},
+        'api': {
+            'base_uri': 'http://' + api_address + ':' + api_port + '/'
+        }
     },
     'Debian': {
         'pkgs': ['designate', 'designate-producer', 'designate-mdns', 'designate-sink', 'designate-worker'],
@@ -16,7 +21,10 @@
 {%- else %}
 {% set server = salt['grains.filter_by']({
     'default': {
-        'pool_manager': {}
+        'pool_manager': {},
+        'api': {
+            'base_uri': 'http://' + api_address + ':' + api_port + '/'
+        }
     },
     'Debian': {
         'pkgs': ['designate', 'designate-pool-manager', 'designate-mdns', 'designate-sink', 'designate-zone-manager'],