Changeset a3ad8bd for fedd/fedd_client.py
- Timestamp:
- Dec 4, 2009 2:21:11 PM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- c17efe6
- Parents:
- 4ac0a41
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_client.py
r4ac0a41 ra3ad8bd 82 82 self.add_option("--trace", action="store_const", dest="tracefile", 83 83 const=sys.stderr, help="Print SOAP exchange to stderr") 84 class fedd_new_opts(fedd_client_opts): 85 def __init__(self): 86 fedd_client_opts.__init__(self) 87 self.add_option("-e", "--experiment_cert", dest="out_certfile", 88 type="string", help="output certificate file") 89 self.add_option("-E", "--experiment_name", dest="exp_name", 90 type="string", help="Suggested experiment name") 84 91 85 92 class fedd_create_opts(fedd_client_opts): … … 1314 1321 sys.exit("No log returned") 1315 1322 1316 class create(fedd_rpc):1323 class new(fedd_rpc): 1317 1324 def __init__(self): 1318 fedd_rpc.__init__(self, " Create")1325 fedd_rpc.__init__(self, "New") 1319 1326 def __call__(self): 1320 1327 access_keys = [] 1321 1328 # Process the options using the customized option parser defined above 1322 parser = fedd_create_opts(access_keys, self.add_ssh_key, 1323 self.add_x509_cert) 1329 parser = fedd_new_opts() 1324 1330 1325 1331 (opts, args) = parser.parse_args() … … 1329 1335 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted) 1330 1336 1331 if not opts.project :1332 parser.error('--project is required')1333 1334 1337 if opts.debug > 0: opts.tracefile=sys.stderr 1335 1338 1336 1339 (user, cert) = self.get_user_info(access_keys) 1337 1338 if opts.user: user = opts.user1339 1340 1340 1341 if opts.cert != None: cert = opts.cert … … 1345 1346 if os.access(cert, os.R_OK): 1346 1347 fid = fedid(file=cert) 1347 if opts.use_fedid == True:1348 user = fid1349 1348 else: 1350 1349 sys.exit("Cannot read certificate (%s)" % cert) 1351 1350 1352 if opts.file:1353 exp_desc = ""1354 try:1355 f = open(opts.file, 'r')1356 for line in f:1357 exp_desc += line1358 f.close()1359 except IOError:1360 sys.exit("Cannot read description file (%s)" %opts.file)1361 else:1362 sys.exit("Must specify an experiment description (--file)")1363 1364 if not opts.master:1365 sys.exit("Must specify a master testbed (--master)")1366 1367 1351 out_certfile = opts.out_certfile 1368 1352 1369 msg = { 1370 'experimentdescription': { 'ns2description': exp_desc }, 1371 'master': opts.master, 1372 'exportProject': { 'localname': opts.project }, 1373 'user' : [ {\ 1374 'userID': pack_id(user), \ 1375 'access': [ { a.type: a.buf } for a in access_keys]\ 1376 } ] 1377 } 1353 msg = { } 1378 1354 1379 1355 if opts.exp_name: … … 1412 1388 print "status: %s" % st 1413 1389 1390 1391 class create(fedd_rpc): 1392 def __init__(self): 1393 fedd_rpc.__init__(self, "Create") 1394 def __call__(self): 1395 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) 1399 1400 (opts, args) = parser.parse_args() 1401 1402 if opts.trusted: 1403 if ( not os.access(opts.trusted, os.R_OK) ) : 1404 sys.exit("Cannot read trusted certificates (%s)" % opts.trusted) 1405 1406 if not opts.project : 1407 parser.error('--project is required') 1408 1409 if opts.debug > 0: opts.tracefile=sys.stderr 1410 1411 (user, cert) = self.get_user_info(access_keys) 1412 1413 if opts.user: user = opts.user 1414 1415 if opts.cert != None: cert = opts.cert 1416 1417 if cert == None: 1418 sys.exit("No certificate given (--cert) or found") 1419 1420 if os.access(cert, os.R_OK): 1421 fid = fedid(file=cert) 1422 if opts.use_fedid == True: 1423 user = fid 1424 else: 1425 sys.exit("Cannot read certificate (%s)" % cert) 1426 1427 if opts.file: 1428 exp_desc = "" 1429 try: 1430 f = open(opts.file, 'r') 1431 for line in f: 1432 exp_desc += line 1433 f.close() 1434 except IOError: 1435 sys.exit("Cannot read description file (%s)" %opts.file) 1436 else: 1437 sys.exit("Must specify an experiment description (--file)") 1438 1439 if not opts.master: 1440 sys.exit("Must specify a master testbed (--master)") 1441 1442 out_certfile = opts.out_certfile 1443 1444 msg = { 1445 'experimentdescription': { 'ns2description': exp_desc }, 1446 'master': opts.master, 1447 'exportProject': { 'localname': opts.project }, 1448 'user' : [ {\ 1449 'userID': pack_id(user), \ 1450 'access': [ { a.type: a.buf } for a in access_keys]\ 1451 } ] 1452 } 1453 1454 if opts.exp_name: 1455 msg['experimentID'] = { 'localname': opts.exp_name } 1456 1457 if opts.debug > 1: print >>sys.stderr, msg 1458 1459 try: 1460 resp_dict = self.do_rpc(msg, 1461 opts.url, opts.transport, cert, opts.trusted, 1462 serialize_only=opts.serialize_only, 1463 tracefile=opts.tracefile) 1464 except self.RPCException, e: 1465 exit_with_fault(\ 1466 {'desc': e.desc, 'errstr': e.errstr, 'code': e.code}) 1467 except RuntimeError, e: 1468 sys.exit("Error processing RPC: %s" % e) 1469 1470 if opts.debug > 1: print >>sys.stderr, resp_dict 1471 1472 ea = resp_dict.get('experimentAccess', None) 1473 if out_certfile and ea and ea.has_key('X509'): 1474 try: 1475 f = open(out_certfile, "w") 1476 print >>f, ea['X509'] 1477 f.close() 1478 except IOError: 1479 sys.exit('Could not write to %s' % out_certfile) 1480 eid = resp_dict.get('experimentID', None) 1481 if eid: 1482 for id in eid: 1483 for k in id.keys(): 1484 print "%s: %s" % (k, id[k]) 1485 st = resp_dict.get('experimentStatus', None) 1486 if st: 1487 print "status: %s" % st 1488 1414 1489 class split(fedd_rpc): 1415 1490 def __init__(self): … … 1749 1824 1750 1825 cmds = {\ 1826 'new': new(),\ 1751 1827 'create': create(),\ 1752 1828 'split': split(),\
Note: See TracChangeset
for help on using the changeset viewer.