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
7 from PLC.Slices import Slice, Slices
9 class GetSliceSshKeys(Method):
11 This method exposes the public ssh keys for a slice's slivers.
12 It expects a slice name or id, and returns a dictionary on hostnames.
13 This method is designed to help third-party software authenticate
14 slivers (e.g. the OMF Experiment Controller).
15 For this reason it is accessible with anonymous authentication.
18 roles = ['admin', 'pi', 'user', 'tech', 'anonymous' ]
21 'slice_id' : Slice.fields['slice_id'],
22 'name' : Slice.fields['name'],
27 Mixed(Slice.fields['slice_id'],
31 returns = Parameter (dict, " ssh keys hashed on hostnames")
33 def call(self, auth, slice_id_or_name):
35 if isinstance(int,slice_id_or_name):
36 filter['slice_id']=slice_id_or_name
37 elif isinstance(str,slice_id_or_name):
38 filter['name']=slice_id_or_name
39 filter['tagname']='ssh_key'
40 # retrieve only sliver tags
41 filter['~node_id']=None
43 # slice_tags don't expose hostname, sigh..
44 slice_tags=SliceTags(api,filter)
45 node_ids = [st['node_id'] for st in slice_tags]
47 nodes=Nodes(api,node_ids)
49 nodes_hash=dict( [ (n['node_id'],n['hostname']) for n in nodes])
50 # return values hashed on hostname
51 return dict([ (nodes_hash[nodes_hash[st['node_id']]],st['value']) for st in slice_tags])