2 # SliceMgr is a GeniServer that implements the Slice interface at PLC
9 from util.hierarchy import Hierarchy
10 from util.trustedroot import TrustedRootList
11 from util.cert import Keypair, Certificate
12 from util.gid import GID
13 from util.geniserver import GeniServer
14 from util.record import GeniRecord
15 from util.genitable import GeniTable
16 from util.geniticket import Ticket
17 from util.excep import *
18 from util.misc import *
20 from util.config import *
23 # SliceMgr class extends GeniServer class
25 class SliceMgr(GeniServer):
27 # Create a new slice manager object.
29 # @param ip the ip address to listen on
30 # @param port the port to listen on
31 # @param key_file private key filename of registry
32 # @param cert_file certificate filename containing public key (could be a GID file)
34 def __init__(self, ip, port, key_file, cert_file):
35 GeniServer.__init__(self, ip, port, key_file, cert_file)
37 # get PL account settings from config module
38 self.pl_auth = get_pl_auth()
40 # connect to planetlab
41 if "Url" in self.pl_auth:
42 self.connect_remote_shell()
44 self.connect_local_shell()
47 # Connect to a remote shell via XMLRPC
49 def connect_remote_shell(self):
51 self.shell = remoteshell.RemoteShell()
54 # Connect to a local shell via local API functions
56 def connect_local_shell(self):
58 self.shell = PLC.Shell.Shell(globals = globals())
61 # Register the server RPCs for the slice interface
63 def register_functions(self):
64 GeniServer.register_functions(self)
66 self.server.register_function(self.create_slice)
67 self.server.register_function(self.get_ticket)
68 self.server.register_function(self.redeem_ticket)
69 self.server.register_function(self.start_slice)
70 self.server.register_function(self.stop_slice)
71 self.server.register_function(self.reset_slice)
72 self.server.register_function(self.delete_slice)
73 self.server.register_function(self.get_slice_resources)
74 self.server.register_function(self.list_slices)
75 self.server.register_function(self.list_nodes)
78 # create_slice: Create (instantiate) a slice.
80 # @param cred credential string
81 # @param name name of the slice to retrieve a ticket for
82 # @param rspec resource specification dictionary
84 # @return the string representation of a ticket object
86 def create_slice(self, cred, name, rspec):
87 self.decode_authentication(cred, "createslice")
88 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
89 # extract per-aggregate netspec from rspec
90 # call create_slice on each aggregate
93 # get_ticket: Retrieve a ticket.
95 # This operation is not supported as part of a slice manager
97 # @param cred credential string
98 # @param name name of the slice to retrieve a ticket for
99 # @param rspec resource specification dictionary
102 def get_ticket(self, cred, name, rspec):
106 # redeem_ticket: Redeem a ticket.
108 # This operation is not supported as part of a slice manager
110 # @param cred credential string
111 # @param name name of the slice to retrieve a ticket for
112 # @param rspec resource specification dictionary
115 def redeem_ticket(self, cred, name, rspec):
119 # stop_slice: Stop a slice.
121 # @param cred a credential identifying the caller (callerGID) and the slice
124 def stop_slice(self, cred_str):
125 self.decode_authentication(cred_str, "stopslice")
126 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
127 # call stop_slice on each aggregate that hosts the slice
130 # start_slice: Start a slice.
132 # @param cred a credential identifying the caller (callerGID) and the slice
135 def start_slice(self, cred_str):
136 self.decode_authentication(cred_str, "startslice")
137 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
138 # call start_slice on each aggregate that hosts the slice
141 # reset_slice: Reset a slice.
143 # @param cred a credential identifying the caller (callerGID) and the slice
146 def reset_slice(self, cred_str):
147 self.decode_authentication(cred_str, "resetslice")
148 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
149 # call reset_slice on each aggregate that hosts the slice
152 # delete_slice: Delete a slice.
154 # @param cred a credential identifying the caller (callerGID) and the slice
157 def delete_slice(self, cred_str):
158 self.decode_authentication(cred_str, "deleteslice")
159 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
160 # call delete_slice on each aggregate that hosts the slice
163 # get_slice_resources: Get resources allocated to slice
165 # @param cred a credential identifying the caller (callerGID) and the slice
168 def get_slice_resources(self, cred_str):
169 self.decode_authentication(cred_str, "getsliceresources")
170 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
171 # call get_resources on each aggregate that hosts the slice
172 # merge returned netspecs into one big rspec
175 # list_slices: List hosted slices.
177 # @param cred a credential identifying the caller (callerGID)
179 def list_slices(self, cred_str):
180 self.decode_authentication(cred_str, "listslices")
181 # probably have this information cached, so return that
182 # otherwise, call list_slices on all peer aggregates
185 # list_nodes: List available nodes.
187 # @param cred a credential identifying the caller (callerGID)
189 def list_nodes(self, cred_str):
190 self.decode_authentication(cred_str, "listslices")
191 # probably have this information cached, so return that
192 # otherwise, call list_nodes on all peer aggregates