start adding ability to delete ports from openstack
diff --git a/xos/core/models/network.py b/xos/core/models/network.py
index 0dc6d4a..8103ba3 100644
--- a/xos/core/models/network.py
+++ b/xos/core/models/network.py
@@ -259,6 +259,7 @@
ip = models.GenericIPAddressField(help_text="Instance ip address", blank=True, null=True)
port_id = models.CharField(null=True, blank=True, max_length=256, help_text="Neutron port id")
mac = models.CharField(null=True, blank=True, max_length=256, help_text="MAC address associated with this port")
+ xos_created = models.BooleanField(default=False) # True if XOS created this port in Neutron, False if port created by Neutron and observed by XOS
class Meta:
unique_together = ('network', 'instance')
diff --git a/xos/model_autodeletion.py b/xos/model_autodeletion.py
index 2bfc48c..6eaf63c 100644
--- a/xos/model_autodeletion.py
+++ b/xos/model_autodeletion.py
@@ -1 +1 @@
-ephemeral_models = ['ReservedResource','Instance','Image','Network','Port','Tag','SitePrivilege','SliceMembership','SliceTag','Reservation','Slice']
+ephemeral_models = ['ReservedResource','Instance','Image','Network','Tag','SitePrivilege','SliceMembership','SliceTag','Reservation','Slice']
diff --git a/xos/synchronizers/openstack/steps/sync_ports.py b/xos/synchronizers/openstack/steps/sync_ports.py
index 3289ece..b8dc85e 100644
--- a/xos/synchronizers/openstack/steps/sync_ports.py
+++ b/xos/synchronizers/openstack/steps/sync_ports.py
@@ -16,8 +16,14 @@
# has, and then work backward from each port's network-id to determine
# which Network is associated from the port.
- def call(self, **args):
- logger.info("sync'ing network instances")
+ def call(self, failed=[], deletion=False):
+ if deletion:
+ self.delete_ports()
+ else:
+ self.sync_ports()
+
+ def sync_ports(self):
+ logger.info("sync'ing Ports [delete=False]")
ports = Port.objects.all()
ports_by_id = {}
@@ -190,12 +196,20 @@
if neutron_port["fixed_ips"]:
port.ip = neutron_port["fixed_ips"][0]["ip_address"]
port.mac = neutron_port["mac_address"]
+ port.xos_created = True
except:
logger.log_exc("failed to create neutron port for %s" % port)
continue
port.save()
- def delete_record(self, network_instance):
- # Nothing to do, this is an OpenCloud object
- pass
+ def delete_ports(self):
+ logger.info("sync'ing Ports [delete=True]")
+ for port in Port.deleted_objects.all():
+ self.delete_record(port)
+
+ def delete_record(self, port):
+ if port.xos_created:
+ logger.info("calling openstack to destroy port %s" % port.port_id)
+ logger.info("Purging port %s" % port)
+ port.delete(purge=True)