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