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
7 from PLC.Methods.AddSiteTag import AddSiteTag
9 can_update = lambda field_value: field_value[0] in \
10 ['name', 'abbreviated_name', 'login_base',
11 'is_public', 'latitude', 'longitude', 'url',
12 'max_slices', 'max_slivers', 'enabled', 'ext_consortium_id']
14 class AddSite(Method):
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
20 Returns the new site_id (> 0) if successful, faults otherwise.
25 site_fields = dict(list(filter(can_update, list(Site.fields.items()))))
32 returns = Parameter(int, 'New site_id (> 0) if successful')
34 def call(self, auth, site_fields):
35 site_fields = dict(list(filter(can_update, list(site_fields.items()))))
36 site = Site(self.api, site_fields)
40 self.event_objects = {'Site': [site['site_id']]}
41 self.message = 'Site %d created' % site['site_id']
44 root_auth = self.api.config.PLC_HRN_ROOT
46 tagvalue = '.'.join([root_auth, site['login_base']])
47 AddSiteTag(self.api).__call__(auth,site['site_id'],tagname,tagvalue)
50 return site['site_id']