Merge branch 'master' of github.com:open-cloud/xos
diff --git a/xos/configurations/cord/make-vtn-networkconfig-json.sh b/xos/configurations/cord/make-vtn-networkconfig-json.sh
index 761ccb2..5256292 100755
--- a/xos/configurations/cord/make-vtn-networkconfig-json.sh
+++ b/xos/configurations/cord/make-vtn-networkconfig-json.sh
@@ -15,7 +15,7 @@
 NODES=$( sudo bash -c "source $SETUPDIR/admin-openrc.sh ; nova hypervisor-list" |grep enabled|awk '{print $4}' )
 
 # also configure ONOS to manage the nm node
-NM=`grep "^nm" $SETUPDIR/fqdn.map | awk '{ print $2 }'`
+NM=`grep "^nm" /root/setup/fqdn.map | awk '{ print $2 }'`
 NODES="$NODES $NM"
 
 NODECOUNT=0
diff --git a/xos/configurations/vtn/Makefile b/xos/configurations/vtn/Makefile
index 8f77036..59feb2d 100644
--- a/xos/configurations/vtn/Makefile
+++ b/xos/configurations/vtn/Makefile
@@ -1,9 +1,9 @@
 SETUPDIR:=../setup
 MYIP:=$(shell hostname -i)
 
-cloudlab: common_cloudlab xos
+cloudlab: common_cloudlab ansible_hosts xos
 
-devstack: upgrade_pkgs common_devstack xos
+devstack: upgrade_pkgs common_devstack ansible_hosts xos
 
 xos: vtn_network_cfg_json
 	sudo MYIP=$(MYIP) docker-compose up -d
@@ -21,6 +21,9 @@
 vtn_network_cfg_json:
 	export SETUPDIR=$(SETUPDIR); bash ../cord/make-vtn-networkconfig-json.sh
 
+ansible_hosts:
+	sudo bash -c "export SETUPDIR=$(SETUPDIR); scripts/gen-inventory.sh"
+
 stop:
 	sudo MYIP=$(MYIP) docker-compose stop
 
@@ -41,3 +44,6 @@
 
 upgrade_pkgs:
 	sudo pip install httpie --upgrade
+
+destroy-networks:
+	sudo ../../tools/destroy-all-networks.sh
diff --git a/xos/configurations/vtn/README.md b/xos/configurations/vtn/README.md
index 5d8eb12..0fac0a5 100644
--- a/xos/configurations/vtn/README.md
+++ b/xos/configurations/vtn/README.md
@@ -22,12 +22,22 @@
 * Login to the *ctl* node of your experiment and run:
 ```
 ctl:~$ git clone https://github.com/open-cloud/xos.git
-ctl:~$ cd xos/xos/configurations/devel/
-ctl:~/xos/xos/configurations/devel$ make cloudlab
+ctl:~$ cd xos/xos/configurations/vtn/
+ctl:~/xos/xos/configurations/vtn$ make cloudlab
 ```
 
+The configuration provides an Ansible script that automates the configuration
+steps outlined in [the VTN README](../cord/README-VTN.md).  Run:
+```
+ctl:~/xos/xos/configurations/vtn$ make destroy-networks
+ctl:~/xos/xos/configurations/vtn$ sudo ansible-playbook setup.yml 
+```
+
+
 ### DevStack
 
+*NOTE: THIS CONFIGURATION IS NOT YET WORKING WITH DEVSTACK.*
+
 The following instructions can be used to install DevStack and XOS together
 on a single node.  This setup has been run successfully in a VirtualBox VM
 with 2 CPUs and 4096 GB RAM.
diff --git a/xos/configurations/vtn/docker-compose.yml b/xos/configurations/vtn/docker-compose.yml
index 406ac80..976de78 100644
--- a/xos/configurations/vtn/docker-compose.yml
+++ b/xos/configurations/vtn/docker-compose.yml
@@ -16,7 +16,7 @@
     volumes:
         - ../setup:/root/setup:ro
         - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-        - ./xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
+        - ./files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
 
 
 xos_synchronizer_onos:
@@ -50,5 +50,5 @@
     volumes:
       - ../setup:/root/setup:ro
       - ../common/xos_common_config:/opt/xos/xos_configuration/xos_common_config:ro
-      - ./xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
+      - ./files/xos_vtn_config:/opt/xos/xos_configuration/xos_vtn_config:ro
       - ../setup/id_rsa.pub:/opt/xos/observers/onos/onos_key.pub:ro
diff --git a/xos/configurations/vtn/files/neutron-supervisor.conf b/xos/configurations/vtn/files/neutron-supervisor.conf
new file mode 100644
index 0000000..591df7d
--- /dev/null
+++ b/xos/configurations/vtn/files/neutron-supervisor.conf
@@ -0,0 +1,2 @@
+[program:neutron-server]
+command=/usr/bin/python /usr/bin/neutron-server --config-file=/etc/neutron/plugins/ml2/ml2_conf.ini --config-file=/etc/neutron/neutron.conf --config-file /usr/local/etc/neutron/plugins/ml2/conf_onos.ini --log-file=/var/log/neutron/neutron-server.log
diff --git a/xos/configurations/vtn/xos_vtn_config b/xos/configurations/vtn/files/xos_vtn_config
similarity index 100%
rename from xos/configurations/vtn/xos_vtn_config
rename to xos/configurations/vtn/files/xos_vtn_config
diff --git a/xos/configurations/vtn/scripts/gen-inventory.sh b/xos/configurations/vtn/scripts/gen-inventory.sh
new file mode 100755
index 0000000..f793a9a
--- /dev/null
+++ b/xos/configurations/vtn/scripts/gen-inventory.sh
@@ -0,0 +1,29 @@
+FN=/etc/ansible/hosts
+
+echo "Writing to $FN"
+
+rm -f $FN
+
+cat >> $FN <<EOF
+localhost
+
+[nodes]
+EOF
+
+NODES=$( sudo bash -c "source $SETUPDIR/admin-openrc.sh ; nova hypervisor-list" |grep enabled|awk '{print $4}' )
+
+# also configure ONOS to manage the nm node
+NM=`grep "^nm" /root/setup/fqdn.map | awk '{ print $2 }'`
+NODES="$NODES $NM"
+
+for NODE in $NODES; do
+    cat >> $FN <<EOF
+$NODE
+EOF
+done
+
+cat >> $FN <<EOF
+[nodes:vars]
+ansible_ssh_user=root
+ansible_ssh_key=/root/setup/id_rsa
+EOF
diff --git a/xos/configurations/vtn/setup.yml b/xos/configurations/vtn/setup.yml
new file mode 100644
index 0000000..ed7cd59
--- /dev/null
+++ b/xos/configurations/vtn/setup.yml
@@ -0,0 +1,51 @@
+---
+- hosts: localhost
+  connection: local
+  sudo: yes
+  vars:
+    vtn_host: cp-1.devel.xos-pg0.apt.emulab.net
+  tasks:
+  - apt: name={{ item }} state=installed
+    with_items:
+    - python-pip
+    - supervisor
+
+  - pip: name={{ item }} state=latest
+    with_items:
+    - setuptools
+    - pip
+    - testrepository
+  - git: repo=https://github.com/openstack/networking-onos.git
+      dest=/srv/networking-onos
+  - shell: cd /srv/networking-onos; python setup.py install
+
+  # Edit /etc/neutron/plugins/ml2/ml2_conf.ini
+  - ini_file: dest=/usr/local/etc/neutron/plugins/ml2/conf_onos.ini
+      section=onos option=url_path value=http://{{ vtn_host }}:8181/onos/openstackswitching
+  - ini_file: dest=/usr/local/etc/neutron/plugins/ml2/conf_onos.ini
+      section=onos option=username value=karaf
+  - ini_file: dest=/usr/local/etc/neutron/plugins/ml2/conf_onos.ini
+      section=onos option=password value=karaf
+
+  # Edit /etc/neutron/neutron.conf
+#  - ini_file: dest=/etc/neutron/neutron.conf
+#      section=DEFAULT option=core_plugin value=neutron.plugins.ml2.plugin.Ml2Plugin
+
+  # Edit /etc/neutron/plugins/ml2/ml2_conf.ini
+  - ini_file: dest=/etc/neutron/plugins/ml2/ml2_conf.ini
+      section=ml2 option=tenant_network_types value=vxlan
+  - ini_file: dest=/etc/neutron/plugins/ml2/ml2_conf.ini
+      section=ml2 option=type_drivers value=vxlan
+  - ini_file: dest=/etc/neutron/plugins/ml2/ml2_conf.ini
+      section=ml2 option=mechanism_drivers value=onos_ml2
+  - ini_file: dest=/etc/neutron/plugins/ml2/ml2_conf.ini
+      section=ml2_type_vxlan option=vni_ranges value=1001:2000
+
+  - service: name=neutron-server state=stopped enabled=no
+  # Run neutron-server with extra config file
+  - copy: src=files/neutron-supervisor.conf dest=/etc/supervisor/conf.d/
+  - shell: supervisorctl reload
+
+#  - shell: ../../scripts/destroy-all-networks.sh
+  - shell: cd ../cord/dataplane; bash ./generate-bm.sh > hosts-bm
+  - shell: cd ../cord/dataplane; ansible-playbook -i hosts-bm dataplane-vtn.yaml