implement GetPersons()
[plcapi.git] / PLC / Sites.py
1 from types import StringTypes
2 import string
3
4 from PLC.Faults import *
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.NovaTable import NovaObject, NovaTable
7 from PLC.Slices import Slice, Slices
8 #from PLC.Persons import Person, Persons
9
10 class Site(NovaObject):
11     """
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().
15     """
16
17     fields = {
18         'enabled': Parameter(bool, "Has been enabled"),
19         'id': Parameter(str, "Site identifier"),
20         'tenant_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"),
28         }
29
30     def sync(self, insert=False, validate=True):
31         NovaObject.sync(self, insert, validate)
32         if insert == True or id not in self:
33             self.object = self.api.client_shell.keystone.tenants.create(**self)
34
35 class Sites(NovaTable):
36     """
37     Representation of row(s) from the sites table in the
38     database.
39     """
40
41     def __init__(self, api, site_filter = None, columns = None):
42         self.api = api 
43         if not site_filter:
44             sites = self.api.client_shell.keystone.tenants.findall()
45         elif isinstance(site_filter, StringTypes):
46             sites = [self.api.client_shell.keystone.tenants.find(id=site_filter)]
47         elif isinstance(site_filter, dict):
48             sites = [self.api.client_shell.keystone.tenants.findall(**site_filter)]
49         elif isinstance(site_filter, (list, tuple, set)):
50             sites = self.api.client_shell.keystone.tenants.findall()
51             sites = [site for site in sites if site.id in site_filter]
52         else:
53             raise PLCInvalidArgument, "Wrong site filter %s" % site_filter         
54
55         for site in sites:
56             site = Site(self.api, object = site)
57             self.append(site)