bug fixes
diff --git a/planetstack/core/admin.py b/planetstack/core/admin.py
index b0f0446..4846a28 100644
--- a/planetstack/core/admin.py
+++ b/planetstack/core/admin.py
@@ -662,12 +662,12 @@
return AdminFormMetaClass
class ControllerAdminForm(forms.ModelForm):
- site_deployments = forms.ModelMultipleChoiceField(
- queryset=SiteDeployment.objects.all(),
+ sites = forms.ModelMultipleChoiceField(
+ queryset=Site.objects.all(),
required=False,
- help_text="Select which sites deployments are managed by this controller",
+ help_text="Select which sites are managed by this controller",
widget=FilteredSelectMultiple(
- verbose_name=('Site Deployments'), is_stacked=False
+ verbose_name=('Sites'), is_stacked=False
)
)
@@ -679,7 +679,7 @@
super(ControllerAdminForm, self).__init__(*args, **kwargs)
if self.instance and self.instance.pk:
- self.fields['site_deployments'].initial = [x.site_deployment for x in self.instance.controllersitedeployments.all()]
+ self.fields['sites'].initial = [x.site_deployment for x in self.instance.controllersite.all()]
def manipulate_m2m_objs(self, this_obj, selected_objs, all_relations, relation_class, local_attrname, foreign_attrname):
""" helper function for handling m2m relations from the MultipleChoiceField
@@ -717,7 +717,7 @@
# save_m2m() doesn't seem to work with 'through' relations. So we
# create/destroy the through models ourselves. There has to be
# a better way...
- self.manipulate_m2m_objs(controller, self.cleaned_data['site_deployments'], controller.controllersitedeployments.all(), ControllerSite, "controller", "site_deployment")
+ self.manipulate_m2m_objs(controller, self.cleaned_data['sites'], controller.controllersite.all(), ControllerSite, "controller", "site")
pass
self.save_m2m()
diff --git a/planetstack/core/models/site.py b/planetstack/core/models/site.py
index 6b1f3df..1d46f4c 100644
--- a/planetstack/core/models/site.py
+++ b/planetstack/core/models/site.py
@@ -299,7 +299,7 @@
deleted_objects = ControllerDeletionManager()
name = models.CharField(max_length=200, unique=True, help_text="Name of the Controller")
- version = models.CharField(max_length=200, unique=True, help_text="Controller version")
+ version = models.CharField(max_length=200, help_text="Controller version")
backend_type = models.CharField(max_length=200, null=True, blank=True, help_text="Type of compute controller, e.g. EC2, OpenStack, or OpenStack version")
auth_url = models.CharField(max_length=200, null=True, blank=True, help_text="Auth url for the compute controller")
admin_user = models.CharField(max_length=200, null=True, blank=True, help_text="Username of an admin user at this controller")
diff --git a/planetstack/model_policies/model_policy_Site.py b/planetstack/model_policies/model_policy_Site.py
index a49c868..7d96264 100644
--- a/planetstack/model_policies/model_policy_Site.py
+++ b/planetstack/model_policies/model_policy_Site.py
@@ -1,6 +1,6 @@
-from core.models import *
def handle(site):
+ from core.models import Controller, ControllerSite
# 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]
diff --git a/planetstack/model_policies/model_policy_Slice.py b/planetstack/model_policies/model_policy_Slice.py
index 37129a3..cc9f2b0 100644
--- a/planetstack/model_policies/model_policy_Slice.py
+++ b/planetstack/model_policies/model_policy_Slice.py
@@ -8,7 +8,7 @@
all_controllers = Controller.objects.all()
for controller in all_controllers:
if controller not in existing_controllers:
- sd = ControllerSlice(slice=slice, controller=controller_controller)
+ sd = ControllerSlice(slice=slice, controller=controller)
sd.save()
# make sure slice has at least 1 public and 1 private networkd
diff --git a/planetstack/model_policies/model_policy_User.py b/planetstack/model_policies/model_policy_User.py
index 5e2adad..b7b16ad 100644
--- a/planetstack/model_policies/model_policy_User.py
+++ b/planetstack/model_policies/model_policy_User.py
@@ -1,30 +1,12 @@
-from core.models import *
-
def handle(user):
- from core.models import Controller, ControllerSite, ControllerUser
- from collections import defaultdict
- 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 ControllerUser.objects.all():
- controller_user_lookup[controller_user.user].append(controller_user.controller)
-
- if user.is_admin:
- # admins should have an account at all controllers
- expected_controllers = controllers
- else:
- # normal users should have an account at their site's controllers
- #expected_controllers = controller_site_lookup[user.site]
- # users are added to all controllers for now
- expected_controllers = controllers
-
- for expected_controller in expected_controllers:
- if not user in controller_user_lookup or \
- expected_controller not in controller_user_lookup[user]:
- # add new record
- ud = ControllerUser(user=user, controller=expected_controller)
- ud.save()
+ from core.models import Controller, ControllerSite, ControllerUser
+ from collections import defaultdict
+
+ controller_users = ControllerUser.objects.filter(user=user)
+ existing_controllers = [cu.controller for cu in controller_users]
+ all_controllers = Controller.objects.all()
+ for controller in all_controllers:
+ if controller not in existing_controllers:
+ ctrl_user = ControllerUser(controller=controller, user=user)
+ ctrl_user.save()
diff --git a/planetstack/openstack_observer/steps/__init__.py b/planetstack/openstack_observer/steps/__init__.py
index f164623..b83322a 100644
--- a/planetstack/openstack_observer/steps/__init__.py
+++ b/planetstack/openstack_observer/steps/__init__.py
@@ -1 +1,3 @@
from .sync_controller_sites import SyncControllerSites
+from .sync_controller_slices import SyncControllerSlices
+from .sync_controller_users import SyncControllerUsers
diff --git a/planetstack/openstack_observer/steps/sync_controller_slices.py b/planetstack/openstack_observer/steps/sync_controller_slices.py
index 24453e3..4487f3a 100644
--- a/planetstack/openstack_observer/steps/sync_controller_slices.py
+++ b/planetstack/openstack_observer/steps/sync_controller_slices.py
@@ -6,13 +6,13 @@
from planetstack.config import Config
from observer.openstacksyncstep import OpenStackSyncStep
from core.models.slice import Slice, ControllerSlice
-from core.models.controllerusers import ControllerUser
+from core.models.controlleruser import ControllerUser
from util.logger import Logger, logging
from observer.ansible import *
logger = Logger(level=logging.INFO)
-class SyncControllerSlice(OpenStackSyncStep):
+class SyncControllerSlices(OpenStackSyncStep):
provides=[ControllerSlice]
requested_interval=0
diff --git a/planetstack/openstack_observer/steps/sync_controller_users.py b/planetstack/openstack_observer/steps/sync_controller_users.py
index 1ace6db..0c35047 100644
--- a/planetstack/openstack_observer/steps/sync_controller_users.py
+++ b/planetstack/openstack_observer/steps/sync_controller_users.py
@@ -6,14 +6,14 @@
from observer.openstacksyncstep import OpenStackSyncStep
from core.models.site import Controller, SiteDeployment, SiteDeployment
from core.models.user import User
-from core.models.controllerusers import ControllerUser
+from core.models.controlleruser import ControllerUser
from util.logger import Logger, logging
from observer.ansible import *
logger = Logger(level=logging.INFO)
-class SyncControllerUser(OpenStackSyncStep):
+class SyncControllerUsers(OpenStackSyncStep):
provides=[ControllerUser, User]
requested_interval=0
@@ -37,7 +37,7 @@
# We must also check if the user should have the admin role
roles = ['user']
if controller_user.user.is_admin:
- roles.append('admin')
+ roles.append('Admin')
# setup user home site roles at controller
if not controller_user.user.site: