1 from types import StringTypes
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Filter import Filter
6 from PLC.Auth import Auth
7 from PLC.Nodes import Node, Nodes
8 from PLC.SliceTags import SliceTag, SliceTags
9 from PLC.Slices import Slice, Slices
11 class RetrieveSliceSliverKeys(Method):
13 This method exposes the public ssh keys for a slice's slivers.
14 It expects a slice name or id, and returns a dictionary on hostnames.
15 This method is designed to help third-party software authenticate
16 slivers (e.g. the OMF Experiment Controller).
17 For this reason it is accessible with anonymous authentication.
20 roles = ['admin', 'pi', 'user', 'tech', 'anonymous' ]
23 'slice_id' : Slice.fields['slice_id'],
24 'name' : Slice.fields['name'],
29 Mixed(Slice.fields['slice_id'],
30 Slice.fields['name']),
34 returns = Parameter (dict, " ssh keys hashed on hostnames")
36 def call(self, auth, slice_id_or_name, node_filter=None):
39 if isinstance(slice_id_or_name,int):
40 filter['slice_id']=slice_id_or_name
41 elif isinstance(slice_id_or_name,StringTypes):
42 filter['name']=slice_id_or_name
43 filter['tagname']='ssh_key'
44 # retrieve only sliver tags
45 filter['~node_id']=None
47 # make sure we only deal with local nodes
48 node_filter['peer_id']=None
49 nodes = Nodes(self.api, node_filter, ['node_id'])
50 node_ids = [ node ['node_id'] for node in nodes ]
51 filter['node_id']=node_ids
53 # slice_tags don't expose hostname, sigh..
54 slice_tags=SliceTags(self.api,filter,['node_id','tagname','value'])
55 node_ids = [st['node_id'] for st in slice_tags]
57 nodes=Nodes(self.api,node_ids,['node_id','hostname'])
59 nodes_hash=dict( [ (n['node_id'],n['hostname']) for n in nodes])
60 # return values hashed on hostname
61 return dict([ (nodes_hash[st['node_id']],st['value']) for st in slice_tags])