add support for docker bridged and host networking
diff --git a/xos/core/admin.py b/xos/core/admin.py
index 03f8c83..97e76ff 100644
--- a/xos/core/admin.py
+++ b/xos/core/admin.py
@@ -1054,7 +1054,7 @@
class SliceAdmin(XOSBaseAdmin):
form = SliceForm
- fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_instances', "default_isolation"]
+ fieldList = ['backend_status_text', 'site', 'name', 'serviceClass', 'enabled','description', 'service', 'slice_url', 'max_instances', "default_isolation", "network"]
fieldsets = [('Slice Details', {'fields': fieldList, 'classes':['suit-tab suit-tab-general']}),]
readonly_fields = ('backend_status_text', )
list_display = ('backend_status_icon', 'name', 'site','serviceClass', 'slice_url', 'max_instances')
diff --git a/xos/openstack_observer/steps/sync_container.py b/xos/openstack_observer/steps/sync_container.py
index 039fb55..adb81c9 100644
--- a/xos/openstack_observer/steps/sync_container.py
+++ b/xos/openstack_observer/steps/sync_container.py
@@ -52,51 +52,54 @@
def get_ports(self, o):
i=0
ports = []
- for port in o.ports.all():
- if (not port.ip):
- # 'unmanaged' ports may have an ip, but no mac
- # XXX: are there any ports that have a mac but no ip?
- raise DeferredException("Port on network %s is not yet ready" % port.network.name)
+ if (o.slice.network in ["host", "bridged"]):
+ pass # no ports in host or bridged mode
+ else:
+ for port in o.ports.all():
+ if (not port.ip):
+ # 'unmanaged' ports may have an ip, but no mac
+ # XXX: are there any ports that have a mac but no ip?
+ raise DeferredException("Port on network %s is not yet ready" % port.network.name)
- pd={}
- pd["mac"] = port.mac or ""
- pd["ip"] = port.ip or ""
- pd["xos_network_id"] = port.network.id
+ pd={}
+ pd["mac"] = port.mac or ""
+ pd["ip"] = port.ip or ""
+ pd["xos_network_id"] = port.network.id
- if port.network.name == "wan_network":
- if port.ip:
- (a, b, c, d) = port.ip.split('.')
- pd["mac"] = "02:42:%02x:%02x:%02x:%02x" % (int(a), int(b), int(c), int(d))
+ if port.network.name == "wan_network":
+ if port.ip:
+ (a, b, c, d) = port.ip.split('.')
+ pd["mac"] = "02:42:%02x:%02x:%02x:%02x" % (int(a), int(b), int(c), int(d))
- if o.isolation == "container":
- # container on bare metal
- instance_port = self.get_instance_port(port)
- if not instance_port:
- raise DeferredException("No instance on slice for port on network %s" % port.network.name)
+ if o.isolation == "container":
+ # container on bare metal
+ instance_port = self.get_instance_port(port)
+ if not instance_port:
+ raise DeferredException("No instance on slice for port on network %s" % port.network.name)
- pd["snoop_instance_mac"] = instance_port.mac
- pd["snoop_instance_id"] = instance_port.instance.instance_id
- pd["src_device"] = ""
- pd["bridge"] = "br-int"
- else:
- # container in VM
- pd["snoop_instance_mac"] = ""
- pd["snoop_instance_id"] = ""
- pd["parent_mac"] = self.get_parent_port_mac(o, port)
- pd["bridge"] = ""
+ pd["snoop_instance_mac"] = instance_port.mac
+ pd["snoop_instance_id"] = instance_port.instance.instance_id
+ pd["src_device"] = ""
+ pd["bridge"] = "br-int"
+ else:
+ # container in VM
+ pd["snoop_instance_mac"] = ""
+ pd["snoop_instance_id"] = ""
+ pd["parent_mac"] = self.get_parent_port_mac(o, port)
+ pd["bridge"] = ""
- for (k,v) in port.get_parameters().items():
- pd[k] = v
+ for (k,v) in port.get_parameters().items():
+ pd[k] = v
- ports.append(pd)
+ ports.append(pd)
- # for any ports that don't have a device, assign one
- used_ports = [x["device"] for x in ports if ("device" in x)]
- avail_ports = ["eth%d"%i for i in range(0,64) if ("eth%d"%i not in used_ports)]
- for port in ports:
- if not port.get("device",None):
- port["device"] = avail_ports.pop(0)
+ # for any ports that don't have a device, assign one
+ used_ports = [x["device"] for x in ports if ("device" in x)]
+ avail_ports = ["eth%d"%i for i in range(0,64) if ("eth%d"%i not in used_ports)]
+ for port in ports:
+ if not port.get("device",None):
+ port["device"] = avail_ports.pop(0)
return ports
@@ -112,6 +115,7 @@
fields["volumes"] = [x.strip() for x in o.volumes.split(",")]
else:
fields["volumes"] = ""
+ fields["network_method"] = o.slice.network or "default"
return fields
def sync_record(self, o):
diff --git a/xos/openstack_observer/steps/sync_container.yaml b/xos/openstack_observer/steps/sync_container.yaml
index b60ffb8..77e57cd 100644
--- a/xos/openstack_observer/steps/sync_container.yaml
+++ b/xos/openstack_observer/steps/sync_container.yaml
@@ -8,6 +8,7 @@
vars:
container_name: {{ container_name }}
docker_image: {{ docker_image }}
+ network_method: {{ network_method }}
ports:
{% for port in ports %}
- device: {{ port.device }}
diff --git a/xos/openstack_observer/templates/start-container.sh.j2 b/xos/openstack_observer/templates/start-container.sh.j2
index 260666c..2fbf478 100644
--- a/xos/openstack_observer/templates/start-container.sh.j2
+++ b/xos/openstack_observer/templates/start-container.sh.j2
@@ -44,7 +44,13 @@
if [ "$?" == 1 ]
then
docker pull $IMAGE
+{% if network_method=="host" %}
+ docker run -d --name=$CONTAINER --privileged=true --net=host $VOLUME_ARGS $IMAGE
+{% elif network_method=="bridged" %}
+ docker run -d --name=$CONTAINER --privileged=true --net=bridge $VOLUME_ARGS $IMAGE
+{% else %}
docker run -d --name=$CONTAINER --privileged=true --net=none $VOLUME_ARGS $IMAGE
+{% endif %}
else
docker start $CONTAINER
fi