Modified OpenStack build settings for mirror-image

Change-Id: Ie59ff1de60f4807a9b39b358834f19cbfac0b652
diff --git a/mirror-image/config-drive/user-data.yaml b/mirror-image/config-drive/user-data.yaml
index 72e45da..6d5d8a5 100644
--- a/mirror-image/config-drive/user-data.yaml
+++ b/mirror-image/config-drive/user-data.yaml
@@ -15,3 +15,5 @@
 # speed up resolving, and not stuck on timeouts. One-shot changes
   - echo '127.0.0.1 ubuntu' >> /etc/hosts
   - echo 'options timeout:1 attempts:4' >> /etc/resolv.conf
+  - echo 'nameserver 172.18.208.44' >> /etc/resolvconf/resolv.conf.d/base
+  - resolvconf -u
diff --git a/mirror-image/scripts/cleanup.sh b/mirror-image/scripts/cleanup.sh
index 295d4cb..857c7d9 100644
--- a/mirror-image/scripts/cleanup.sh
+++ b/mirror-image/scripts/cleanup.sh
@@ -23,3 +23,5 @@
 echo "cleaning up minion_id for salt"
 rm -f /etc/salt/minion_id || true
 
+echo "cleaning up resolvconf"
+sed -i '/172\.18\.208\.44/d' /etc/resolvconf/resolv.conf.d/base
\ No newline at end of file
diff --git a/mirror-image/scripts/mirrors.sh b/mirror-image/scripts/mirrors.sh
index 23bd679..fe7101f 100644
--- a/mirror-image/scripts/mirrors.sh
+++ b/mirror-image/scripts/mirrors.sh
@@ -1,15 +1,19 @@
 #!/bin/bash -xe
-#docker registry
-salt-call -t 5 --retcode-passthrough --no-color state.sls docker.host
-#docker run --restart always -d -p 5000:5000 --name registry registry:2
-salt-call -t 5 --retcode-passthrough state.sls docker.client.registry
-#docker system prune --all --force
 
 #aptly
+salt-call -t 5 --no-color state.sls aptly.server
+salt-call -t 5 --no-color state.sls aptly.publisher
 salt-call -t 5 --no-color state.sls aptly
-salt-call -t 5 --retcode-passthrough --no-color state.sls aptly.server
-sudo -i -u aptly aptly_mirror_update.sh -sv
-sudo -i -u aptly aptly_publish_update.sh -acrfv
+salt-call -t 5 --retcode-passthrough --no-color state.sls aptly
+aptly_mirror_update.sh -sv
+aptly-publisher --url http://10.99.0.1:18084 --timeout=1200 publish -v -d -c /etc/aptly-publisher.yaml --architectures amd64 --recreate --force-overwrite
+
+#docker registry
+salt-call -t 5 --retcode-passthrough state.sls docker.client.registry
+docker system prune --all --force
+
+#debmirror
+salt-call -t 5 --no-color state.sls debmirror
 
 #git
 salt-call -t 5 --retcode-passthrough --no-color state.sls git.server
diff --git a/mirror-image/scripts/reboot.sh b/mirror-image/scripts/reboot.sh
new file mode 100644
index 0000000..52adc95
--- /dev/null
+++ b/mirror-image/scripts/reboot.sh
@@ -0,0 +1,2 @@
+pgrep -f "sshd: root@" | xargs kill -9
+reboot now
\ No newline at end of file
diff --git a/mirror-image/scripts/salt.sh b/mirror-image/scripts/salt.sh
index 9c8a837..879c250 100644
--- a/mirror-image/scripts/salt.sh
+++ b/mirror-image/scripts/salt.sh
@@ -10,5 +10,6 @@
 salt-call -t 5 --retcode-passthrough --no-color state.sls linux.system.file
 salt-call -t 5 --retcode-passthrough --no-color state.sls docker.host
 salt-call -t 5 --retcode-passthrough --no-color state.sls docker exclude=docker.client.registry
+sleep 120
 salt-call -t 5 --retcode-passthrough --no-color state.sls linux.network
 salt-call -t 5 --retcode-passthrough --no-color state.sls nginx
diff --git a/mirror-image/scripts/salt_bootstrap.sh b/mirror-image/scripts/salt_bootstrap.sh
index 8dec3ce..453c3fb 100644
--- a/mirror-image/scripts/salt_bootstrap.sh
+++ b/mirror-image/scripts/salt_bootstrap.sh
@@ -5,7 +5,7 @@
 SALTSTACK_GPG=${SALTSTACK_GPG:-"https://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3/SALTSTACK-GPG-KEY.pub"}
 SALTSTACK_REPO=${SALTSTACK_REPO:-"http://repo.saltstack.com/apt/ubuntu/16.04/amd64/2016.3 xenial main"}
 APT_MIRANTIS_GPG=${APT_MIRANTIS_GPG:-"http://apt.mirantis.com/public.gpg"}
-APT_MIRANTIS_SALT_REPO=${APT_MIRANTIS_SALT_REPO:-"http://apt.mirantis.com/xenial/ ${FORMULA_VERSION} salt"}
+APT_MIRANTIS_SALT_REPO=${APT_MIRANTIS_SALT_REPO:-"http://apt.mirantis.com/xenial/ $FORMULA_VERSION salt"}
 GIT_SALT_FORMULAS_SCRIPTS=${GIT_SALT_FORMULAS_SCRIPTS:-"https://github.com/salt-formulas/salt-formulas-scripts"}
 
 wget -O - ${SALTSTACK_GPG} | sudo apt-key add -
diff --git a/mirror-image/template.json b/mirror-image/template.json
index b1a7171..f606787 100644
--- a/mirror-image/template.json
+++ b/mirror-image/template.json
@@ -4,9 +4,6 @@
     "password": "r00tme",
     "do_api_token": "{{ env `DO_API_TOKEN` }}",
     "image_name": "{{ env `IMAGE_NAME` }}",
-    "VM_IMAGE": "{{ env `VM_IMAGE` }}",
-    "floating_ip_pool": "{{ env `VM_FLOATING_IP_POOL` }}",
-    "VM_FLAVOR": "{{ env `VM_FLAVOR` }}",
     "disk_size": "150000",
     "cluster_model": "{{ env `CLUSTER_MODEL` }}",
     "cluster_model_ref": "{{ env `CLUSTER_MODEL_REF` }}",
@@ -20,7 +17,17 @@
     "apt_mirantis_salt_repo": "{{ env `APT_MIRANTIS_SALT_REPO` }}",
     "git_salt_formulas_scripts": "{{ env `GIT_SALT_FORMULAS_SCRIPTS` }}",
     "apt_repository": "{{ env `APT_REPOSITORY` }}",
-    "apt_repository_gpg": "{{ env `APT_REPOSITORY_GPG` }}"
+    "apt_repository_gpg": "{{ env `APT_REPOSITORY_GPG` }}",
+    "os_endpoint": "https://cloud-cz.bud.mirantis.net:5000/v2.0",
+    "os_flavor": "56c551be-41c0-49a4-b367-9b31691c32c3",
+    "os_username": "{{ env `OS_USERNAME` }}",
+    "os_password": "{{ env `OS_PASSWORD` }}",
+    "os_image": "60878bd4-cb4a-4d71-ae02-2a8ee4476d10",
+    "os_zone": "mcp-mk",
+    "os_floating_ip_pool": "public",
+    "os_tenant": "26e4dd19485249608ee3685f254f3909",
+    "os_network": "772f8ca6-1f4a-4535-99d0-880d6ead9a82"
+
   },
   "provisioners": [
     {
@@ -55,17 +62,20 @@
         "PACKER_OFFLINE_BUILD=true"
       ],
       "type": "shell",
+      "execute_command": "chmod +x {{ .Path }}; {{ .Vars }} {{ .Path }}",
       "expect_disconnect": "true",
       "scripts": [
         "scripts/base.sh",
         "scripts/network.sh",
-        "scripts/salt_bootstrap.sh"
+        "scripts/salt_bootstrap.sh",
+        "scripts/reboot.sh"
       ]
     },
     {
       "environment_vars": [
         "APT_MIRANTIS_SALT_REPO={{ user `apt_mirantis_salt_repo` }}"
       ],
+      "pause_before": "120s",
       "type": "shell",
       "expect_disconnect": "true",
       "scripts": [
@@ -102,14 +112,17 @@
       "ssh_username": "{{user `user`}}",
       "ssh_password": "{{user `password`}}",
       "image_name": "{{user `image_name`}}",
-      "floating_ip_pool": "{{user `floating_ip_pool`}}",
+      "floating_ip_pool": "{{user `os_floating_ip_pool`}}",
       "reuse_ips": "true",
-      "security_groups": [
-        "open_all"
-      ],
-      "source_image": "{{ user `VM_IMAGE` }}",
-      "flavor": "{{ user `VM_FLAVOR` }}",
-      "user_data_file": "config-drive/user-data.yaml"
+      "source_image": "{{ user `os_image` }}",
+      "flavor": "{{ user `os_flavor` }}",
+      "user_data_file": "config-drive/user-data.yaml",
+      "tenant_id": "{{ user `os_tenant` }}",
+      "networks": ["{{ user `os_network` }}"],
+      "availability_zone": "{{user `os_zone`}}",
+      "identity_endpoint": "{{user `os_endpoint`}}",
+      "username": "{{user `os_username`}}",
+      "password": "{{user `os_password`}}"
     },
     {
       "type": "qemu",