Ignore:
Timestamp:
Dec 4, 2009 2:21:11 PM (14 years ago)
Author:
Ted Faber <faber@…>
Branches:
axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
Children:
c17efe6
Parents:
4ac0a41
Message:

checkpoint, adding new operation - prequel to splitting the create call to allow delegation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/fedd_client.py

    r4ac0a41 ra3ad8bd  
    8282        self.add_option("--trace", action="store_const", dest="tracefile",
    8383                const=sys.stderr, help="Print SOAP exchange to stderr")
     84class 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")
    8491
    8592class fedd_create_opts(fedd_client_opts):
     
    13141321                sys.exit("No log returned")
    13151322
    1316 class create(fedd_rpc):
     1323class new(fedd_rpc):
    13171324    def __init__(self):
    1318         fedd_rpc.__init__(self, "Create")
     1325        fedd_rpc.__init__(self, "New")
    13191326    def __call__(self):
    13201327        access_keys = []
    13211328        # 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()
    13241330
    13251331        (opts, args) = parser.parse_args()
     
    13291335                sys.exit("Cannot read trusted certificates (%s)" % opts.trusted)
    13301336
    1331         if not opts.project :
    1332             parser.error('--project is required')
    1333 
    13341337        if opts.debug > 0: opts.tracefile=sys.stderr
    13351338
    13361339        (user, cert) = self.get_user_info(access_keys)
    1337 
    1338         if opts.user: user = opts.user
    13391340
    13401341        if opts.cert != None: cert = opts.cert
     
    13451346        if os.access(cert, os.R_OK):
    13461347            fid = fedid(file=cert)
    1347             if opts.use_fedid == True:
    1348                 user = fid
    13491348        else:
    13501349            sys.exit("Cannot read certificate (%s)" % cert)
    13511350
    1352         if opts.file:
    1353             exp_desc = ""
    1354             try:
    1355                 f = open(opts.file, 'r')
    1356                 for line in f:
    1357                     exp_desc += line
    1358                 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 
    13671351        out_certfile = opts.out_certfile
    13681352
    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 = { }
    13781354
    13791355        if opts.exp_name:
     
    14121388            print "status: %s" % st
    14131389
     1390
     1391class 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
    14141489class split(fedd_rpc):
    14151490    def __init__(self):
     
    17491824
    17501825cmds = {\
     1826        'new': new(),\
    17511827        'create': create(),\
    17521828        'split': split(),\
Note: See TracChangeset for help on using the changeset viewer.