3 from sfa.util.faults import *
4 from sfa.util.namespace import *
5 from sfa.util.sfaticket import SfaTicket
8 from sfa.server import sfa_component_setup
9 # get current trusted gids
11 sfa_component_setup.get_trusted_certs()
13 # our keypair may be old, try refreshing
14 sfa_component_setup.get_node_key()
15 sfa_component_setup.get_credential(force=True)
16 sfa_component_setup.get_trusted_certs()
20 version['geni_api'] = 1
23 def slice_status(api, slice_xrn, creds):
25 result['geni_urn'] = slice_xrn
26 result['geni_status'] = 'unknown'
27 result['geni_resources'] = {}
30 def start_slice(api, xrn, creds):
31 hrn, type = urn_to_hrn(xrn)
32 slicename = hrn_to_pl_slicename(hrn)
33 api.nodemanger.Start(slicename)
35 def stop_slice(api, xrn, creds):
36 hrn, type = urn_to_hrn(xrn)
37 slicename = hrn_to_pl_slicename(hrn)
38 api.nodemanager.Stop(slicename)
40 def delete_slice(api, xrn, creds):
41 hrn, type = urn_to_hrn(xrn)
42 slicename = hrn_to_pl_slicename(hrn)
43 api.nodemanager.Destroy(slicename)
45 def reset_slice(api, xrn):
46 hrn, type = urn_to_hrn(xrn)
47 slicename = hrn_to_pl_slicename(hrn)
48 if not api.sliver_exists(slicename):
49 raise SliverDoesNotExist(slicename)
50 api.nodemanager.ReCreate(slicename)
53 # this returns a tuple, the data we want is at index 1
54 xids = api.nodemanager.GetXIDs()
55 # unfortunately the data we want is given to us as
56 # a string but we really want it as a dict
58 slices = eval(xids[1])
61 def redeem_ticket(api, ticket_string):
62 ticket = SfaTicket(string=ticket_string)
64 hrn = ticket.attributes['slivers'][0]['hrn']
65 slicename = hrn_to_pl_slicename(hrn)
66 if not api.sliver_exists(slicename):
67 raise SliverDoesNotExist(slicename)
69 # convert ticket to format nm is used to
70 nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
71 api.nodemanager.AdminTicket(nm_ticket)