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