dynamically create port forwards from 'head_vm_hosts'
diff --git a/roles/juju-setup/defaults/main.yml b/roles/juju-setup/defaults/main.yml
index f98ca2a..6b09858 100644
--- a/roles/juju-setup/defaults/main.yml
+++ b/roles/juju-setup/defaults/main.yml
@@ -15,16 +15,24 @@
cpu: "1"
memMB: "2048"
diskGB: "20"
+ forwarded_ports:
+ - { ext: 8777, int: 8777 }
- name: "glance"
cpu: "2"
memMB: "4096"
diskGB: "160"
+ forwarded_ports:
+ - { ext: 9292, int: 9292 }
- name: "keystone"
cpu: "2"
memMB: "4096"
diskGB: "40"
+ forwarded_ports:
+ - { ext: 35357, int: 35357 }
+ - { ext: 4990, int: 4990 }
+ - { ext: 5000, int: 5000 }
- name: "mysql"
cpu: "2"
@@ -35,11 +43,15 @@
cpu: "1"
memMB: "2048"
diskGB: "20"
+ forwarded_ports:
+ - { ext: 3128, int: 80 }
- name: "neutron-api"
cpu: "2"
memMB: "4096"
diskGB: "40"
+ forwarded_ports:
+ - { ext: 9696, int: 9696 }
- name: "neutron-gateway"
cpu: "2"
@@ -50,11 +62,15 @@
cpu: "2"
memMB: "4096"
diskGB: "40"
+ forwarded_ports:
+ - { ext: 8774, int: 8774 }
- name: "openstack-dashboard"
cpu: "1"
memMB: "2048"
diskGB: "20"
+ forwarded_ports:
+ - { ext: 8080, int: 80 }
- name: "rabbitmq-server"
cpu: "2"
diff --git a/roles/juju-setup/tasks/main.yml b/roles/juju-setup/tasks/main.yml
index 6b7c25e..d1b2f30 100644
--- a/roles/juju-setup/tasks/main.yml
+++ b/roles/juju-setup/tasks/main.yml
@@ -31,6 +31,19 @@
- name: Verify that we can log into every VM
command: ansible services -m ping -u ubuntu
+- name: Have libvirt enable port forwarding to VM's
+ become: yes
+ template:
+ src={{ item }}.j2
+ dest=/etc/libvirt/hooks/{{ item }}
+ mode=0755 owner=root
+ with_items:
+ - daemon
+ - qemu
+ notify:
+ - reload libvirt-bin
+ - run qemu hook
+
- name: Initialize Juju
command: juju generate-config
creates={{ ansible_user_dir }}/.juju/environments.yaml
@@ -77,7 +90,6 @@
# FIXME: ignoring errors when creating relationships.
# Previous method wasn't idempotent either
-
- name: Create relations between services
command: "juju add-relation '{{ item.0.name }}' '{{ item.1 }}'"
ignore_errors: True
@@ -85,19 +97,10 @@
- "{{ service_relations }}"
- relations
-# Need to wait for services to come up here
-# Possibly do so by using wait_for and wating on forwarded ports after next step?
-
-- name: Have libvirt enable port forwarding to VM's
- become: yes
- copy:
- src={{ item }}
- dest=/etc/libvirt/hooks/{{ item }}
- mode=0755 owner=root
- with_items:
- - daemon
- - qemu
- notify:
- - reload libvirt-bin
- - run qemu hook
+# This should be able to test for the VM's coming up, but not working right now
+#- name: Wait for juju services on VM's to come up
+# wait_for:
+# port={{ item.ext }}
+# timeout=10
+# with_items: "{{ head_vm_list | map(attribute='forwarded_ports') | reject('undefined') | list }}"
diff --git a/roles/juju-setup/templates/daemon.j2 b/roles/juju-setup/templates/daemon.j2
new file mode 100644
index 0000000..32e9b55
--- /dev/null
+++ b/roles/juju-setup/templates/daemon.j2
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+SHELL="/bin/bash"
+
+NIC=$( route|grep default|awk '{print $NF}' )
+
+NAME="${1}"
+OP="${2}"
+SUBOP="${3}"
+ARGS="${4}"
+
+add_port_fwd_rule() {
+ DPORT=$1
+ VM=$2
+ TOPORT=$3
+
+ VMIP=$( getent ahosts $VM|head -1|awk '{print $1}' )
+ iptables -t nat -C PREROUTING -p tcp -i $NIC --dport $DPORT -j DNAT --to-destination $VMIP:$TOPORT
+ if [ "$?" -ne 0 ]
+ then
+ iptables -t nat -A PREROUTING -p tcp -i $NIC --dport $DPORT -j DNAT --to-destination $VMIP:$TOPORT
+ fi
+}
+
+if [ "$OP" = "start" ] || [ "$OP" = "reload" ]
+then
+ iptables -t nat -F
+
+{% for vm in head_vm_list -%}
+{% if vm.forwarded_ports is defined -%}
+{% for port in vm.forwarded_ports -%}
+ add_port_fwd_rule {{ port.ext }} {{ vm.name }} {{ port.int }}
+{% endfor -%}
+{% endif -%}
+{% endfor -%}
+
+ # Also flush the filter table before rules re-added
+ iptables -F
+fi
+
diff --git a/roles/juju-setup/files/qemu b/roles/juju-setup/templates/qemu.j2
similarity index 100%
rename from roles/juju-setup/files/qemu
rename to roles/juju-setup/templates/qemu.j2