Merge branch 'pod'

Continue automating and simplifying setup of CORD POD.  Remove unnecessary
neutron-gateway and neutron-openvswitch charms (not needed by VTN).
diff --git a/cord-hosts b/cord-hosts
index 52135d2..53b6e10 100644
--- a/cord-hosts
+++ b/cord-hosts
@@ -6,5 +6,4 @@
 10.90.0.66
 
 [all:vars]
-cloudlab=False
 ansible_ssh_user=cord
diff --git a/cord-setup.yml b/cord-setup.yml
index 5f599ae..c5c5ec1 100644
--- a/cord-setup.yml
+++ b/cord-setup.yml
@@ -15,7 +15,7 @@
   - name: Add Ansible repository
     apt_repository: repo="ppa:ansible/ansible"
 
-  - name: Update Ansible cache
+  - name: Update apt cache
     apt: update_cache=yes
 
   - name: Install packages
@@ -57,10 +57,21 @@
     authorized_key: user="{{ ansible_env['SUDO_USER'] }}"
       key="{{ sshkey.stdout }}"
 
+  - name: Copy keypair to /tmp
+    shell: cp -f {{ ansible_env['PWD'] }}/.ssh/{{ item }} /tmp; chmod +r /tmp/{{ item }}
+    with_items:
+    - id_rsa
+    - id_rsa.pub
+
+  - name: Check whether we're on CloudLab
+    shell: ls /usr/testbed/bin/mkextrafs
+    ignore_errors: true
+    register: is_cloudlab
+
   - name: (CloudLab) Set up extra disk space
     shell: /usr/testbed/bin/mkextrafs -f /var/lib/uvtool/libvirt/images
       creates=/var/lib/uvtool/libvirt/images/lost+found
-    when: cloudlab is defined and cloudlab
+    when: is_cloudlab | success
 
   - name: Add myself to libvirtd group
     user: name={{ ansible_env['SUDO_USER'] }}
@@ -74,20 +85,26 @@
 - hosts: head
   sudo: yes
   tasks:
-  - name: Create VMs to host OpenCloud services
+  - name: Create VMs to host OpenCloud services on mgmtbr
     sudo: no
     script: scripts/create-vms-cord.sh
+    when: test_setup is not defined
 
-  - include: tasks/vm-ips.yml
+  - name: Create VMs to host OpenCloud services on virbr0
+    sudo: no
+    script: scripts/create-vms-cord.sh --testing
+    when: test_setup is defined
+
+  - include: tasks/vm-ips-cord.yml
 
   - name: Add VMs to /etc/hosts
-    template: src=templates/etc/hosts.j2
+    template: src=templates/etc/cord-hosts.j2
       dest=/etc/hosts
     notify:
     - Reload dnsmasq
 
   - name: Set up /etc/ansible/hosts
-    template: src=templates/etc/ansible/hosts.j2
+    template: src=templates/etc/ansible/cord-hosts.j2
       dest=/etc/ansible/hosts
 
   - name: Copy ansible.cfg to disable host key checking
@@ -127,14 +144,19 @@
     authorized_key: user="root"
       key="{{ hostvars['head']['sshkey']['stdout'] }}"
 
+  - name: Check whether we're on CloudLab
+    shell: ls /usr/testbed/bin/mkextrafs
+    ignore_errors: true
+    register: is_cloudlab
+
   - name: Make sure that /var/lib/nova exists
     file: path=/var/lib/nova state=directory
-    when: cloudlab is defined and cloudlab
+    when: is_cloudlab | success
 
   - name: (CloudLab) Set up extra disk space
     shell: /usr/testbed/bin/mkextrafs -f /var/lib/nova
       creates=/var/lib/nova/lost+found
-    when: cloudlab is defined and cloudlab
+    when: is_cloudlab | success
 
 # Play: Install services using Juju
 - hosts: head
@@ -166,8 +188,12 @@
     shell: juju add-machine ssh:{{ item }}
     with_items: "{{ groups['compute'] }}"
 
+  - name: Get onos-cord IP
+    shell: uvt-kvm ip onos-cord
+    register: onos_cord_ip
+
   - name: Copy cord.yaml bundle
-    copy: src=cord.yaml dest={{ ansible_env['PWD'] }}/cord.yaml
+    template: src=templates/cord.yaml dest={{ ansible_env['PWD'] }}/cord.yaml
 
   - name: Deploy OpenStack services with Juju
     shell: juju quickstart cord.yaml
@@ -184,5 +210,29 @@
     template: src=templates/admin-openrc-cord.sh.j2
      dest={{ ansible_env['PWD'] }}/admin-openrc.sh
 
+  - name: Copy credentials to /tmp
+    shell: cp -f {{ ansible_env['PWD'] }}/admin-openrc.sh /tmp
+
   - name: Copy credentials to nova-cloud-controller
     shell: "scp admin-openrc.sh ubuntu@nova-cloud-controller:"
+
+- hosts: head
+  sudo: no
+  tasks:
+
+  - name: Copy over VM setup files
+    copy: src=files/tmp/{{ item }}
+      dest=/tmp
+    with_items:
+    - set-up-xos.yml
+    - set-up-onos.yml
+
+  - name: Copy over ONOS docker-compose.yml
+    copy: src=files/onos/docker-compose.yml
+      dest=/tmp
+
+  - name: Set up xos VM
+    shell: ansible-playbook /tmp/set-up-xos.yml
+
+  - name: Set up onos-cord VM
+    shell: ansible-playbook /tmp/set-up-onos.yml
diff --git a/cord-test-hosts b/cord-test-hosts
new file mode 100644
index 0000000..c41c275
--- /dev/null
+++ b/cord-test-hosts
@@ -0,0 +1,7 @@
+head    ansible_ssh_host=localhost connection=local
+
+[compute]
+nova-compute ansible_ssh_user=ubuntu
+
+[all:vars]
+test_setup=true 
diff --git a/files/onos/docker-compose.yml b/files/onos/docker-compose.yml
new file mode 100644
index 0000000..9b16c4d
--- /dev/null
+++ b/files/onos/docker-compose.yml
@@ -0,0 +1,10 @@
+onos:
+    image: onosproject/onos
+    expose:
+    - "6653"
+    - "8101"
+    - "8181"
+    - "9876"
+    net: host
+    volumes:
+    - ./id_rsa:/root/node_key:ro
diff --git a/files/tmp/set-up-onos.yml b/files/tmp/set-up-onos.yml
new file mode 100644
index 0000000..ac76476
--- /dev/null
+++ b/files/tmp/set-up-onos.yml
@@ -0,0 +1,25 @@
+---
+- hosts: onos-cord
+  sudo: no
+  vars:
+    homedir: /tmp
+  remote_user: ubuntu
+  tasks:
+  - shell: "which docker > /dev/null || wget -qO- https://get.docker.com/ | sh"
+
+  - shell: usermod -aG docker ubuntu
+    sudo: yes
+
+  - shell: "curl -L https://github.com/docker/compose/releases/download/1.5.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose; chmod +x /usr/local/bin/docker-compose"
+    sudo: yes
+
+  - file: path={{ ansible_env['PWD'] }}/cord
+      state=directory
+
+  - copy: src={{ homedir }}/{{ item }}
+      dest={{ ansible_env['PWD'] }}/cord
+    with_items:
+      - id_rsa
+      - docker-compose.yml
+
+  # To do: add docker-compose.yml file to cord/ directory
diff --git a/files/tmp/set-up-xos.yml b/files/tmp/set-up-xos.yml
new file mode 100644
index 0000000..a73fe5f
--- /dev/null
+++ b/files/tmp/set-up-xos.yml
@@ -0,0 +1,43 @@
+---
+- hosts: xos
+  sudo: no
+  remote_user: ubuntu
+  vars:
+    homedir: /tmp
+  tasks:
+  - apt: update_cache=yes
+    sudo: yes
+
+  - apt: name={{ item }}
+      state=present
+    sudo: yes
+    with_items:
+    - git
+    - make
+    - python-novaclient
+    - python-neutronclient
+    - python-keystoneclient
+    - python-glanceclient
+
+  - git: repo=https://github.com/open-cloud/xos.git
+      dest={{ ansible_env['PWD'] }}/xos
+
+  - shell: make -f {{ ansible_env['PWD'] }}/xos/xos/configurations/common/Makefile.prereqs
+
+  - copy: src={{ homedir }}/{{ item }}
+      dest={{ ansible_env['PWD'] }}/xos/xos/configurations/cord-pod/
+    with_items:
+    - id_rsa
+    - id_rsa.pub
+
+  - copy: src={{ homedir }}/admin-openrc.sh
+      dest={{ ansible_env['PWD'] }}/xos/xos/configurations/cord-pod
+
+  - copy: src={{ homedir }}/id_rsa
+      dest={{ ansible_env['PWD'] }}/xos/xos/configurations/cord-pod/node_key
+
+  - file: path={{ ansible_env['PWD'] }}/xos/xos/configurations/cord-pod/images
+      state=directory
+
+  - get_url: url=http://www.vicci.org/opencloud/trusty-server-cloudimg-amd64-disk1.img
+      dest={{ ansible_env['PWD'] }}/xos/xos/configurations/cord-pod/images/trusty-server-multi-nic.img
diff --git a/scripts/create-vms-cord.sh b/scripts/create-vms-cord.sh
index 953ca3d..c00eacb 100755
--- a/scripts/create-vms-cord.sh
+++ b/scripts/create-vms-cord.sh
@@ -1,5 +1,21 @@
 #!/bin/bash
 
+TESTING=false
+
+while [[ $# > 0 ]]
+do
+key="$1"
+
+case $key in
+    --testing)
+    TESTING=true
+    ;;
+    *)
+    ;;
+esac
+shift
+done
+
 function create-vm {
 	NAME=$1
 	CPU=$2
@@ -8,7 +24,13 @@
 	uvt-kvm list | grep $1
 	if [ "$?" -ne "0" ]
 	then
-		uvt-kvm create $NAME --cpu=$CPU --memory=$MEM_MB --disk=$DISK_GB --bridge mgmtbr
+		if $TESTING
+		then
+			# Don't use mgmtbr for testing
+			uvt-kvm create $NAME --cpu=$CPU --memory=$MEM_MB --disk=$DISK_GB
+		else
+			uvt-kvm create $NAME --cpu=$CPU --memory=$MEM_MB --disk=$DISK_GB --bridge mgmtbr
+		fi
 		uvt-kvm wait --insecure $NAME
 	fi
 }
@@ -19,8 +41,14 @@
 create-vm keystone 2 4096 40
 create-vm glance 2 4096 160
 create-vm nova-cloud-controller 2 4096 40
-create-vm neutron-gateway 2 4096 40
 create-vm neutron-api 2 4096 40
 create-vm openstack-dashboard 1 2048 20
 create-vm ceilometer 1 2048 20
 create-vm nagios 1 2048 20
+
+create-vm xos 2 4096 40
+create-vm onos-cord 2 4096 40
+if $TESTING
+then
+	create-vm nova-compute 2 4096 100
+fi
diff --git a/scripts/juju-cord-setup.py b/scripts/juju-cord-setup.py
index ba19ffd..418aab2 100755
--- a/scripts/juju-cord-setup.py
+++ b/scripts/juju-cord-setup.py
@@ -6,7 +6,7 @@
 
 # Assumption: VMs have same hostname as service that runs inside
 machines = ["mysql", "rabbitmq-server", "keystone", "glance", "nova-cloud-controller",
-            "neutron-gateway", "openstack-dashboard", "ceilometer", "nagios", "neutron-api"]
+            "openstack-dashboard", "ceilometer", "nagios", "neutron-api"]
 
 
 # Figure out Juju ID of machine we should install on
diff --git a/tasks/vm-ips-cord.yml b/tasks/vm-ips-cord.yml
new file mode 100644
index 0000000..3fb6d5d
--- /dev/null
+++ b/tasks/vm-ips-cord.yml
@@ -0,0 +1,40 @@
+---
+- shell: uvt-kvm ip juju
+  register: juju_ip
+
+- shell: uvt-kvm ip mysql
+  register: mysql_ip
+
+- shell: uvt-kvm ip rabbitmq-server
+  register: rabbitmq_ip
+
+- shell: uvt-kvm ip keystone
+  register: keystone_ip
+
+- shell: uvt-kvm ip glance
+  register: glance_ip
+
+- shell: uvt-kvm ip nova-cloud-controller
+  register: novacc_ip
+
+- shell: uvt-kvm ip openstack-dashboard
+  register: horizon_ip
+
+- shell: uvt-kvm ip nagios
+  register: nagios_ip
+
+- shell: uvt-kvm ip ceilometer
+  register: ceilometer_ip
+
+- shell: uvt-kvm ip neutron-api
+  register: neutron_api_ip
+
+- shell: uvt-kvm ip xos
+  register: xos_ip
+
+- shell: uvt-kvm ip onos-cord
+  register: onos_cord_ip
+
+- shell: uvt-kvm ip nova-compute
+  register: nova_compute_ip
+  when: test_setup is defined
diff --git a/cord.yaml b/templates/cord.yaml
similarity index 80%
rename from cord.yaml
rename to templates/cord.yaml
index 08f9cfb..1efb0b0 100644
--- a/cord.yaml
+++ b/templates/cord.yaml
@@ -19,13 +19,9 @@
     constraints: arch=amd64
   '10':
     constraints: arch=amd64
-  '11':
-    constraints: arch=amd64
 relations:
 - - nova-compute:amqp
   - rabbitmq-server:amqp
-- - neutron-gateway:amqp
-  - rabbitmq-server:amqp
 - - keystone:shared-db
   - mysql:shared-db
 - - nova-cloud-controller:identity-service
@@ -34,14 +30,10 @@
   - keystone:identity-service
 - - neutron-api:identity-service
   - keystone:identity-service
-- - neutron-openvswitch:neutron-plugin-api
-  - neutron-api:neutron-plugin-api
 - - neutron-api:shared-db
   - mysql:shared-db
 - - neutron-api:amqp
   - rabbitmq-server:amqp
-- - neutron-gateway:neutron-plugin-api
-  - neutron-api:neutron-plugin-api
 - - glance:shared-db
   - mysql:shared-db
 - - glance:amqp
@@ -54,12 +46,6 @@
   - nova-compute:cloud-compute
 - - nova-cloud-controller:amqp
   - rabbitmq-server:amqp
-- - nova-cloud-controller:quantum-network-service
-  - neutron-gateway:quantum-network-service
-- - nova-compute:neutron-plugin
-  - neutron-openvswitch:neutron-plugin
-- - neutron-openvswitch:amqp
-  - rabbitmq-server:amqp
 - - openstack-dashboard:identity-service
   - keystone:identity-service
 - - nova-cloud-controller:shared-db
@@ -68,8 +54,6 @@
   - neutron-api:neutron-api
 - - ntp:juju-info
   - nova-compute:juju-info
-- - ntp:juju-info
-  - neutron-gateway:juju-info
 - - nagios
   - nrpe
 - - mysql:juju-info
@@ -82,8 +66,6 @@
   - nrpe
 - - nova-cloud-controller
   - nrpe
-- - neutron-gateway
-  - nrpe
 - - openstack-dashboard
   - nrpe
 - - neutron-api
@@ -114,7 +96,7 @@
     options:
       openstack-origin: cloud:trusty-kilo
     to:
-    - '8'
+    - '7'
   ceilometer-agent:
     charm: cs:trusty/ceilometer-agent-13
     num_units: 0
@@ -133,7 +115,7 @@
     annotations:
       gui-x: '500'
       gui-y: '0'
-    charm: cs:trusty/keystone-31
+    charm: cs:trusty/keystone-33
     num_units: 1
     options:
       admin-password: 'ADMIN_PASS'
@@ -147,7 +129,7 @@
     charm: cs:trusty/mongodb-33
     num_units: 1
     to:
-    - '8'
+    - '7'
   mysql:
     annotations:
       gui-x: '0'
@@ -162,35 +144,21 @@
     charm: cs:trusty/nagios-10
     num_units: 1
     to:
-    - '9'
+    - '8'
   neutron-api:
     annotations:
       gui-x: '500'
       gui-y: '500'
-    charm: cs:trusty/neutron-api-21
+    charm: cs:~cordteam/trusty/neutron-api-1
     num_units: 1
     options:
-      #neutron-security-groups: true
+      neutron-plugin: onosvtn
+      onos-vtn-ip: {{ onos_cord_ip.stdout }}
+      neutron-security-groups: true
       openstack-origin: cloud:trusty-kilo
+      overlay-network-type: vxlan
     to:
-    - '10'
-  neutron-gateway:
-    annotations:
-      gui-x: '0'
-      gui-y: '0'
-    charm: cs:trusty/neutron-gateway-7
-    num_units: 1
-    options:
-      #ext-port: eth1
-      openstack-origin: cloud:trusty-kilo
-    to:
-    - '6'
-  neutron-openvswitch:
-    annotations:
-      gui-x: '250'
-      gui-y: '500'
-    charm: cs:trusty/neutron-openvswitch-13
-    num_units: 0
+    - '9'
   nova-cloud-controller:
     annotations:
       gui-x: '0'
@@ -198,7 +166,7 @@
     charm: cs:trusty/nova-cloud-controller-64
     num_units: 1
     options:
-      config-flags: "force_config_drive = always"
+      config-flags: "force_config_drive=always"
       console-access-protocol: novnc
       network-manager: Neutron
       openstack-origin: cloud:trusty-kilo
@@ -220,7 +188,7 @@
       openstack-origin: cloud:trusty-kilo
       #manage-neutron-plugin-legacy-mode: False
     to:
-    - '11'
+    - '10'
   nrpe:
     charm: cs:trusty/nrpe-4
     num_units: 0
@@ -239,7 +207,7 @@
     options:
       openstack-origin: cloud:trusty-kilo
     to:
-    - '7'
+    - '6'
   rabbitmq-server:
     annotations:
       gui-x: '500'
diff --git a/templates/etc/ansible/cord-hosts.j2 b/templates/etc/ansible/cord-hosts.j2
new file mode 100644
index 0000000..6379422
--- /dev/null
+++ b/templates/etc/ansible/cord-hosts.j2
@@ -0,0 +1,16 @@
+[localhost]
+127.0.0.1 hostname={{ ansible_fqdn }}
+
+[services]
+juju
+mysql
+rabbitmq-server
+keystone
+glance
+nova-cloud-controller
+openstack-dashboard
+ceilometer
+nagios
+neutron-api
+xos
+onos-cord
diff --git a/templates/etc/cord-hosts.j2 b/templates/etc/cord-hosts.j2
new file mode 100644
index 0000000..3dc570e
--- /dev/null
+++ b/templates/etc/cord-hosts.j2
@@ -0,0 +1,22 @@
+127.0.0.1	localhost
+127.0.1.1	ubuntu
+{{ juju_ip.stdout }} juju
+{{ mysql_ip.stdout }} mysql
+{{ rabbitmq_ip.stdout }} rabbitmq-server
+{{ keystone_ip.stdout }} keystone
+{{ glance_ip.stdout }} glance
+{{ novacc_ip.stdout }} nova-cloud-controller
+{{ horizon_ip.stdout }} openstack-dashboard
+{{ ceilometer_ip.stdout }} ceilometer
+{{ nagios_ip.stdout }} nagios
+{{ neutron_api_ip.stdout}} neutron-api
+{{ xos_ip.stdout }} xos
+{{ onos_cord_ip.stdout }} onos-cord
+{% if test_setup is defined %}
+{{ nova_compute_ip.stdout }} nova-compute 
+{% endif %}
+
+# The following lines are desirable for IPv6 capable hosts
+::1     localhost ip6-localhost ip6-loopback
+ff02::1 ip6-allnodes
+ff02::2 ip6-allrouters