Changeset 7b26c39
- Timestamp:
- Dec 8, 2009 4:51:06 PM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 7d2814a
- Parents:
- 7183b48
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_client.py
r7183b48 r7b26c39 265 265 print>>out, "Description: %s" % dict['desc'] 266 266 sys.exit(dict.get('code', 20)) 267 # Base class that will do a the SOAP/XMLRPC exchange for a request. 267 # Base class for the various client operations. It includes some commonly used 268 # functions and classes the most important of which are the exception classes 269 # and the service calling classes. 268 270 class fedd_rpc: 271 269 272 class RPCException: 273 """ 274 An error during the RPC exchange. It unifies errors from both SOAP and 275 XMLPRC calls. 276 """ 270 277 def __init__(self, fb): 271 278 self.desc = fb.get('desc', None) … … 273 280 self.errstr = fb.get('errstr', None) 274 281 275 def __init__(self, pre): 282 class caller(service_caller): 283 """ 284 The caller is used by fedd_rpc.do_rpc to make the rpc call. The extra 285 stashed information is used to parse responses a little. 286 """ 287 def __init__(self, pre): 288 self.ResponseBody="%sResponseBody" % pre 289 self.method = pre 290 service_caller.__init__(self, self.method) 291 292 def __init__(self): 276 293 """ 277 294 Specialize the class for the pre method 278 295 """ 279 self.RequestBody="%sRequestBody" % pre 280 self.ResponseBody="%sResponseBody" % pre 281 self.method = pre 282 283 self.caller = service_caller(self.method) 296 self.caller = fedd_rpc.caller 284 297 self.RPCException = fedd_rpc.RPCException 285 298 … … 333 346 334 347 def do_rpc(self, req_dict, url, transport, cert, trusted, tracefile=None, 335 serialize_only=False ):348 serialize_only=False, caller=None): 336 349 """ 337 350 The work of sending and parsing the RPC as either XMLRPC or SOAP 338 351 """ 352 353 if caller is None: 354 raise RuntimeError("Must provide caller to do_rpc") 339 355 340 356 context = None … … 355 371 else: 356 372 try: 357 resp = self.caller.call_soap_service(url, req_dict,373 resp = caller.call_soap_service(url, req_dict, 358 374 context=context, tracefile=tracefile) 359 375 except service_error, e: … … 370 386 else: 371 387 try: 372 resp = self.caller.call_xmlrpc_service(url, req_dict,388 resp = caller.call_xmlrpc_service(url, req_dict, 373 389 context=context, tracefile=tracefile) 374 390 except service_error, e: … … 382 398 raise RuntimeError("Unknown RPC transport: %s" % transport) 383 399 384 if resp.has_key( self.ResponseBody):385 return resp[ self.ResponseBody]400 if resp.has_key(caller.ResponseBody): 401 return resp[caller.ResponseBody] 386 402 else: 387 403 raise RuntimeError("No body in response??") 388 404 389 405 class exp_data_base(fedd_rpc): 390 def __init__(self , op='Info'):406 def __init__(self): 391 407 """ 392 408 Init the various conversions 393 409 """ 394 410 395 fedd_rpc.__init__(self , op)411 fedd_rpc.__init__(self) 396 412 # List of things one could ask for and what formatting routine is 397 413 # called. … … 441 457 class exp_data(exp_data_base): 442 458 def __init__(self): 443 exp_data_base.__init__(self , 'Info')459 exp_data_base.__init__(self) 444 460 445 461 def __call__(self): … … 491 507 opts.url, opts.transport, cert, opts.trusted, 492 508 serialize_only=opts.serialize_only, 493 tracefile=opts.tracefile) 509 tracefile=opts.tracefile, 510 caller=self.caller('Info')) 494 511 except self.RPCException, e: 495 512 exit_with_fault(\ … … 542 559 class multi_exp_data(exp_data_base): 543 560 def __init__(self): 544 exp_data_base.__init__(self , 'MultiInfo')561 exp_data_base.__init__(self) 545 562 546 563 … … 578 595 opts.url, opts.transport, cert, opts.trusted, 579 596 serialize_only=opts.serialize_only, 580 tracefile=opts.tracefile) 597 tracefile=opts.tracefile, 598 caller=self.caller('MultiInfo')) 581 599 except self.RPCException, e: 582 600 exit_with_fault(\ … … 601 619 class multi_status(exp_data_base): 602 620 def __init__(self): 603 exp_data_base.__init__(self , 'MultiInfo')621 exp_data_base.__init__(self) 604 622 605 623 … … 637 655 opts.url, opts.transport, cert, opts.trusted, 638 656 serialize_only=opts.serialize_only, 639 tracefile=opts.tracefile) 657 tracefile=opts.tracefile, 658 caller=self.caller('MultiInfo')) 640 659 except self.RPCException, e: 641 660 exit_with_fault(\ … … 688 707 689 708 class image(fedd_rpc): 690 def __init__(self , op='Vtopo'):709 def __init__(self): 691 710 """ 692 711 Null constructor 693 712 """ 694 713 695 fedd_rpc.__init__(self , op)714 fedd_rpc.__init__(self) 696 715 697 716 @staticmethod … … 869 888 opts.url, opts.transport, cert, opts.trusted, 870 889 serialize_only=opts.serialize_only, 871 tracefile=opts.tracefile) 890 tracefile=opts.tracefile, 891 caller=self.caller('Vtopo')) 872 892 except self.RPCException, e: 873 893 exit_with_fault(\ … … 885 905 886 906 class ns_image(image): 887 def __init__(self , op='Ns2Split'):907 def __init__(self): 888 908 """ 889 909 Null constructor 890 910 """ 891 911 892 image.__init__(self , 'Ns2Split')912 image.__init__(self) 893 913 894 914 def generate_topo_dict(self, splitout): … … 1024 1044 opts.url, opts.transport, cert, opts.trusted, 1025 1045 serialize_only=opts.serialize_only, 1026 tracefile=opts.tracefile) 1046 tracefile=opts.tracefile, 1047 caller=self.caller('Ns2Split')) 1027 1048 except self.RPCException, e: 1028 1049 exit_with_fault(\ … … 1042 1063 1043 1064 class topdl_image(image): 1044 def __init__(self , op='Ns2Split'):1065 def __init__(self): 1045 1066 """ 1046 1067 Null constructor 1047 1068 """ 1048 1069 1049 image.__init__(self , 'Ns2Split')1070 image.__init__(self) 1050 1071 1051 1072 @staticmethod … … 1157 1178 """ 1158 1179 1159 fedd_rpc.__init__(self , "Terminate")1180 fedd_rpc.__init__(self) 1160 1181 1161 1182 def __call__(self): … … 1219 1240 opts.url, opts.transport, cert, opts.trusted, 1220 1241 serialize_only=opts.serialize_only, 1221 tracefile=opts.tracefile) 1242 tracefile=opts.tracefile, 1243 caller=self.caller('Terminate')) 1222 1244 except self.RPCException, e: 1223 1245 exit_with_fault(\ … … 1242 1264 """ 1243 1265 1244 fedd_rpc.__init__(self , "TerminateSegment")1266 fedd_rpc.__init__(self) 1245 1267 1246 1268 def __call__(self): … … 1304 1326 opts.url, opts.transport, cert, opts.trusted, 1305 1327 serialize_only=opts.serialize_only, 1306 tracefile=opts.tracefile) 1328 tracefile=opts.tracefile, 1329 caller=self.caller('TerminateSegment')) 1307 1330 except self.RPCException, e: 1308 1331 exit_with_fault(\ … … 1323 1346 class new(fedd_rpc): 1324 1347 def __init__(self): 1325 fedd_rpc.__init__(self , "New")1348 fedd_rpc.__init__(self) 1326 1349 def __call__(self): 1327 1350 access_keys = [] … … 1362 1385 opts.url, opts.transport, cert, opts.trusted, 1363 1386 serialize_only=opts.serialize_only, 1364 tracefile=opts.tracefile) 1387 tracefile=opts.tracefile, 1388 caller=self.caller("New")) 1365 1389 except self.RPCException, e: 1366 1390 exit_with_fault(\ … … 1391 1415 class create(fedd_rpc): 1392 1416 def __init__(self): 1393 fedd_rpc.__init__(self, "Create")1417 fedd_rpc.__init__(self) 1394 1418 def __call__(self): 1395 1419 access_keys = [] 1396 # Process the options using the customized option parser defined above 1397 parser = fedd_create_opts(access_keys, self.add_ssh_key, 1398 self.add_x509_cert) 1420 parser = fedd_create_opts(access_keys, self.add_ssh_key, 1421 self.add_x509_cert) 1399 1422 1400 1423 (opts, args) = parser.parse_args() … … 1442 1465 out_certfile = opts.out_certfile 1443 1466 1467 msg = { } 1468 1469 if opts.exp_name: 1470 msg['experimentID'] = { 'localname': opts.exp_name } 1471 1472 if opts.debug > 1: print >>sys.stderr, msg 1473 1474 try: 1475 resp_dict = self.do_rpc(msg, 1476 opts.url, opts.transport, cert, opts.trusted, 1477 serialize_only=opts.serialize_only, 1478 tracefile=opts.tracefile, 1479 caller=self.caller('New')) 1480 except self.RPCException, e: 1481 exit_with_fault(\ 1482 {'desc': e.desc, 'errstr': e.errstr, 'code': e.code}) 1483 except RuntimeError, e: 1484 sys.exit("Error processing RPC: %s" % e) 1485 1486 if opts.debug > 1: print >>sys.stderr, resp_dict 1487 1488 ea = resp_dict.get('experimentAccess', None) 1489 if out_certfile and ea and ea.has_key('X509'): 1490 try: 1491 f = open(out_certfile, "w") 1492 print >>f, ea['X509'] 1493 f.close() 1494 except IOError: 1495 sys.exit('Could not write to %s' % out_certfile) 1496 eid = resp_dict.get('experimentID', None) 1497 e_fedid = None 1498 e_local = None 1499 if eid: 1500 for id in eid: 1501 for k in id.keys(): 1502 print "%s: %s" % (k, id[k]) 1503 if k =='fedid': 1504 e_fedid = id[k] 1505 elif k =='localname': 1506 e_local = id[k] 1507 1508 st = resp_dict.get('experimentStatus', None) 1509 if st: 1510 print "status: %s" % st 1511 1512 1444 1513 msg = { 1445 1514 'experimentdescription': { 'ns2description': exp_desc }, … … 1452 1521 } 1453 1522 1454 if opts.exp_name: 1455 msg['experimentID'] = { 'localname': opts.exp_name } 1523 if e_fedid: 1524 msg['experimentID'] = { 'fedid': e_fedid } 1525 elif e_local: 1526 msg['experimentID'] = { 'localname': e_local } 1527 else: 1528 sys.exit("New did not return an experiment ID??") 1456 1529 1457 1530 if opts.debug > 1: print >>sys.stderr, msg … … 1461 1534 opts.url, opts.transport, cert, opts.trusted, 1462 1535 serialize_only=opts.serialize_only, 1463 tracefile=opts.tracefile) 1536 tracefile=opts.tracefile, 1537 caller=self.caller('Create')) 1464 1538 except self.RPCException, e: 1465 1539 exit_with_fault(\ … … 1489 1563 class split(fedd_rpc): 1490 1564 def __init__(self): 1491 fedd_rpc.__init__(self , "Ns2Split")1565 fedd_rpc.__init__(self) 1492 1566 def __call__(self): 1493 1567 access_keys = [] … … 1548 1622 opts.url, opts.transport, cert, opts.trusted, 1549 1623 serialize_only=opts.serialize_only, 1550 tracefile=opts.tracefile) 1624 tracefile=opts.tracefile, 1625 caller=self.caller('Ns2Split')) 1551 1626 except self.RPCException, e: 1552 1627 exit_with_fault(\ … … 1564 1639 class access(fedd_rpc): 1565 1640 def __init__(self): 1566 fedd_rpc.__init__(self , "RequestAccess")1641 fedd_rpc.__init__(self) 1567 1642 1568 1643 def print_response_as_testbed(self, resp, label, out=sys.stdout): … … 1664 1739 opts.url, opts.transport, cert, opts.trusted, 1665 1740 serialize_only=opts.serialize_only, 1666 tracefile=opts.tracefile) 1741 tracefile=opts.tracefile, 1742 caller=self.caller('RequestAccess')) 1667 1743 except self.RPCException, e: 1668 1744 exit_with_fault(\ … … 1682 1758 """ 1683 1759 1684 fedd_rpc.__init__(self , 'Info')1760 fedd_rpc.__init__(self) 1685 1761 1686 1762 def __call__(self): … … 1740 1816 opts.url, opts.transport, cert, opts.trusted, 1741 1817 serialize_only=opts.serialize_only, 1742 tracefile=opts.tracefile) 1818 tracefile=opts.tracefile, 1819 caller=self.caller('Info')) 1743 1820 except self.RPCException, e: 1744 1821 exit_with_fault(\ … … 1765 1842 class start_segment(fedd_rpc): 1766 1843 def __init__(self): 1767 fedd_rpc.__init__(self , "StartSegment")1844 fedd_rpc.__init__(self) 1768 1845 def __call__(self): 1769 1846 # Process the options using the customized option parser defined above … … 1811 1888 opts.url, opts.transport, cert, opts.trusted, 1812 1889 serialize_only=opts.serialize_only, 1813 tracefile=opts.tracefile) 1890 tracefile=opts.tracefile, 1891 caller=self.caller('StartSegment')) 1814 1892 except self.RPCException, e: 1815 1893 exit_with_fault(\ -
wsdl/fedd_types.xsd
r7183b48 r7b26c39 480 480 <xsd:element name="testbedmap" type="tns:mapType" minOccurs="0" 481 481 maxOccurs="unbounded"/> 482 <!-- this can go away pretty quickly, I think --> 482 483 <xsd:element name="user" type="tns:userType" minOccurs="1" 483 484 maxOccurs="unbounded"/> … … 486 487 <xsd:element name="master" type="xsd:string"/> 487 488 <xsd:element name='exportProject' type="tns:IDType"/> 488 <xsd:element name="experimentID" type="tns:IDType" minOccurs="0" 489 maxOccurs="1"/> 489 <xsd:element name="experimentID" type="tns:IDType"/> 490 490 </xsd:sequence> 491 491 </xsd:complexType> … … 502 502 maxOccurs="unbounded"/> 503 503 <xsd:element name="experimentStatus" type="tns:statusType"/> 504 <xsd:element name="experimentAccess" type="tns:accessType" minOccurs="0"505 maxOccurs="1"/>506 504 </xsd:sequence> 507 505 </xsd:complexType>
Note: See TracChangeset
for help on using the changeset viewer.