from PLC.Auth import Auth
can_update = lambda (field, value): field in \
- ['name', 'abbreviated_name', 'login_base',
- 'is_public', 'latitude', 'longitude', 'url',
- 'max_slices', 'max_slivers', 'enabled', 'ext_consortium_id']
+ ['enabled', 'tenant_name', 'description']
class AddSite(Method):
"""
site_fields
]
- returns = Parameter(int, 'New site_id (> 0) if successful')
+ returns = Parameter(str, 'New site_id if successful')
def call(self, auth, site_fields):
site_fields = dict(filter(can_update, site_fields.items()))
- site = Site(self.api, site_fields)
- site.sync()
-
- # Logging variables
- self.event_objects = {'Site': [site['site_id']]}
- self.message = 'Site %d created' % site['site_id']
-
- return site['site_id']
+ tenant = self.api.client_shell.keystone.tenants.create(**site_fields)
+ return tenant.id
from PLC.Method import Method
from PLC.Parameter import Parameter, Mixed
from PLC.Sites import Site, Sites
-from PLC.Persons import Person, Persons
-from PLC.Nodes import Node, Nodes
-from PLC.PCUs import PCU, PCUs
from PLC.Auth import Auth
class DeleteSite(Method):
accepts = [
Auth(),
- Mixed(Site.fields['site_id'],
- Site.fields['login_base'])
+ Site.fields['id']
]
returns = Parameter(int, '1 if successful')
- def call(self, auth, site_id_or_login_base):
+ def call(self, auth, site_id):
# Get account information
- sites = Sites(self.api, [site_id_or_login_base])
+ sites = Sites(self.api, site_id)
if not sites:
raise PLCInvalidArgument, "No such site"
site = sites[0]
-
- if site['peer_id'] is not None:
- raise PLCInvalidArgument, "Not a local site"
-
site.delete()
-
- # Logging variables
- self.event_objects = {'Site': [site['site_id']]}
- self.message = 'Site %d deleted' % site['site_id']
-
-
return 1
fields = {
'enabled': Parameter(bool, "Has been enabled"),
- 'id': Parameter(int, "Site identifier"),
- 'name': Parameter(str, "Full site name", max = 254),
+ 'id': Parameter(str, "Site identifier"),
+ 'tenant_name': Parameter(str, "Full site name", max = 254),
'description': Parameter(str, "Description", max = 254),
#'max_slices': Parameter(int, "Maximum number of slices that the site is able to create"),
#'max_slivers': Parameter(int, "Maximum number of slivers that the site is able to create"),
'node_ids': Parameter([int], "List of site node identifiers"),
}
- def delete(self, commit = True):
- """
- Delete existing site.
- """
-
- assert 'site_id' in self
-
- # Delete accounts of all people at the site who are not
- # members of at least one other non-deleted site.
- persons = Persons(self.api, self['person_ids'])
- for person in persons:
- delete = True
-
- person_sites = Sites(self.api, person['site_ids'])
- for person_site in person_sites:
- if person_site['site_id'] != self['site_id']:
- delete = False
- break
-
- if delete:
- person.delete(commit = False)
-
- # Delete all site addresses
- addresses = Addresses(self.api, self['address_ids'])
- for address in addresses:
- address.delete(commit = False)
-
- # Delete all site slices
- slices = Slices(self.api, self['slice_ids'])
- for slice in slices:
- slice.delete(commit = False)
-
- # Delete all site PCUs
- pcus = PCUs(self.api, self['pcu_ids'])
- for pcu in pcus:
- pcu.delete(commit = False)
-
- # Delete all site nodes
- nodes = Nodes(self.api, self['node_ids'])
- for node in nodes:
- node.delete(commit = False)
-
- # Clean up miscellaneous join tables
- for table in self.join_tables:
- self.api.db.do("DELETE FROM %s WHERE site_id = %d" % \
- (table, self['site_id']))
-
- # Mark as deleted
- self['deleted'] = True
- self.sync(commit)
-
class Sites(NovaObjects):
"""
Representation of row(s) from the sites table in the
self.fields = Site.fields
if not site_filter:
sites = self.api.client_shell.keystone.tenants.findall()
- elif isintance(site_filter, StringTypes):
+ elif isinstance(site_filter, StringTypes):
sites = [self.api.client_shell.keystone.tenants.find(id=site_filter)]
- elif isintance(site_filter, StringTypes):
+ elif isinstance(site_filter, StringTypes):
sites = [self.api.client_shell.keystone.tenants.find(**site_filter)]
elif isinstance(site_filter, (list, tuple, set)):
sites = self.api.client_shell.keystone.tenants.findall()