match up parent interfaces in container_vm the right way
diff --git a/xos/openstack_observer/steps/sync_container.py b/xos/openstack_observer/steps/sync_container.py
index fefd415..685b778 100644
--- a/xos/openstack_observer/steps/sync_container.py
+++ b/xos/openstack_observer/steps/sync_container.py
@@ -39,6 +39,16 @@
                 return p
         return None
 
+    def get_parent_port_mac(self, instance, port):
+        if not instance.parent:
+            raise Exception("instance has no parent")
+        for parent_port in instance.parent.ports.all():
+            if parent_port.network == port.network:
+                if not parent_port.mac:
+                     raise Exception("parent port on network %s does not have mac yet" % parent_port.network.name)
+                return parent_port.mac
+        raise Exception("failed to find corresponding parent port for network %s" % port.network.name)
+
     def get_ports(self, o):
         i=0
         ports = []
@@ -66,7 +76,7 @@
                 # container in VM
                 pd["snoop_instance_mac"] = ""
                 pd["snoop_instance_id"] = ""
-                pd["src_device"] = "eth%d" % i
+                pd["parent_mac"] = self.get_parent_port_mac(o, port)
 
             for (k,v) in port.get_parameters().items():
                 pd[k] = v
diff --git a/xos/openstack_observer/steps/sync_container.yaml b/xos/openstack_observer/steps/sync_container.yaml
index 7fb6331..b79bbd1 100644
--- a/xos/openstack_observer/steps/sync_container.yaml
+++ b/xos/openstack_observer/steps/sync_container.yaml
@@ -16,7 +16,7 @@
          ip: {{ port.ip }}
          snoop_instance_mac: {{ port.snoop_instance_mac }}
          snoop_instance_id: {{ port.snoop_instance_id }}
-         src_device: {{ port.src_device }}
+         parent_mac: {{ port.parent_mac|default("") }}
          s_tag: {{ port.s_tag|default("")  }}
          c_tag: {{ port.c_tag|default("") }}
          next_hop: {{ port.next_hop|default("") }}
diff --git a/xos/openstack_observer/steps/teardown_container.yaml b/xos/openstack_observer/steps/teardown_container.yaml
index eee38ca..de90e9e 100644
--- a/xos/openstack_observer/steps/teardown_container.yaml
+++ b/xos/openstack_observer/steps/teardown_container.yaml
@@ -16,7 +16,7 @@
          ip: {{ port.ip }}
          snoop_instance_mac: {{ port.snoop_instance_mac }}
          snoop_instance_id: {{ port.snoop_instance_id }}
-         src_device: {{ port.src_device }}
+         parent_mac: {{ port.parent_mac|default("") }}
          s_tag: {{ port.s_tag|default("")  }}
          c_tag: {{ port.c_tag|default("") }}
          next_hop: {{ port.next_hop|default("") }}
diff --git a/xos/openstack_observer/templates/start-container.sh.j2 b/xos/openstack_observer/templates/start-container.sh.j2
index 42d93a2..6ae1394 100644
--- a/xos/openstack_observer/templates/start-container.sh.j2
+++ b/xos/openstack_observer/templates/start-container.sh.j2
@@ -6,6 +6,11 @@
 CONTAINER={{ container_name }}
 IMAGE={{ docker_image }}
 
+function mac_to_iface {
+    PARENT_MAC=$1
+    ifconfig|grep $PARENT_MAC| awk '{print $1}'|grep -v '\.'
+}
+
 {% if volumes %}
 {% for volume in volumes %}
 DEST_DIR=/var/container_volumes/$CONTAINER/{{ volume }}
@@ -38,11 +43,10 @@
 CTAG_ARG=""
 {% endif %}
 
-{% if port.src_device %}
+{% if port.parent_mac %}
 # container-in-VM
-VLAN_ARG=""
-NEXTHOP_ARG=""
-CMD="docker exec $CONTAINER ifconfig {{ port.src_device }} >> /dev/null || pipework {{ port.src_device }} -i {{ port.device }} $CONTAINER {{ port.ip }}/24$NEXTHOP_ARG {{ port.mac }} $CTAG_ARG"
+SRC_DEV=$( mac_to_iface "{{ port.parent_mac }}" )
+CMD="docker exec $CONTAINER ifconfig $SRC_DEV >> /dev/null || pipework $SRC_DEV -i {{ port.device }} $CONTAINER {{ port.ip }}/24$NEXTHOP_ARG {{ port.mac }} $CTAG_ARG"
 echo $CMD
 eval $CMD