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