6 from PLC.Faults import *
7 from PLC.Method import Method
8 from PLC.Parameter import Parameter, Mixed
9 from PLC.Slices import Slice, Slices
10 from PLC.Auth import Auth
11 from PLC.GPG import gpg_sign, gpg_verify
12 from PLC.InitScripts import InitScript, InitScripts
14 from PLC.Methods.GetSlivers import get_slivers
16 class GetSliceTicket(Method):
18 Returns a ticket for, or signed representation of, the specified
19 slice. Slice tickets may be used to manually instantiate or update
20 a slice on a node. Present this ticket to the local Node Manager
21 interface to redeem it.
23 If the slice has not been added to a node with AddSliceToNodes,
24 and the ticket is redeemed on that node, it will be deleted the
25 next time the Node Manager contacts the API.
27 Users may only obtain tickets for slices of which they are
28 members. PIs may obtain tickets for any of the slices at their
29 sites, or any slices of which they are members. Admins may obtain
30 tickets for any slice.
32 Returns 1 if successful, faults otherwise.
35 roles = ['admin', 'pi', 'user', 'peer']
39 Mixed(Slice.fields['slice_id'],
40 Slice.fields['name']),
43 returns = Parameter(str, 'Signed slice ticket')
45 def call(self, auth, slice_id_or_name):
46 slices = Slices(self.api, [slice_id_or_name])
48 raise PLCInvalidArgument, "No such slice"
51 # Allow peers to obtain tickets for their own slices
52 if slice['peer_id'] is not None:
53 if not isinstance(self.caller, Peer):
54 raise PLCInvalidArgument, "Not a local slice"
55 elif slice['peer_id'] != self.caller['peer_id']:
56 raise PLCInvalidArgument, "Only the authoritative peer may obtain tickets for that slice"
58 # Tickets are the canonicalized XML-RPC methodResponse
59 # representation of a partial GetSlivers() response, i.e.,
61 initscripts = InitScripts(self.api, {'enabled': True})
64 'timestamp': int(time.time()),
65 'initscripts': initscripts,
66 'slivers': get_slivers(self.api, self.caller, auth, [slice['slice_id']]),
70 signed_ticket = gpg_sign((data,),
71 self.api.config.PLC_ROOT_GPG_KEY,
72 self.api.config.PLC_ROOT_GPG_KEY_PUB,
73 methodresponse = True,
77 gpg_verify(signed_ticket,
78 self.api.config.PLC_ROOT_GPG_KEY_PUB)