added policy for Site model
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_Site.py b/planetstack/model_policies/model_policy_Site.py
new file mode 100644
index 0000000..cfadbd4
--- /dev/null
+++ b/planetstack/model_policies/model_policy_Site.py
@@ -0,0 +1,27 @@
+from core.models import *
+
+def handle(site):
+ """
+ ensure ControllerSiteDeployment object exists for each of the site's SiteDeployment objects
+ """
+ from core.models import SiteDeployments, Controller, ControllerSiteDeployments
+ from collections import defaultdict
+
+
+ # get current controller site deployments
+ ctrl_site_deployments = ControllerSiteDeployments.objects.filter(site_deployment__site = site)
+ ctrl_site_deployments_dict = {}
+ for ctrl_site_depl in controller_site_deployments:
+ ctrl_site_deployments_dict[ctrl_site_depl.site_deployment] = ctrl_cite_depl
+
+ # get current site deployments
+ site_deployments = SiteDeployments.objects.filter(site=site)
+
+ # for each site deployment, if there is no controller site deployment create one
+ for site_deployment in site_deployments:
+ if site_deployment not in ctrl_site_deployments_dict:
+ ctrl_site_deployment = ControllerSiteDeployment(
+ site_deployment=site_deployment,
+ controller=site_deployment.controller,
+ )
+ ctrl_site_deployment.save()
diff --git a/planetstack/openstack_observer/steps/sync_controller_site_deployments.py b/planetstack/openstack_observer/steps/sync_controller_site_deployments.py
index fb257f1..d0e4a7f 100644
--- a/planetstack/openstack_observer/steps/sync_controller_site_deployments.py
+++ b/planetstack/openstack_observer/steps/sync_controller_site_deployments.py
@@ -16,7 +16,7 @@
tenant_fields = {'endpoint':controller_site_deployment.controller.auth_url,
'admin_user': controller_site_deployment.controller.admin_user,
'admin_password': controller_site_deployment.controller.admin_password,
- 'admin_tenant': 'admin',
+ 'admin_tenant': controller_site_deployment.controller.admin_tenant,
'ansible_tag': '%s@%s'%(controller_site_deployment.site_deployment.site.login_base,controller_site_deployment.site_deployment.deployment.name), # name of ansible playbook
'tenant': controller_site_deployment.site_deployment.site.login_base,
'tenant_description': controller_site_deployment.site_deployment.site.name}