5c9506df069d37b3db3276d5beb4864c91c64f62
[sfa.git] / sfa / managers / component_manager_pl.py
1 import os
2 import xmlrpclib
3
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
7
8 def init_server():
9     from sfa.server import sfa_component_setup
10     # get current trusted gids
11     try:
12         sfa_component_setup.get_trusted_certs()
13     except:
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()
18
19 def get_version():
20     version = {}
21     version['geni_api'] = 1
22     return version
23
24 def slice_status(api, slice_xrn, creds):
25     result = {}
26     result['geni_urn'] = slice_xrn
27     result['geni_status'] = 'unknown'
28     result['geni_resources'] = {}
29     return result
30            
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)
35
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)
40
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)
45
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)
52  
53 def get_slices(api):
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
58     # lets eval it
59     slices = eval(xids[1])
60     return slices.keys()
61
62 def redeem_ticket(api, ticket_string):
63     ticket = SfaTicket(string=ticket_string)
64     ticket.decode()
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)
69
70     # convert ticket to format nm is used to
71     nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
72     api.nodemanager.AdminTicket(nm_ticket)
73     
74