last_updated = datetime.now()
return last_updated
+ def validate_login_base(self, login_base):
+ if not len(login_base):
+ raise PLCInvalidArgument, "Login base must be specified"
+
+ if not set(login_base).issubset(string.lowercase + string.digits):
+ raise PLCInvalidArgument, "Login base must consist only of lowercase ASCII letters or numbers"
+
+ conflicts = Site().select(filter={'login_base': login_base})
+ for site in conflicts:
+ if 'site_id' not in self or self['site_id'] != site.site_id:
+ raise PLCInvalidArgument, "login_base already in use"
+
+ return login_base
+
def add_person(self, person_filter, role_name=None):
assert 'site_id' in self
assert 'tenant_id' in self
def __init__(self, api, site_filter = None, columns = None):
self.api = api
+ self.refresh(api)
if not site_filter:
sites = Site().select()
elif isinstance(site_filter, int):
site['site_tag_ids'] = [rec.tag_id for rec in site_tags]
self.append(site)
+
+ def refresh(self, api):
+ """
+ Import tenants from keystone.
+ """
+ # get current sites
+ sites = Site().select()
+ login_bases = [site['login_base'] for site in sites]
+
+ # get current tenants
+ tenants = api.client_shell.keystone.tenants.list()
+
+ # add tenants that dont already exist
+ for tenant in tenants:
+ # site tenants should not contain '_'
+ if '_' not in tenant.name and tenant.name not in login_bases:
+ description = tenant.description
+ if not description: description = tenant.name
+ site = Site(api, {'login_base': tenant.name,
+ 'tenant_id': tenant.id,
+ 'enabled': tenant.enabled,
+ 'description': description
+ 'name': tenant.name,
+ 'abbreviated_name': tenant.name,
+ 'is_public': True})
+ site.sync()