Merge branch 'config-refactored'
diff --git a/containers/synchronizer/Dockerfile b/containers/synchronizer/Dockerfile
index 187168c..011e8dd 100644
--- a/containers/synchronizer/Dockerfile
+++ b/containers/synchronizer/Dockerfile
@@ -1,6 +1,5 @@
 FROM       xosproject/xos
 
-# Install custom Ansible
 RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y \
     openssh-client \
     python-crypto \
@@ -8,11 +7,13 @@
     python-paramiko \
     python-yaml \
     python-httplib2 \
+    rsync \
     supervisor
 
 RUN pip install -U \
     jinja2
 
+# Install custom Ansible
 RUN \
     git clone -b release1.8.2 git://github.com/ansible/ansible.git /opt/ansible && \
     git clone -b release1.8.2 git://github.com/ansible/ansible-modules-extras.git /opt/ansible/lib/ansible/modules/extras && \
diff --git a/containers/xos/Dockerfile b/containers/xos/Dockerfile
index dc9a638..c70085f 100644
--- a/containers/xos/Dockerfile
+++ b/containers/xos/Dockerfile
@@ -42,7 +42,7 @@
     django-crispy-forms \
     django-encrypted-fields \
     django-extensions \
-    django-filter \
+    django-filter==0.11.0 \
     django-geoposition \
     django-ipware \
     django_rest_swagger \
diff --git a/containers/xos/Dockerfile.templ b/containers/xos/Dockerfile.templ
index 216ceb5..4bb201e 100644
--- a/containers/xos/Dockerfile.templ
+++ b/containers/xos/Dockerfile.templ
@@ -43,7 +43,7 @@
     django-encrypted-fields \
     django_evolution \
     django-extensions \
-    django-filter \
+    django-filter==0.11.0 \
     django-geoposition \
     django-ipware \
     django_rest_swagger \
diff --git a/xos/configurations/common/Dockerfile.common b/xos/configurations/common/Dockerfile.common
index d78585a..ac8931f 100644
--- a/xos/configurations/common/Dockerfile.common
+++ b/xos/configurations/common/Dockerfile.common
@@ -34,7 +34,7 @@
 RUN pip install djangorestframework==2.4.4
 RUN pip install markdown  # Markdown support for the browseable API.
 RUN pip install pyyaml    # YAML content-type support.
-RUN pip install django-filter  # Filtering support
+RUN pip install django-filter==0.11.0  # Filtering support
 RUN pip install lxml  # XML manipulation library
 RUN pip install netaddr # IP Addr library
 RUN pip install pytz
diff --git a/xos/configurations/cord/README-VTN.md b/xos/configurations/cord/README-VTN.md
index ffb5d56..9827b0e 100644
--- a/xos/configurations/cord/README-VTN.md
+++ b/xos/configurations/cord/README-VTN.md
@@ -47,7 +47,8 @@
     # change 172.17.0.2 to the IP address for the ONOS container (use "docker inspect")
     iptables -t nat -A PREROUTING -i br-ex -p tcp --dport 8101 -j DNAT --to-destination 172.17.0.2
     iptables -t nat -A PREROUTING -i br-ex -p tcp --dport 8181 -j DNAT --to-destination 172.17.0.2
-
+    iptables -t nat -A PREROUTING -i br-ex -p tcp --dport 6653 -j DNAT --to-destination 172.17.0.2
+    
 Compute nodes (all of them):
 
     systemctl stop neutron-plugin-openvswitch-agent
@@ -71,3 +72,4 @@
 
 Notes:
 * Adding use_vtn=True to the [networking] section in the XOS config file has two effects: 1) it sets the gateway in sync_controller_networks, and 2) it disables automatic creation of nat-net for new slices. This is because VTN will fail if there is no gateway on a network, and because we don't have nat-net under the VTN configuration.
+* When using of-vfctl to look at flow rules, if you get a protocol error, try "ovs-ofctl show -O OpenFlow13 br-int "
diff --git a/xos/configurations/cord/dataplane/change_controller.sh b/xos/configurations/cord/dataplane/change_controller.sh
new file mode 100755
index 0000000..2b961ee
--- /dev/null
+++ b/xos/configurations/cord/dataplane/change_controller.sh
@@ -0,0 +1,13 @@
+#! /bin/bash
+
+# put IP address of node running ONOS VTN App here
+DESIRED_CONTROLLER="tcp:130.127.133.24:6653"
+
+while [[ 1 ]]; do
+    CONTROLLER=`ovs-vsctl get-controller br-int`
+    if [[ "$CONTROLLER" == "tcp:172.17.0.2:6653" ]]; then
+       ovs-vsctl set-controller br-int $DESIRED_CONTROLLER
+       echo "changed controller from $CONTROLLER to $DESIRED_CONTROLLER"
+    fi
+    sleep 10s
+done
diff --git a/xos/configurations/cord/dataplane/dataplane-vtn.yaml b/xos/configurations/cord/dataplane/dataplane-vtn.yaml
new file mode 100644
index 0000000..c53bd1e
--- /dev/null
+++ b/xos/configurations/cord/dataplane/dataplane-vtn.yaml
@@ -0,0 +1,23 @@
+---
+- hosts: baremetal
+
+  user: root
+  sudo: no
+  tasks:
+  - name: stop neutron openvswitch agent
+    service: name=neutron-plugin-openvswitch-agent state=stopped
+
+  - name: Update openvswitch config
+    lineinfile:
+      dest=/usr/share/openvswitch/scripts/ovs-ctl
+      insertafter="set ovsdb-server.*DB_FILE.*"
+      regexp=".*set.*--remote=ptcp.*"
+      line="        set \"$@\" --remote=ptcp:6641"
+      state=present
+
+  - name: Restart openvswitch
+    service: name=openvswitch-switch state=restarted
+
+  - name: Delete br-int
+    shell: ovs-vsctl show | grep -i br-int > /dev/null && ovs-vsctl del-br br-int
+    ignore_errors: yes
\ No newline at end of file
diff --git a/xos/configurations/cord/dataplane/generate-bm.sh b/xos/configurations/cord/dataplane/generate-bm.sh
index e6053dc..2ead7ed 100755
--- a/xos/configurations/cord/dataplane/generate-bm.sh
+++ b/xos/configurations/cord/dataplane/generate-bm.sh
@@ -29,9 +29,14 @@
 
 echo switch_volt ansible_ssh_host=$( get_ip mysite_volt flat-lan-1-net) grenames=\"$GRE_NAMES\" bm_ips=\"$BM_IPS\"
 
+# now for the network management node
+NM=`grep "^nm" /root/setup/fqdn.map | awk '{ print $2 }'`
+echo "nm $NM"
+
 echo "[baremetal]"
 I=1
 for NODE in $NODES; do
     echo bm$I
     I=$((I+1))
 done
+
diff --git a/xos/configurations/cord/make-vtn-networkconfig-json.sh b/xos/configurations/cord/make-vtn-networkconfig-json.sh
index b35c440..c4506cc 100755
--- a/xos/configurations/cord/make-vtn-networkconfig-json.sh
+++ b/xos/configurations/cord/make-vtn-networkconfig-json.sh
@@ -27,7 +27,7 @@
                     {
                       "hostname": "$NODE",
                       "ovsdbIp": "$NODEIP",
-                      "ovsdbPort": "6640",
+                      "ovsdbPort": "6641",
                       "bridgeId": "of:000000000000000$I"
 EOF
     if [[ "$I" -lt "$NODECOUNT" ]]; then
@@ -46,7 +46,7 @@
 
 cat >> $FN <<EOF
                 ]
-            }

+            }
         },
         "org.onosproject.openstackswitching" : {
             "openstackswitching" : {
diff --git a/xos/observers/base/SyncInstanceUsingAnsible.py b/xos/observers/base/SyncInstanceUsingAnsible.py
index 373178c..81f6632 100644
--- a/xos/observers/base/SyncInstanceUsingAnsible.py
+++ b/xos/observers/base/SyncInstanceUsingAnsible.py
@@ -113,7 +113,7 @@
             key_name = instance.parent.slice.service.private_key_fn
 
         if not os.path.exists(key_name):
-            raise Exception("Node key %s does not exist" % node_key_name)
+            raise Exception("Node key %s does not exist" % key_name)
 
         key = file(key_name).read()
 
@@ -219,4 +219,3 @@
                 self.map_delete_outputs(o,res)
         except AttributeError:
                 pass
-
diff --git a/xos/observers/monitoring_channel/monitoring_channel_observer_config b/xos/observers/monitoring_channel/monitoring_channel_observer_config
index 922a019..5657e1d 100644
--- a/xos/observers/monitoring_channel/monitoring_channel_observer_config
+++ b/xos/observers/monitoring_channel/monitoring_channel_observer_config
@@ -32,7 +32,8 @@
 pretend=False
 backoff_disabled=True
 save_ansible_output=True
-proxy_ssh=True
+# set proxy_ssh to false on cloudlab
+proxy_ssh=False
 full_setup=True
 
 [feefie]
diff --git a/xos/observers/onos/scripts/dockerip.sh b/xos/observers/onos/scripts/dockerip.sh
index 4bf355d..732c3fe 100644
--- a/xos/observers/onos/scripts/dockerip.sh
+++ b/xos/observers/onos/scripts/dockerip.sh
@@ -1,4 +1,9 @@
-#!/bin/sh
+#!/bin/bash
 
-docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1 | tr -d '\n' | tr -d '\r'
+MODE=`docker inspect --format '{{ .HostConfig.NetworkMode }}' $1  | tr -d '\n' | tr -d '\r'`
+if [[ "$MODE" == "host" ]]; then
+    echo -n "127.0.0.1"
+else
+    docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1 | tr -d '\n' | tr -d '\r'
+fi
 
diff --git a/xos/observers/onos/steps/sync_onosapp.py b/xos/observers/onos/steps/sync_onosapp.py
index 0feb2e5..cfe1041 100644
--- a/xos/observers/onos/steps/sync_onosapp.py
+++ b/xos/observers/onos/steps/sync_onosapp.py
@@ -1,6 +1,7 @@
 import hashlib
 import os
 import socket
+import socket
 import sys
 import base64
 import time
@@ -73,6 +74,19 @@
 
         return os.path.join(step_dir, "..", "files", str(self.get_onos_service(o).id), o.name)
 
+    def get_cluster_configuration(self, o):
+        instance = self.get_instance(o)
+        if not instance:
+           raise "No instance for ONOS App"
+        node_ips = [socket.gethostbyname(instance.node.name)]
+
+        ipPrefix = ".".join(node_ips[0].split(".")[:3]) + ".*"
+        result = '{ "nodes": ['
+        result = result + ",".join(['{ "ip": "%s"}' % ip for ip in node_ips])
+        result = result + '], "ipPrefix": "%s"}' % ipPrefix
+        return result
+
+
     def write_configs(self, o):
         o.config_fns = []
         o.rest_configs = []
@@ -86,7 +100,23 @@
         attrs = o.provider_service.serviceattribute_dict
         attrs.update(o.tenantattribute_dict)
 
-        for (name, value) in attrs.items():
+        ordered_attrs = attrs.keys()
+
+        o.early_rest_configs=[]
+        if ("cordvtn" in o.dependencies):
+            # For VTN, since it's running in a docker host container, we need
+            # to make sure it configures the cluster using the right ip addresses.
+            # NOTE: rest_onos/v1/cluster/configuration/ will reboot the cluster and
+            #   must go first.
+            name="rest_onos/v1/cluster/configuration/"
+            value= self.get_cluster_configuration(o)
+            fn = name[5:].replace("/","_")
+            endpoint = name[5:]
+            file(os.path.join(o.files_dir, fn),"w").write(" " +value)
+            o.early_rest_configs.append( {"endpoint": endpoint, "fn": fn} )
+
+        for name in attrs.keys():
+            value = attrs[name]
             if name.startswith("config_"):
                 fn = name[7:] # .replace("_json",".json")
                 o.config_fns.append(fn)
@@ -114,6 +144,7 @@
         fields["nat_ip"] = instance.get_ssh_ip()
         fields["config_fns"] = o.config_fns
         fields["rest_configs"] = o.rest_configs
+        fields["early_rest_configs"] = o.early_rest_configs
         if o.dependencies:
             fields["dependencies"] = [x.strip() for x in o.dependencies.split(",")]
         else:
diff --git a/xos/observers/onos/steps/sync_onosapp.yaml b/xos/observers/onos/steps/sync_onosapp.yaml
index 496fad0..a03368b 100644
--- a/xos/observers/onos/steps/sync_onosapp.yaml
+++ b/xos/observers/onos/steps/sync_onosapp.yaml
@@ -14,6 +14,13 @@
          body: "{{ '{{' }} lookup('file', '{{ files_dir }}/{{ rest_config.fn }}') {{ '}}' }}"
 {% endfor %}
 {% endif %}
+{% if early_rest_configs %}
+    early_rest_configs:
+{% for early_rest_config in early_rest_configs %}
+       - endpoint: {{ early_rest_config.endpoint }}
+         body: "{{ '{{' }} lookup('file', '{{ files_dir }}/{{ early_rest_config.fn }}') {{ '}}' }}"
+{% endfor %}
+{% endif %}
 
   tasks:
 
@@ -63,6 +70,22 @@
   - name: Wait for ONOS to install the apps
     wait_for: timeout=15
 
+{% if early_rest_configs %}
+  - name: Add ONOS early configuration values
+    uri:
+      url: http://{{ '{{' }} onosaddr.stdout {{ '}}' }}:8181/{{ '{{' }} item.endpoint {{ '}}' }}
+      body: "{{ '{{' }} item.body {{ '}}' }}"
+      body_format: raw
+      method: POST
+      user: karaf
+      password: karaf
+    with_items: "early_rest_configs"
+
+  # Don't know how to check for this condition, just wait
+  - name: Wait for ONOS to restart
+    wait_for: timeout=15
+{% endif %}
+
 {% if dependencies %}
   - name: Add dependencies to ONOS
     uri:
diff --git a/xos/observers/vcpe/vcpe_observer_config b/xos/observers/vcpe/vcpe_observer_config
index afd1501..d2c9239 100644
--- a/xos/observers/vcpe/vcpe_observer_config
+++ b/xos/observers/vcpe/vcpe_observer_config
@@ -33,7 +33,8 @@
 pretend=False
 backoff_disabled=True
 save_ansible_output=True
-proxy_ssh=True
+# set proxy_ssh to false on cloudlab
+proxy_ssh=False
 full_setup=True
 
 [feefie]
diff --git a/xos/tosca/samples/vtn.yaml b/xos/tosca/samples/vtn.yaml
index 38db047..4683b70 100644
--- a/xos/tosca/samples/vtn.yaml
+++ b/xos/tosca/samples/vtn.yaml
@@ -56,7 +56,7 @@
               node: docker-onos
               relationship: tosca.relationships.UsesImage
       properties:
-          network: bridged
+          network: host
           default_isolation: container
 
     # Virtual machines