namespace module is gone, plxrn provides PL-specific translations
[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.xrn import urn_to_hrn
6 from sfa.util.plxrn import hrn_to_pl_slicename
7 from sfa.util.sfaticket import SfaTicket
8
9 def init_server():
10     from sfa.server import sfa_component_setup
11     # get current trusted gids
12     try:
13         sfa_component_setup.get_trusted_certs()
14     except:
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()
19
20 def get_version():
21     version = {}
22     version['geni_api'] = 1
23     return version
24
25 def slice_status(api, slice_xrn, creds):
26     result = {}
27     result['geni_urn'] = slice_xrn
28     result['geni_status'] = 'unknown'
29     result['geni_resources'] = {}
30     return result
31            
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)
36
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)
41
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)
46
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)
53  
54 def get_slices(api):
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
59     # lets eval it
60     slices = eval(xids[1])
61     return slices.keys()
62
63 def redeem_ticket(api, ticket_string):
64     ticket = SfaTicket(string=ticket_string)
65     ticket.decode()
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)
70
71     # convert ticket to format nm is used to
72     nm_ticket = xmlrpclib.dumps((ticket.attributes,), methodresponse=True)
73     api.nodemanager.AdminTicket(nm_ticket)
74     
75