Implement Sites()
[plcapi.git] / PLC / Methods / AddSite.py
1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Sites import Site, Sites
5 from PLC.Auth import Auth
6
7 can_update = lambda (field, value): field in \
8              ['enabled', 'tenant_name', 'description']
9
10 class AddSite(Method):
11     """
12     Adds a new site, and creates a node group for that site. Any
13     fields specified in site_fields are used, otherwise defaults are
14     used.
15
16     Returns the new site_id (> 0) if successful, faults otherwise.
17     """
18
19     roles = ['admin']
20
21     site_fields = dict(filter(can_update, Site.fields.items()))
22
23     accepts = [
24         Auth(),
25         site_fields
26         ]
27
28     returns = Parameter(str, 'New site_id if successful')
29
30     def call(self, auth, site_fields):
31         site_fields = dict(filter(can_update, site_fields.items()))
32         tenant = self.api.client_shell.keystone.tenants.create(**site_fields)
33         return tenant.id