# $Id$
+# $URL$
import time
from PLC.Faults import *
from PLC.ConfFiles import ConfFile, ConfFiles
from PLC.Slices import Slice, Slices
from PLC.Persons import Person, Persons
+from PLC.Sites import Sites
+from PLC.Roles import Roles
from PLC.Keys import Key, Keys
from PLC.SliceTags import SliceTag, SliceTags
from PLC.InitScripts import InitScript, InitScripts
+# XXX used to check if slice expiration time is sane
+MAXINT = 2L**31-1
+
def get_slivers(api, slice_filter, node = None):
# Get slice information
slices = Slices(api, slice_filter, ['slice_id', 'name', 'instantiation', 'expires', 'person_ids', 'slice_tag_ids'])
# Do not set any nodegroup slice attributes for
# which there is at least one sliver attribute
# already set.
- if slice_tag['tagname'] not in slice_tags:
+ if slice_tag not in slice_tags:
attributes.append({'tagname': slice_tag['tagname'],
'value': slice_tag['value']})
attributes.append({'tagname': slice_tag['tagname'],
'value': slice_tag['value']})
+ # XXX Sanity check; though technically this should be a system invariant
+ # checked with an assertion
+ if slice['expires'] > MAXINT: slice['expires']= MAXINT
+
slivers.append({
'name': slice['name'],
'slice_id': slice['slice_id'],
'groups': [NodeGroup.fields['groupname']],
'conf_files': [ConfFile.fields],
'initscripts': [InitScript.fields],
+ 'accounts': [{
+ 'name': Parameter(str, "unix style account name", max = 254),
+ 'keys': [{
+ 'key_type': Key.fields['key_type'],
+ 'key': Key.fields['key']
+ }],
+ }],
'slivers': [{
'name': Slice.fields['name'],
'slice_id': Slice.fields['slice_id'],
slivers = get_slivers(self.api, slice_ids, node)
+ # get the special accounts and keys needed for the node
+ # root
+ # site_admin
+ accounts = []
+ if False and 'site_id' not in node:
+ nodes = Nodes(self.api, node['node_id'])
+ node = nodes[0]
+
+ # used in conjunction with reduce to flatten lists, like in
+ # reduce ( reduce_flatten_list, [ [1] , [2,3] ], []) => [ 1,2,3 ]
+ def reduce_flatten_list (x,y): return x+y
+
+ # power users are pis and techs
+ def get_site_power_user_keys(api,site_id_or_name):
+ site = Sites (api,site_id_or_name,['person_ids'])[0]
+ key_ids = reduce (reduce_flatten_list,
+ [ p['key_ids'] for p in \
+ Persons(api,{ 'person_id':site['person_ids'],
+ 'enabled':True, '|role_ids' : [20, 40] },
+ ['key_ids']) ],
+ [])
+ return [ key['key'] for key in Keys (api, key_ids) if key['key_type']=='ssh']
+
+ # all admins regardless of their site
+ def get_all_admin_keys(api):
+ key_ids = reduce (reduce_flatten_list,
+ [ p['key_ids'] for p in \
+ Persons(api, {'peer_id':None, 'enabled':True, '|role_ids':[10] },
+ ['key_ids']) ],
+ [])
+ return [ key['key'] for key in Keys (api, key_ids) if key['key_type']=='ssh']
+
+ # 'site_admin' account setup
+ personsitekeys=get_site_power_user_keys(self.api,node['site_id'])
+ accounts.append({'name':'site_admin','keys':personsitekeys})
+
+ # 'root' account setup on nodes from all 'admin' users
+ personsitekeys=get_all_admin_keys(self.api)
+ accounts.append({'name':'root','keys':personsitekeys})
+
node.update_last_contact()
return {
'groups': groups,
'conf_files': conf_files.values(),
'initscripts': initscripts,
- 'slivers': slivers
+ 'slivers': slivers,
+ 'accounts': accounts
}
class v42GetSlivers(v43GetSlivers):