create vSG lan port when Instance is created
diff --git a/xos/configurations/common/fixtures.yaml b/xos/configurations/common/fixtures.yaml
index c5e9dd1..6419211 100644
--- a/xos/configurations/common/fixtures.yaml
+++ b/xos/configurations/common/fixtures.yaml
@@ -21,3 +21,6 @@
bridge:
type: tosca.nodes.NetworkParameterType
+
+ neutron_port_name:
+ type: tosca.nodes.NetworkParameterType
diff --git a/xos/services/cord/models.py b/xos/services/cord/models.py
index 0dc1df5..6d26048 100644
--- a/xos/services/cord/models.py
+++ b/xos/services/cord/models.py
@@ -674,6 +674,7 @@
flavor = flavors[0],
isolation = slice.default_isolation,
parent = parent)
+
self.save_instance(instance)
return instance
@@ -729,16 +730,23 @@
port.save()
return port
+ def get_lan_network(self, instance):
+ # TODO: for VTN, pick the access network
+
+ slice = self.provider_service.slices.all()[0]
+ lan_networks = [x for x in slice.networks.all() if "lan" in x.name]
+ if not lan_networks:
+ raise XOSProgrammingError("No lan_network")
+ return lan_networks[0]
+
def save_instance(self, instance):
with transaction.atomic():
instance.volumes = "/etc/dnsmasq.d,/etc/ufw"
super(VSGTenant, self).save_instance(instance)
if instance.isolation in ["container", "container_vm"]:
- lan_networks = [x for x in instance.slice.networks.all() if "lan" in x.name]
- if not lan_networks:
- raise XOSProgrammingError("No lan_network")
- port = self.find_or_make_port(instance, lan_networks[0], ip="192.168.0.1", port_id="unmanaged")
+ lan_network = self.get_lan_network(instance)
+ port = self.find_or_make_port(instance, lan_network, ip="192.168.0.1", port_id="unmanaged")
port.set_parameter("c_tag", self.volt.c_tag)
port.set_parameter("s_tag", self.volt.s_tag)
port.set_parameter("device", "eth1")
@@ -751,6 +759,14 @@
port.set_parameter("next_hop", value="10.0.1.253") # FIX ME
port.set_parameter("device", "eth0")
+ if instance.isolation in ["vm"]:
+ lan_network = self.get_lan_network(instance)
+ port = self.find_or_make_port(instance, lan_network)
+ port.set_parameter("c_tag", self.volt.c_tag)
+ port.set_parameter("s_tag", self.volt.s_tag)
+ port.set_parameter("neutron_port_name", "stag-%s" % self.volt.s_tag)
+ port.save()
+
# tag the instance with the s-tag, so we can easily find the
# instance later
if self.volt and self.volt.s_tag:
diff --git a/xos/synchronizers/openstack/steps/sync_instances.py b/xos/synchronizers/openstack/steps/sync_instances.py
index 22aa45c..73624a3 100644
--- a/xos/synchronizers/openstack/steps/sync_instances.py
+++ b/xos/synchronizers/openstack/steps/sync_instances.py
@@ -84,8 +84,18 @@
if instance.slice.service and instance.slice.service.public_key:
pubkeys.add(instance.slice.service.public_key)
+ # handle ports the were created by the user
+ port_ids=[]
+ for port in Port.objects.filter(instance=instance):
+ if not port.port_id:
+ raise DeferredException("Instance %s waiting on port %s" % (instance, port))
+ port_ids.append(port.port_id)
+
+ # we want to exclude from 'nics' any network that already has a Port
+ existing_port_networks = [port.network for network in Port.objects.filter(instance=instance)]
+
nics = []
- networks = [ns.network for ns in NetworkSlice.objects.filter(slice=instance.slice)]
+ networks = [ns.network for ns in NetworkSlice.objects.filter(slice=instance.slice) if ns.network not in existing_port_networks]
controller_networks = ControllerNetwork.objects.filter(network__in=networks,
controller=instance.node.site_deployment.controller)
diff --git a/xos/synchronizers/openstack/steps/sync_ports.py b/xos/synchronizers/openstack/steps/sync_ports.py
index 21376e5..3289ece 100644
--- a/xos/synchronizers/openstack/steps/sync_ports.py
+++ b/xos/synchronizers/openstack/steps/sync_ports.py
@@ -180,7 +180,12 @@
client = OpenStackClient(controller=controller, **auth) # cacert=self.config.nova_ca_ssl_cert,
driver = OpenStackDriver(client=client)
- neutron_port = driver.shell.quantum.create_port({"port": {"network_id": cn.net_id}})["port"]
+ args = {"network_id": cn.net_id}
+ neutron_port_name = port.get_parameters().get("neutron_port_name", None)
+ if neutron_port_name:
+ args["name"] = neutron_port_name
+
+ neutron_port = driver.shell.quantum.create_port({"port": args})["port"]
port.port_id = neutron_port["id"]
if neutron_port["fixed_ips"]:
port.ip = neutron_port["fixed_ips"][0]["ip_address"]