1 from types import StringTypes
4 from PLC.Faults import *
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.NovaObject import NovaObject, NovaObjects
7 from PLC.Slices import Slice, Slices
8 #from PLC.Persons import Person, Persons
12 Representation of a row in the sites table. To use, optionally
13 instantiate with a dict of values. Update as you would a
14 dict. Commit to the database with sync().
18 'enabled': Parameter(bool, "Has been enabled"),
19 'id': Parameter(int, "Site identifier"),
20 'name': Parameter(str, "Full site name", max = 254),
21 'description': Parameter(str, "Description", max = 254),
22 #'max_slices': Parameter(int, "Maximum number of slices that the site is able to create"),
23 #'max_slivers': Parameter(int, "Maximum number of slivers that the site is able to create"),
24 'person_ids': Parameter([int], "List of account identifiers"),
25 'slice_ids': Parameter([int], "List of slice identifiers"),
26 'pcu_ids': Parameter([int], "List of PCU identifiers"),
27 'node_ids': Parameter([int], "List of site node identifiers"),
30 def delete(self, commit = True):
35 assert 'site_id' in self
37 # Delete accounts of all people at the site who are not
38 # members of at least one other non-deleted site.
39 persons = Persons(self.api, self['person_ids'])
40 for person in persons:
43 person_sites = Sites(self.api, person['site_ids'])
44 for person_site in person_sites:
45 if person_site['site_id'] != self['site_id']:
50 person.delete(commit = False)
52 # Delete all site addresses
53 addresses = Addresses(self.api, self['address_ids'])
54 for address in addresses:
55 address.delete(commit = False)
57 # Delete all site slices
58 slices = Slices(self.api, self['slice_ids'])
60 slice.delete(commit = False)
62 # Delete all site PCUs
63 pcus = PCUs(self.api, self['pcu_ids'])
65 pcu.delete(commit = False)
67 # Delete all site nodes
68 nodes = Nodes(self.api, self['node_ids'])
70 node.delete(commit = False)
72 # Clean up miscellaneous join tables
73 for table in self.join_tables:
74 self.api.db.do("DELETE FROM %s WHERE site_id = %d" % \
75 (table, self['site_id']))
78 self['deleted'] = True
81 class Sites(NovaObjects):
83 Representation of row(s) from the sites table in the
87 def __init__(self, api, site_filter = None, columns = None):
89 self.fields = Site.fields
91 sites = self.api.client_shell.keystone.tenants.findall()
92 elif isintance(site_filter, StringTypes):
93 sites = [self.api.client_shell.keystone.tenants.find(id=site_filter)]
94 elif isintance(site_filter, StringTypes):
95 sites = [self.api.client_shell.keystone.tenants.find(**site_filter)]
96 elif isinstance(site_filter, (list, tuple, set)):
97 sites = self.api.client_shell.keystone.tenants.findall()
98 sites = [site for site in sites if site.id in site_filter]
100 raise PLCInvalidArgument, "Wrong site filter %s" % site_filter