svn keywords
[plcapi.git] / PLC / Methods / AddSite.py
1 # $Id$
2 # $URL$
3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Sites import Site, Sites
7 from PLC.Auth import Auth
8
9 can_update = lambda (field, value): field in \
10              ['name', 'abbreviated_name', 'login_base',
11               'is_public', 'latitude', 'longitude', 'url',
12               'max_slices', 'max_slivers', 'enabled']
13
14 class AddSite(Method):
15     """
16     Adds a new site, and creates a node group for that site. Any
17     fields specified in site_fields are used, otherwise defaults are
18     used.
19
20     Returns the new site_id (> 0) if successful, faults otherwise.
21     """
22
23     roles = ['admin']
24
25     site_fields = dict(filter(can_update, Site.fields.items()))
26
27     accepts = [
28         Auth(),
29         site_fields
30         ]
31
32     returns = Parameter(int, 'New site_id (> 0) if successful')
33
34     def call(self, auth, site_fields):
35         site_fields = dict(filter(can_update, site_fields.items()))
36         site = Site(self.api, site_fields)
37         site.sync()
38         
39         # Logging variables 
40         self.event_objects = {'Site': [site['site_id']]}
41         self.message = 'Site %d created' % site['site_id']
42         
43         return site['site_id']