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 *
21 # SliceMgr class extends GeniServer class
23 class SliceMgr(GeniServer):
25 # Create a new slice manager object.
27 # @param ip the ip address to listen on
28 # @param port the port to listen on
29 # @param key_file private key filename of registry
30 # @param cert_file certificate filename containing public key (could be a GID file)
32 def __init__(self, ip, port, key_file, cert_file):
33 GeniServer.__init__(self, ip, port, key_file, cert_file)
35 # get PL account settings from config module
36 self.pl_auth = get_pl_auth()
38 # connect to planetlab
39 if "Url" in self.pl_auth:
40 self.connect_remote_shell()
42 self.connect_local_shell()
45 # Connect to a remote shell via XMLRPC
47 def connect_remote_shell(self):
49 self.shell = remoteshell.RemoteShell()
52 # Connect to a local shell via local API functions
54 def connect_local_shell(self):
56 self.shell = PLC.Shell.Shell(globals = globals())
59 # Register the server RPCs for the slice interface
61 def register_functions(self):
62 GeniServer.register_functions(self)
64 self.server.register_function(self.create_slice)
65 self.server.register_function(self.get_ticket)
66 self.server.register_function(self.redeem_ticket)
67 self.server.register_function(self.start_slice)
68 self.server.register_function(self.stop_slice)
69 self.server.register_function(self.reset_slice)
70 self.server.register_function(self.delete_slice)
71 self.server.register_function(self.get_slice_resources)
72 self.server.register_function(self.list_slices)
73 self.server.register_function(self.list_nodes)
76 # create_slice: Create (instantiate) a slice.
78 # @param cred credential string
79 # @param name name of the slice to retrieve a ticket for
80 # @param rspec resource specification dictionary
82 # @return the string representation of a ticket object
84 def create_slice(self, cred, name, rspec):
85 self.decode_authentication(cred, "createslice")
86 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
87 # extract per-aggregate netspec from rspec
88 # call create_slice on each aggregate
91 # get_ticket: Retrieve a ticket.
93 # This operation is not supported as part of a slice manager
95 # @param cred credential string
96 # @param name name of the slice to retrieve a ticket for
97 # @param rspec resource specification dictionary
100 def get_ticket(self, cred, name, rspec):
104 # redeem_ticket: Redeem a ticket.
106 # This operation is not supported as part of a slice manager
108 # @param cred credential string
109 # @param name name of the slice to retrieve a ticket for
110 # @param rspec resource specification dictionary
113 def redeem_ticket(self, cred, name, rspec):
117 # stop_slice: Stop a slice.
119 # @param cred a credential identifying the caller (callerGID) and the slice
122 def stop_slice(self, cred_str):
123 self.decode_authentication(cred_str, "stopslice")
124 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
125 # call stop_slice on each aggregate that hosts the slice
128 # start_slice: Start a slice.
130 # @param cred a credential identifying the caller (callerGID) and the slice
133 def start_slice(self, cred_str):
134 self.decode_authentication(cred_str, "startslice")
135 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
136 # call start_slice on each aggregate that hosts the slice
139 # reset_slice: Reset a slice.
141 # @param cred a credential identifying the caller (callerGID) and the slice
144 def reset_slice(self, cred_str):
145 self.decode_authentication(cred_str, "resetslice")
146 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
147 # call reset_slice on each aggregate that hosts the slice
150 # delete_slice: Delete a slice.
152 # @param cred a credential identifying the caller (callerGID) and the slice
155 def delete_slice(self, cred_str):
156 self.decode_authentication(cred_str, "deleteslice")
157 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
158 # call delete_slice on each aggregate that hosts the slice
161 # get_slice_resources: Get resources allocated to slice
163 # @param cred a credential identifying the caller (callerGID) and the slice
166 def get_slice_resources(self, cred_str):
167 self.decode_authentication(cred_str, "getsliceresources")
168 slicename = hrn_to_pl_slicename(self.object_gid.get_hrn())
169 # call get_resources on each aggregate that hosts the slice
170 # merge returned netspecs into one big rspec
173 # list_slices: List hosted slices.
175 # @param cred a credential identifying the caller (callerGID)
177 def list_slices(self, cred_str):
178 self.decode_authentication(cred_str, "listslices")
179 # probably have this information cached, so return that
180 # otherwise, call list_slices on all peer aggregates
183 # list_nodes: List available nodes.
185 # @param cred a credential identifying the caller (callerGID)
187 def list_nodes(self, cred_str):
188 self.decode_authentication(cred_str, "listslices")
189 # probably have this information cached, so return that
190 # otherwise, call list_nodes on all peer aggregates