Controller replaces Deployment
diff --git a/planetstack/openstack_observer/steps/sync_controller_networks.py b/planetstack/openstack_observer/steps/sync_controller_networks.py
index a6fc389..bb18b39 100644
--- a/planetstack/openstack_observer/steps/sync_controller_networks.py
+++ b/planetstack/openstack_observer/steps/sync_controller_networks.py
@@ -12,21 +12,21 @@
logger = Logger(level=logging.INFO)
-class SyncNetworkDeployments(OpenStackSyncStep):
+class SyncControllerNetworks(OpenStackSyncStep):
requested_interval = 0
- provides=[Network, NetworkDeployments, Sliver]
+ provides=[Network, ControllerNetworks, Sliver]
def fetch_pending(self, deleted):
if (deleted):
- return NetworkDeployments.deleted_objects.all()
+ return ControllerNetworks.deleted_objects.all()
else:
- return NetworkDeployments.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
+ return ControllerNetworks.objects.filter(Q(enacted__lt=F('updated')) | Q(enacted=None))
- def get_next_subnet(self, deployment=None):
+ def get_next_subnet(self, controller=None):
# limit ourself to 10.0.x.x for now
valid_subnet = lambda net: net.startswith('10.0')
- driver = self.driver.admin_driver(deployment=deployment,tenant='admin')
+ driver = self.driver.admin_driver(controller=controller,tenant='admin')
subnets = driver.shell.quantum.list_subnets()['subnets']
ints = [int(IPNetwork(subnet['cidr']).ip) for subnet in subnets \
if valid_subnet(subnet['cidr'])]
@@ -39,98 +39,98 @@
next_network = IPNetwork(str(IPAddress(last_network) + last_network.size) + "/24")
return next_network
- def save_network_deployment(self, network_deployment):
- if (not network_deployment.net_id) and network_deployment.network.template.sharedNetworkName:
+ def save_controller_network(self, controller_network):
+ if (not controller_network.net_id) and controller_network.network.template.sharedNetworkName:
# It's a shared network, try to find the shared network id
- quantum_networks = self.driver.shell.quantum.list_networks(name=network_deployment.network.template.sharedNetworkName)["networks"]
+ quantum_networks = self.driver.shell.quantum.list_networks(name=controller_network.network.template.sharedNetworkName)["networks"]
if quantum_networks:
logger.info("set shared network id %s" % quantum_networks[0]["id"])
- network_deployment.net_id = quantum_networks[0]["id"]
+ controller_network.net_id = quantum_networks[0]["id"]
else:
- logger.info("failed to find shared network id for deployment")
+ logger.info("failed to find shared network id for controller")
return
# At this point, it must be a private network, so create it if it does
# not exist.
- if not network_deployment.net_id:
- network_name = network_deployment.network.name
+ if not controller_network.net_id:
+ network_name = controller_network.network.name
# create network
os_network = self.driver.create_network(network_name, shared=True)
- network_deployment.net_id = os_network['id']
+ controller_network.net_id = os_network['id']
# create router
#router = self.driver.create_router(network_name)
- #network_deployment.router_id = router['id']
+ #controller_network.router_id = router['id']
# create subnet
- next_subnet = self.get_next_subnet(deployment=network_deployment.deployment.name)
+ next_subnet = self.get_next_subnet(controller=controller_network.controller.name)
cidr = str(next_subnet.cidr)
ip_version = next_subnet.version
start = str(next_subnet[2])
end = str(next_subnet[-2])
subnet = self.driver.create_subnet(name=network_name,
- network_id = network_deployment.net_id,
+ network_id = controller_network.net_id,
cidr_ip = cidr,
ip_version = ip_version,
start = start,
end = end)
- network_deployment.subnet = cidr
- network_deployment.subnet_id = subnet['id']
+ controller_network.subnet = cidr
+ controller_network.subnet_id = subnet['id']
# add subnet as interface to slice's router
#self.driver.add_router_interface(router['id'], subnet['id'])
# add external route
#self.driver.add_external_route(subnet)
- logger.info("created private subnet (%s) for network: %s" % (cidr, network_deployment.network))
+ logger.info("created private subnet (%s) for network: %s" % (cidr, controller_network.network))
# Now, figure out the subnet and subnet_id for the network. This works
# for both private and shared networks.
- if (not network_deployment.subnet_id) or (not network_deployment.subnet):
- (network_deployment.subnet_id, network_deployment.subnet) = self.driver.get_network_subnet(network_deployment.net_id)
- logger.info("sync'ed subnet (%s) for network: %s" % (network_deployment.subnet, network_deployment.network))
+ if (not controller_network.subnet_id) or (not controller_network.subnet):
+ (controller_network.subnet_id, controller_network.subnet) = self.driver.get_network_subnet(controller_network.net_id)
+ logger.info("sync'ed subnet (%s) for network: %s" % (controller_network.subnet, controller_network.network))
- if (not network_deployment.subnet):
+ if (not controller_network.subnet):
# this will generate a non-null database constraint error
# ... which in turn leads to transaction errors
# it's probably caused by networks that no longer exist at the
# quantum level.
- logger.info("null subnet for network %s, skipping save" % network_deployment.network)
+ logger.info("null subnet for network %s, skipping save" % controller_network.network)
return
- network_deployment.save()
+ controller_network.save()
- def sync_record(self, network_deployment):
- logger.info("sync'ing network deployment %s for network %s slice %s deployment %s" % (network_deployment, network_deployment.network, str(network_deployment.network.owner), network_deployment.deployment))
+ def sync_record(self, controller_network):
+ logger.info("sync'ing network controller %s for network %s slice %s controller %s" % (controller_network, controller_network.network, str(controller_network.network.owner), controller_network.controller))
- if not network_deployment.deployment.admin_user:
- logger.info("deployment %r has no admin_user, skipping" % network_deployment.deployment)
+ if not controller_network.controller.admin_user:
+ logger.info("controller %r has no admin_user, skipping" % controller_network.controller)
return
- self.driver = self.driver.admin_driver(deployment=network_deployment.deployment,tenant='admin')
- if network_deployment.network.owner and network_deployment.network.owner.creator:
+ self.driver = self.driver.admin_driver(controller=controller_network.controller,tenant='admin')
+ if controller_network.network.owner and controller_network.network.owner.creator:
try:
# update manager context
# Bring back
- self.save_network_deployment(network_deployment)
- logger.info("saved network deployment: %s" % (network_deployment))
+ self.save_controller_network(controller_network)
+ logger.info("saved network controller: %s" % (controller_network))
except Exception,e:
- logger.log_exc("save network deployment failed: %s" % network_deployment)
+ logger.log_exc("save network controller failed: %s" % controller_network)
raise e
- def delete_record(self, network_deployment):
- driver = OpenStackDriver().client_driver(caller=network_deployment.network.owner.creator,
- tenant=network_deployment.network.owner.name,
- deployment=network_deployment.deployment.name)
- if (network_deployment.router_id) and (network_deployment.subnet_id):
- driver.delete_router_interface(network_deployment.router_id, network_deployment.subnet_id)
- if network_deployment.subnet_id:
- driver.delete_subnet(network_deployment.subnet_id)
- if network_deployment.router_id:
- driver.delete_router(network_deployment.router_id)
- if network_deployment.net_id:
- driver.delete_network(network_deployment.net_id)
+ def delete_record(self, controller_network):
+ driver = OpenStackDriver().client_driver(caller=controller_network.network.owner.creator,
+ tenant=controller_network.network.owner.name,
+ controller=controller_network.controller.name)
+ if (controller_network.router_id) and (controller_network.subnet_id):
+ driver.delete_router_interface(controller_network.router_id, controller_network.subnet_id)
+ if controller_network.subnet_id:
+ driver.delete_subnet(controller_network.subnet_id)
+ if controller_network.router_id:
+ driver.delete_router(controller_network.router_id)
+ if controller_network.net_id:
+ driver.delete_network(controller_network.net_id)