1 from PLC.Method import Method
2 from PLC.Parameter import Parameter, Mixed
3 from PLC.Filter import Filter
4 from PLC.Auth import Auth
5 from PLC.Nodes import Node, Nodes
6 from PLC.SliceTags import SliceTag, SliceTags
8 class GetSliceSshKeys(Method):
10 This method exposes the public ssh keys for a slice's slivers.
11 It expects a slice name or id, and returns a dictionary on hostnames.
12 This method is designed to help third-party software authenticate
13 slivers (e.g. the OMF Experiment Controller).
14 For this reason it is accessible with anonymous authentication.
17 roles = ['admin', 'pi', 'user', 'tech', 'anonymous' ]
20 'slice_id' : Slice.fields['slice_id'],
21 'name' : Slice.fields['name'],
26 Mixed(Slice.fields['slice_id'],
30 returns = Parameter (dict, " ssh keys hashed on hostnames")
32 def call(self, auth, slice_id_or_name):
34 if isinstance(int,slice_id_or_name):
35 filter['slice_id']=slice_id_or_name
36 elif isinstance(str,slice_id_or_name):
37 filter['name']=slice_id_or_name
38 filter['tagname']='ssh_key'
39 # retrieve only sliver tags
40 filter['~node_id']=None
42 # slice_tags don't expose hostname, sigh..
43 slice_tags=SliceTags(api,filter)
44 node_ids = [st['node_id'] for st in slice_tags]
46 nodes=Nodes(api,node_ids)
48 nodes_hash=dict([n['node_id'],n['hostname'] for n in nodes])
49 # return values hashed on hostname
50 return dict([ (nodes_hash[nodes_hash[st['node_id']]],st['value']) for st in slice_tags])