4 from sfa.util.faults import *
5 from sfa.util.xrn import urn_to_hrn
6 from sfa.util.plxrn import hrn_to_pl_slicename
7 from sfa.util.sfaticket import SfaTicket
10 from sfa.server import sfa_component_setup
11 # get current trusted gids
13 sfa_component_setup.get_trusted_certs()
15 # our keypair may be old, try refreshing
16 sfa_component_setup.get_node_key()
17 sfa_component_setup.get_credential(force=True)
18 sfa_component_setup.get_trusted_certs()
22 version['geni_api'] = 1
25 def slice_status(api, slice_xrn, creds):
27 result['geni_urn'] = slice_xrn
28 result['geni_status'] = 'unknown'
29 result['geni_resources'] = {}
32 def start_slice(api, xrn, creds):
33 hrn, type = urn_to_hrn(xrn)
34 slicename = hrn_to_pl_slicename(hrn)
35 api.nodemanger.Start(slicename)
37 def stop_slice(api, xrn, creds):
38 hrn, type = urn_to_hrn(xrn)
39 slicename = hrn_to_pl_slicename(hrn)
40 api.nodemanager.Stop(slicename)
42 def delete_slice(api, xrn, creds):
43 hrn, type = urn_to_hrn(xrn)
44 slicename = hrn_to_pl_slicename(hrn)
45 api.nodemanager.Destroy(slicename)
47 def reset_slice(api, xrn):
48 hrn, type = urn_to_hrn(xrn)
49 slicename = hrn_to_pl_slicename(hrn)
50 if not api.sliver_exists(slicename):
51 raise SliverDoesNotExist(slicename)
52 api.nodemanager.ReCreate(slicename)
55 # this returns a tuple, the data we want is at index 1
56 xids = api.nodemanager.GetXIDs()
57 # unfortunately the data we want is given to us as
58 # a string but we really want it as a dict
60 slices = eval(xids[1])
63 def redeem_ticket(api, ticket_string):
64 ticket = SfaTicket(string=ticket_string)
66 hrn = ticket.attributes['slivers'][0]['hrn']
67 slicename = hrn_to_pl_slicename(hrn)
68 if not api.sliver_exists(slicename):
69 raise SliverDoesNotExist(slicename)
71 # convert ticket to format nm is used to
72 nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
73 api.nodemanager.AdminTicket(nm_ticket)