add support for docker daemon.json configuration

Change-Id: Ib254c9a9c0e55131817268b9798612800508949b
diff --git a/README.rst b/README.rst
index 2718b40..deeb54d 100644
--- a/README.rst
+++ b/README.rst
@@ -23,12 +23,14 @@
     docker:
       host:
         enabled: true
-        experimental: true
-        insecure_registries:
-          - 127.0.0.1
-        log:
-          engine: json-file
-          size: 50m
+        options:
+          bip: 172.31.255.1/16
+          insecure_registries:
+            - 127.0.0.1
+            - 10.0.0.1
+          log-driver: json-file
+          log-opts:
+            max-size: 50m
 
 
 Docker Swarm
diff --git a/docker/files/daemon.json b/docker/files/daemon.json
index d1bdb8f..64de897 100644
--- a/docker/files/daemon.json
+++ b/docker/files/daemon.json
@@ -1,17 +1,42 @@
-{% from "docker/map.jinja" import host with context %}
+{%- from "docker/map.jinja" import host with context -%}
+
+{#- legacy and backward compatibility -#}
+
+{%- if 'experimental' not in host.get('options') and host.experimental is defined %}
+  {% do host.update({"experimental": host.experimental}) %}
+{%- endif -%}
+
+{%- if 'insecure-registries' not in host.get('options') and host.insecure_registries is defined %}
+  {% do host.options.update({"insecure-registries": []}) %}
+  {%- for srv in host.get('insecure_registries') %}
+    {% do host.options['insecure-registries'].append(srv) %}
+  {%- endfor %}
+{%- endif -%}
+
 {
-  {%- if host.experimental is defined %}
-  "experimental": {{ host.experimental|lower }}
-  {%- if host.insecure_registries is defined %},{% endif %}
-  {%- endif %}
-  {%- if host.insecure_registries is defined %}
-  "insecure-registries": [
-    {%- for registry in host.insecure_registries %}
-    "{{ registry }}"{% if not loop.last %},{% endif %}
+{%- for k, v in host.get('options', {}).iteritems() -%}
+
+  {%- if v is string %}
+    "{{ k }}": "{{ v }}"{%- if not loop.last %},{% endif %}
+
+  {%- elif v is mapping %}
+    "{{ k }}": {
+      {%- for ki, kv in v.iteritems() %}
+      "{{ ki }}": "{{ kv }}"{%- if not loop.last %},{% endif %}
+      {%- endfor %}
+    }{%- if not loop.last %},{% endif %}
+
+  {%- elif v is iterable %}
+    "{{ k }}": [
+    {%- for i in v %}
+      "{{ i }}"{% if not loop.last %},{% endif %}
     {%- endfor %}
-  ]
-  {%- endif %}
+    ]{%- if not loop.last %},{% endif %}
+
+  {%- elif v in [True, False] %}
+    "{{ k }}": {{ v|lower }}{%- if not loop.last %},{% endif %}
+
+  {%- endif -%}
+
+{%- endfor %}
 }
-{#-
-  vim: syntax=jinja
--#}
diff --git a/docker/files/default b/docker/files/default
index 7aa92ce..42f9bfb 100644
--- a/docker/files/default
+++ b/docker/files/default
@@ -6,7 +6,7 @@
 
 # Use DOCKER_OPTS to modify the daemon startup options.
 #DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
-DOCKER_OPTS=" --log-driver={{ host.log.get('engine','json-file') }} --log-opt max-size={{ host.log.get('size', '50m') }}"
+DOCKER_OPTS=" --log-driver={{ host.get('options', {}).get('log-driver','json-file') }} --log-opt max-size={{ host.get('options').get('log-opt', {}).get('max-size', '50m') }}"
 
 # If you need Docker to use an HTTP proxy, it can also be specified here.
 #export http_proxy="http://127.0.0.1:3128/"
diff --git a/metadata/service/host/init.yml b/metadata/service/host/init.yml
index c8a4f26..6355b8b 100644
--- a/metadata/service/host/init.yml
+++ b/metadata/service/host/init.yml
@@ -6,6 +6,7 @@
   docker:
     host:
       enabled: true
-      log:
-        engine: json-file
-        size: 50m
+      options:
+        log-driver: json-file
+        log-opts:
+          max-size: 50m
diff --git a/tests/pillar/host_single.sls b/tests/pillar/host_single.sls
index 991dead..66aa4f9 100644
--- a/tests/pillar/host_single.sls
+++ b/tests/pillar/host_single.sls
@@ -1,6 +1,12 @@
 docker:
   host:
     enabled: true
-    log:
-      engine: json-file
-      size: 50m
+    options:
+      bip: 192.168.0.1/24
+      log-driver: json-file
+      log-opts:
+        size: 50m
+      insecure-registry:
+      - srv01
+      - srv02
+      - srv03