Changeset 19cc408
- Timestamp:
- Oct 3, 2008 4:46:21 PM (16 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-1.30, version-2.00, version-3.01, version-3.02
- Children:
- ea0a821
- Parents:
- 01073f7
- Location:
- fedd
- Files:
-
- 4 added
- 1 deleted
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd.py
r01073f7 r19cc408 15 15 16 16 from fedd_util import fedd_ssl_context, fedid 17 from fedd_proj import new_feddservice 17 from fedd_deter_impl import new_feddservice 18 from service_error import * 18 19 19 20 # The SSL server here is based on the implementation described at … … 27 28 SSLServer.__init__(self, ME, handler, ssl_ctx) 28 29 self.impl = impl 30 self.soap_methods = impl.get_soap_services() 31 self.xmlrpc_methods = impl.get_xmlrpc_services() 29 32 30 33 class fedd_soap_handler(BaseHTTPRequestHandler): 31 34 server_version = "ZSI/2.0 fedd/0.1 " + BaseHTTPRequestHandler.server_version 32 33 35 34 36 def send_xml(self, text, code=200): … … 80 82 if not self.check_method(ps): return 81 83 try: 82 resp = self.s erver.impl.soap_dispatch(ps.body_root.localName, ps,84 resp = self.soap_dispatch(ps.body_root.localName, ps, 83 85 fedid(cert=self.request.get_peer_cert())) 84 86 except Fault, f: … … 91 93 self.send_xml(str(sw)) 92 94 95 def soap_dispatch(self, method, req, fid): 96 if self.server.soap_methods.has_key(method): 97 try: 98 return self.server.soap_methods[method](req, fid) 99 except service_error, e: 100 de = ns0.faultType_Def( 101 (ns0.faultType_Def.schema, 102 "FeddFaultBody")).pyclass() 103 de._code=e.code 104 de._errstr=e.code_string() 105 de._desc=e.desc 106 if e.is_server_error(): 107 raise Fault(Fault.Server, e.code_string(), detail=de) 108 else: 109 raise Fault(Fault.Client, e.code_string(), detail=de) 110 else: 111 raise Fault(Fault.Client, "Unknown method: %s" % method) 112 113 93 114 class fedd_xmlrpc_handler(BaseHTTPRequestHandler): 94 115 server_version = "ZSI/2.0 fedd/0.1 " + BaseHTTPRequestHandler.server_version … … 120 141 if method != None: 121 142 try: 122 resp = self. server.impl.xmlrpc_dispatch(method, params,143 resp = self.xmlrpc_dispatch(method, params, 123 144 fedid(cert=self.request.get_peer_cert())) 124 145 data = xmlrpclib.dumps((resp,), encoding='UTF-8', … … 129 150 self.send_xml(data) 130 151 152 153 def xmlrpc_dispatch(self, method, req, fid): 154 if self.server.xmlrpc_methods.has_key(method): 155 try: 156 return self.server.xmlrpc_methods[method](req, fid) 157 except service_error, e: 158 raise xmlrpclib.Fault(e.code_string(), e.desc) 159 else: 160 raise xmlrpclib.Fault(100, "Unknown method: %s" % method) 131 161 132 162 class fedd_opts(OptionParser): -
fedd/fedd_allocate_project.py
r01073f7 r19cc408 16 16 import subprocess 17 17 import tempfile 18 import copy19 18 20 19 from fedd_services import * -
fedd/fedd_experiment_control.py
r01073f7 r19cc408 29 29 from service_error import * 30 30 31 class fedd_ create_experiment_local:31 class fedd_experiment_control_local: 32 32 scripts = ["fed_bootstrap", "federate.sh", "smbmount.FreeBSD.pl", 33 33 "smbmount.Linux.pl", "make_hosts", "fed-tun.pl", "fed-tun.ucb.pl", 34 34 "fed_evrepeater", "rc.accounts.patch"] 35 35 36 def __init__(self,37 cert_file=None,38 cert_pwd=None,39 exp_stem="fed-stem",40 debug=False,41 muxmax=2,42 nthreads=2,43 randomize_experiments=False,44 scp_exec="/usr/bin/scp",45 scripts_dir="./",46 splitter=None,47 ssh_exec="/usr/bin/ssh",48 ssh_identity_file=None,49 ssh_keygen="/usr/bin/ssh-keygen",50 ssh_pubkey_file=None,51 ssh_type="rsa",52 tbmap=None,53 tclsh="/usr/local/bin/otclsh",54 tcl_splitter="/usr/testbed/lib/ns2ir/parse.tcl",55 trace_file=None,56 trusted_certs=None,57 ):58 self.scripts = fedd_create_experiment_local.scripts59 self.thread_with_rv = fedd_create_experiment_local.pooled_thread60 self.thread_pool = fedd_create_experiment_local.thread_pool61 62 self.cert_file = cert_file63 self.cert_pwd = cert_pwd64 self.exp_stem = exp_stem65 self.debug = debug66 self.muxmax = muxmax67 self.nthreads = nthreads68 self.randomize_experiments = randomize_experiments69 self.scp_exec = scp_exec70 self.scripts_dir = scripts_dir71 self.splitter = splitter72 self.ssh_exec=ssh_exec73 self.ssh_keygen = ssh_keygen74 self.ssh_identity_file = ssh_identity_file75 self.ssh_type = ssh_type76 self.state = { }77 self.tclsh = tclsh78 self.tcl_splitter = tcl_splitter79 self.tbmap = tbmap80 self.trace_file = trace_file81 self.trusted_certs=trusted_certs82 83 self.def_expstart = \84 "sudo -H /bin/sh FEDDIR/fed_bootstrap >& /tmp/federate";85 self.def_mexpstart = "sudo -H FEDDIR/make_hosts FEDDIR/hosts";86 self.def_gwstart = \87 "sudo -H FEDDIR/fed-tun.pl -f GWCONF>& /tmp/bridge.log";88 self.def_mgwstart = \89 "sudo -H FEDDIR/fed-tun.pl -f GWCONF >& /tmp/bridge.log";90 self.def_gwimage = "FBSD61-TUNNEL2";91 self.def_gwtype = "pc";92 93 94 if ssh_pubkey_file:95 try:96 f = open(ssh_pubkey_file, 'r')97 self.ssh_pubkey = f.read()98 f.close()99 except IOError:100 raise service_error(service_error.internal,101 "Cannot read sshpubkey")102 103 # Confirm federation scripts in the right place104 for s in self.scripts:105 if not os.path.exists(self.scripts_dir + "/" + s):106 raise service_error(service_error.server_config,107 "%s/%s not in local script dir" % (self.scripts_dir, s))108 36 class thread_pool: 109 37 def __init__(self): … … 139 67 self.changed.notifyAll() 140 68 self.changed.release() 141 142 143 69 144 70 class pooled_thread(Thread): … … 177 103 if self.pdata: 178 104 self.pdata.terminate() 105 106 def __init__(self, config=None): 107 self.scripts = fedd_experiment_control_local.scripts 108 self.thread_with_rv = fedd_experiment_control_local.pooled_thread 109 self.thread_pool = fedd_experiment_control_local.thread_pool 110 111 self.cert_file = None 112 self.cert_pwd = None 113 self.trusted_certs = None 114 115 if config.create_experiment_cert_file: 116 self.cert_file = config.create_experiment_cert_file 117 self.cert_pwd = config.create_experiment_cert_pwd 118 if config.create_experiment_trusted_certs: 119 self.trusted_certs = config.create_experiment_trusted_certs 120 121 if config.proxy_cert_file: 122 if not self.cert_file: 123 self.cert_file = config.proxy_cert_file 124 self.cert_pwd = config.proxy_cert_pwd 125 if config.proxy_trusted_certs: 126 if not self.trusted_certs: 127 self.trusted_certs = config.proxy_trusted_certs 128 129 if config.cert_file: 130 if not self.cert_file: 131 self.cert_file = config.cert_file 132 self.cert_pwd = config.cert_pwd 133 if config.trusted_certs: 134 if not self.trusted_certs: 135 self.trusted_certs = config.trusted_certs 136 137 self.exp_stem = "fed-stem" 138 self.debug = config.create_debug 139 self.muxmax = 2 140 self.nthreads = 2 141 self.randomize_experiments = False 142 self.scp_exec = "/usr/bin/scp" 143 self.scripts_dir = "/users/faber/testbed/federation" 144 self.splitter = None 145 self.ssh_exec="/usr/bin/ssh" 146 self.ssh_keygen = "/usr/bin/ssh-keygen" 147 self.ssh_identity_file = None 148 # XXX 149 self.ssh_pubkey_file = "/users/faber/.ssh/id_rsa.pub" 150 self.ssh_type = "rsa" 151 self.state = { } 152 self.tclsh = "/usr/local/bin/otclsh" 153 self.tcl_splitter = "/usr/testbed/lib/ns2ir/parse.tcl" 154 self.tbmap = { 155 'deter':'https://users.isi.deterlab.net:23235', 156 'emulab':'https://users.isi.deterlab.net:23236', 157 'ucb':'https://users.isi.deterlab.net:23237', 158 } 159 self.trace_file = sys.stderr 160 161 self.def_expstart = \ 162 "sudo -H /bin/sh FEDDIR/fed_bootstrap >& /tmp/federate"; 163 self.def_mexpstart = "sudo -H FEDDIR/make_hosts FEDDIR/hosts"; 164 self.def_gwstart = \ 165 "sudo -H FEDDIR/fed-tun.pl -f GWCONF>& /tmp/bridge.log"; 166 self.def_mgwstart = \ 167 "sudo -H FEDDIR/fed-tun.pl -f GWCONF >& /tmp/bridge.log"; 168 self.def_gwimage = "FBSD61-TUNNEL2"; 169 self.def_gwtype = "pc"; 170 171 172 if self.ssh_pubkey_file: 173 try: 174 f = open(self.ssh_pubkey_file, 'r') 175 self.ssh_pubkey = f.read() 176 f.close() 177 except IOError: 178 raise service_error(service_error.internal, 179 "Cannot read sshpubkey") 180 181 # Confirm federation scripts in the right place 182 for s in self.scripts: 183 if not os.path.exists(self.scripts_dir + "/" + s): 184 raise service_error(service_error.server_config, 185 "%s/%s not in local script dir" % (self.scripts_dir, s)) 186 187 self.soap_handlers = {\ 188 'Create': make_soap_handler(\ 189 CreateRequestMessage.typecode, 190 getattr(self, "create_experiment"), 191 CreateResponseMessage, 192 "CreateResponseBody"), 193 'Vtopo': make_soap_handler(\ 194 VtopoRequestMessage.typecode, 195 getattr(self, "get_vtopo"), 196 VtopoResponseMessage, 197 "VtopoResponseBody"), 198 'Vis': make_soap_handler(\ 199 VisRequestMessage.typecode, 200 getattr(self, "get_vis"), 201 VisResponseMessage, 202 "VisResponseBody"), 203 'Info': make_soap_handler(\ 204 InfoRequestMessage.typecode, 205 getattr(self, "get_info"), 206 InfoResponseMessage, 207 "InfoResponseBody"), 208 'Terminate': make_soap_handler(\ 209 TerminateRequestMessage.typecode, 210 getattr(self, "terminate_experiment"), 211 TerminateResponseMessage, 212 "TerminateResponseBody"), 213 } 214 215 self.xmlrpc_handlers = {\ 216 'Create': make_xmlrpc_handler(\ 217 getattr(self, "create_experiment"), 218 "CreateResponseBody"), 219 'Vtopo': make_xmlrpc_handler(\ 220 getattr(self, "get_vtopo"), 221 "VtopoResponseBody"), 222 'Vis': make_xmlrpc_handler(\ 223 getattr(self, "get_vis"), 224 "VisResponseBody"), 225 'Info': make_xmlrpc_handler(\ 226 getattr(self, "get_info"), 227 "InfoResponseBody"), 228 'Terminate': make_xmlrpc_handler(\ 229 getattr(self, "terminate_experiment"), 230 "TerminateResponseBody"), 231 } 232 233 def get_soap_services(self): 234 return self.soap_handlers 235 236 def get_xmlrpc_services(self): 237 return self.xmlrpc_handlers 179 238 180 239 def copy_file(self, src, dest, size=1024): … … 650 709 # No retry loop here. Proxy servers must correctly authenticate 651 710 # themselves without help 711 652 712 try: 653 713 ctx = fedd_ssl_context(self.cert_file, … … 666 726 msg.set_element_RequestAccessRequestBody( 667 727 pack_soap(msg, "RequestAccessRequestBody", req)) 728 668 729 try: 669 730 resp = port.RequestAccess(msg) -
fedd/fedd_util.py
r01073f7 r19cc408 329 329 if keypath: os.remove(keypath) 330 330 if certpath: os.remove(certpath) 331 332 333 def make_soap_handler(typecode, method, constructor, body_name): 334 """ 335 Generate the handler code to unpack and pack SOAP requests and responses 336 and call the given method. 337 338 The code to decapsulate and encapsulate parameters encoded in SOAP is the 339 same modulo a few parameters. This is basically a stub compiler for 340 calling a fedd service trhough a soap interface. The parameters are the 341 typecode of the request parameters, the method to call (usually a bound 342 instance of a method on a fedd service providing class), the constructor of 343 a response packet and the name of the body element of that packet. The 344 handler takes a ParsedSoap object (the request) and returns an instance of 345 the class created by constructor containing the response. Failures of the 346 constructor or badly created constructors will result in None being 347 returned. 348 """ 349 def handler(ps, fid): 350 req = ps.Parse(typecode) 351 352 msg = method(unpack_soap(req), fedid) 353 354 resp = constructor() 355 set_element = getattr(resp, "set_element_%s" % body_name, None) 356 if set_element and callable(set_element): 357 try: 358 set_element(pack_soap(resp, body_name, msg)) 359 return resp 360 except (NameError, TypeError): 361 return None 362 else: 363 return None 364 365 return handler 366 367 def make_xmlrpc_handler(method, body_name, input_binaries=('fedid',), 368 output_binaries=('fedid',)): 369 """ 370 Generate the handler code to unpack and pack SOAP requests and responses 371 and call the given method. 372 373 The code to marshall and unmarshall XMLRPC parameters to and from a fedd 374 service is largely the same. This helper creates such a handler. The 375 parameters are the method name, the name of the body struct that contains 376 the response asn the list of fields that are encoded as Binary objects in 377 the input and in the output. A handler is created that takes the params 378 response from an xm,lrpclib.loads on the incoming rpc and a fedid and 379 responds with a hash representing the struct ro be returned to the other 380 side. On error None is returned. 381 """ 382 def handler(params, fid): 383 p = decapsulate_binaries(params[0], input_binaries) 384 msg = method(p, fedid) 385 386 if msg != None: 387 return encapsulate_binaries({ body_name: msg }, output_binaries) 388 else: 389 return None 390 391 return handler
Note: See TracChangeset
for help on using the changeset viewer.