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 GetSliceSshKeys(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'],
33 returns = Parameter (dict, " ssh keys hashed on hostnames")
35 def call(self, auth, slice_id_or_name):
37 if isinstance(slice_id_or_name,int):
38 filter['slice_id']=slice_id_or_name
39 elif isinstance(slice_id_or_name,StringTypes):
40 filter['name']=slice_id_or_name
41 filter['tagname']='ssh_key'
42 # retrieve only sliver tags
43 filter['~node_id']=None
45 # slice_tags don't expose hostname, sigh..
46 slice_tags=SliceTags(self.api,filter,['node_id','tagname','value'])
47 node_ids = [st['node_id'] for st in slice_tags]
49 nodes=Nodes(self.api,node_ids,['node_id','hostname'])
51 nodes_hash=dict( [ (n['node_id'],n['hostname']) for n in nodes])
52 # return values hashed on hostname
53 return dict([ (nodes_hash[st['node_id']],st['value']) for st in slice_tags])