removing plural from model names. some cleanup
diff --git a/planetstack/model_policies/__init__.py b/planetstack/model_policies/__init__.py
index 8671d6a..ac395a1 100644
--- a/planetstack/model_policies/__init__.py
+++ b/planetstack/model_policies/__init__.py
@@ -1,3 +1,4 @@
from .model_policy_Slice import *
from .model_policy_User import *
from .model_policy_Network import *
+from .model_policy_Site import *
diff --git a/planetstack/model_policies/model_policy_Network.py b/planetstack/model_policies/model_policy_Network.py
index d9d138d..f822bf2 100644
--- a/planetstack/model_policies/model_policy_Network.py
+++ b/planetstack/model_policies/model_policy_Network.py
@@ -1,16 +1,16 @@
from core.models import *
def handle(network):
- from core.models import ControllerSlices,ControllerNetworks
+ from core.models import ControllerSlice,ControllerNetwork
from collections import defaultdict
# network controllers are not visible to users. We must ensure
# networks are deployed at all deploymets available to their slices.
- slice_controllers = ControllerSlices.objects.all()
+ slice_controllers = ControllerSlice.objects.all()
slice_deploy_lookup = defaultdict(list)
for slice_controller in slice_controllers:
slice_deploy_lookup[slice_controller.slice].append(slice_controller.controller)
- network_controllers = ControllerNetworks.objects.all()
+ network_controllers = ControllerNetwork.objects.all()
network_deploy_lookup = defaultdict(list)
for network_controller in network_controllers:
network_deploy_lookup[network_controller.network].append(network_controller.controller)
@@ -19,5 +19,5 @@
for expected_controller in expected_controllers:
if network not in network_deploy_lookup or \
expected_controller not in network_deploy_lookup[network]:
- nd = ControllerNetworks(network=network, controller=expected_controller)
+ nd = ControllerNetwork(network=network, controller=expected_controller)
nd.save()
diff --git a/planetstack/model_policies/model_policy_Site.py b/planetstack/model_policies/model_policy_Site.py
new file mode 100644
index 0000000..a49c868
--- /dev/null
+++ b/planetstack/model_policies/model_policy_Site.py
@@ -0,0 +1,12 @@
+from core.models import *
+
+def handle(site):
+ # make sure site has a ControllerSite record for each controller
+ ctrl_sites = ControllerSite.objects.filter(site=site)
+ existing_controllers = [cs.controller for cs in ctrl_sites]
+
+ all_controllers = Controller.objects.all()
+ for ctrl in all_controllers:
+ if ctrl not in existing_controllers:
+ ctrl_site = ControllerSite(controller=ctrl, site=site)
+ ctrl_site.save()
diff --git a/planetstack/model_policies/model_policy_Slice.py b/planetstack/model_policies/model_policy_Slice.py
index 0d83d68..37129a3 100644
--- a/planetstack/model_policies/model_policy_Slice.py
+++ b/planetstack/model_policies/model_policy_Slice.py
@@ -1,64 +1,59 @@
def handle(slice):
- from core.models import Controller,ControllerSlices,Controller,Network,NetworkSlice,NetworkTemplate
- from collections import defaultdict
- ctrl_site_deployments = SiteDeployments.objects.all()
-
- slice_controllers = ControllerSlices.objects.all()
- slice_deploy_lookup = defaultdict(list)
- for slice_controller in slice_controllers:
- slice_deploy_lookup[slice_controller.slice].append(slice_controller)
-
- all_controllers = Controller.objects.all()
- for expected_controller in all_controllers:
- if slice not in slice_deploy_lookup or \
- expected_controller not in slice_deploy_lookup[slice]:
- sd = ControllerSlices(slice=slice, controller=expected_controller)
- sd.save()
+ from core.models import Controller, ControllerSlice, SiteDeployment, Network, NetworkSlice,NetworkTemplate
+ from collections import defaultdict
+ controller_slices = ControllerSlice.objects.filter(slice=slice)
+ existing_controllers = [cs.controller for cs in controller_slices]
+
+ all_controllers = Controller.objects.all()
+ for controller in all_controllers:
+ if controller not in existing_controllers:
+ sd = ControllerSlice(slice=slice, controller=controller_controller)
+ sd.save()
- # make sure slice has at least 1 public and 1 private networkd
- public_nets = []
- private_net = None
- networks = Network.objects.filter(owner=slice)
- for network in networks:
- if network.template.name == 'Public dedicated IPv4':
- public_nets.append(network)
- elif network.template.name == 'Public shared IPv4':
- public_nets.append(network)
- elif network.template.name == 'Private':
- private_net = network
- if not public_nets:
+ # make sure slice has at least 1 public and 1 private networkd
+ public_nets = []
+ private_net = None
+ networks = Network.objects.filter(owner=slice)
+ for network in networks:
+ if network.template.name == 'Public dedicated IPv4':
+ public_nets.append(network)
+ elif network.template.name == 'Public shared IPv4':
+ public_nets.append(network)
+ elif network.template.name == 'Private':
+ private_net = network
+ if not public_nets:
# ensure there is at least one public network, and default it to dedicated
- nat_net = Network(
- name = slice.name+'-nat',
- template = NetworkTemplate.objects.get(name='Public shared IPv4'),
- owner = slice
- )
- nat_net.save()
- public_nets.append(nat_net)
+ nat_net = Network(
+ name = slice.name+'-nat',
+ template = NetworkTemplate.objects.get(name='Public shared IPv4'),
+ owner = slice
+ )
+ nat_net.save()
+ public_nets.append(nat_net)
- if not private_net:
- private_net = Network(
- name = slice.name+'-private',
- template = NetworkTemplate.objects.get(name='Private'),
- owner = slice
- )
- private_net.save()
- # create slice networks
- public_net_slice = None
- private_net_slice = None
- net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
- for net_slice in net_slices:
- if net_slice.network in public_nets:
- public_net_slice = net_slice
- elif net_slice.network == private_net:
- private_net_slice = net_slice
- if not public_net_slice:
- public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
- public_net_slice.save()
- if not private_net_slice:
- private_net_slice = NetworkSlice(slice=slice, network=private_net)
- private_net_slice.save()
+ if not private_net:
+ private_net = Network(
+ name = slice.name+'-private',
+ template = NetworkTemplate.objects.get(name='Private'),
+ owner = slice
+ )
+ private_net.save()
+ # create slice networks
+ public_net_slice = None
+ private_net_slice = None
+ net_slices = NetworkSlice.objects.filter(slice=slice, network__in=[private_net]+public_nets)
+ for net_slice in net_slices:
+ if net_slice.network in public_nets:
+ public_net_slice = net_slice
+ elif net_slice.network == private_net:
+ private_net_slice = net_slice
+ if not public_net_slice:
+ public_net_slice = NetworkSlice(slice=slice, network=public_nets[0])
+ public_net_slice.save()
+ if not private_net_slice:
+ private_net_slice = NetworkSlice(slice=slice, network=private_net)
+ private_net_slice.save()
diff --git a/planetstack/model_policies/model_policy_User.py b/planetstack/model_policies/model_policy_User.py
index 703b28c..5e2adad 100644
--- a/planetstack/model_policies/model_policy_User.py
+++ b/planetstack/model_policies/model_policy_User.py
@@ -1,15 +1,15 @@
from core.models import *
def handle(user):
- from core.models import Controller, ControllerSiteDeployments, ControllerUsers
+ from core.models import Controller, ControllerSite, ControllerUser
from collections import defaultdict
- ctrl_site_deployments = ControllerSiteDeployments.objects.all()
+ ctrl_site_deployments = ControllerSite.objects.all()
controller_lookup = defaultdict(list)
for ctrl_site_deployment in ctrl_site_deployments:
controller_site_lookup[ctrl_site_deployment.site_deployment].append(ctrl_site_deployment)
controller_user_lookup = defaultdict(list)
- for controller_user in ControllerUsers.objects.all():
+ for controller_user in ControllerUser.objects.all():
controller_user_lookup[controller_user.user].append(controller_user.controller)
if user.is_admin:
@@ -25,6 +25,6 @@
if not user in controller_user_lookup or \
expected_controller not in controller_user_lookup[user]:
# add new record
- ud = ControllerUsers(user=user, controller=expected_controller)
+ ud = ControllerUser(user=user, controller=expected_controller)
ud.save()