- Timestamp:
- Dec 8, 2009 6:11:35 PM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 23356cb
- Parents:
- 3bddd24
- Location:
- fedd
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/fedd_client.py
r3bddd24 r99eb8cf 90 90 type="string", help="Suggested experiment name") 91 91 92 class fedd_create_opts(fedd_client_opts): 93 def __init__(self, access_keys, add_key_callback=None, 94 add_cert_callback=None): 92 class fedd_create_opts(fedd_new_opts): 93 def __init__(self): 95 94 fedd_client_opts.__init__(self) 96 self.add_option("--experiment_cert", dest="out_certfile",97 type="string", help="output certificate file")98 self.add_option("--experiment_name", dest="exp_name",99 type="string", help="Suggested experiment name")100 self.add_option("--useFedid", action="store_true",101 dest="use_fedid", default=False,102 help="Use a fedid derived from my certificate as user identity")103 95 self.add_option("--file", dest="file", 104 96 help="experiment description file") … … 106 98 type="string", 107 99 help="Project to export from master") 108 if add_key_callback:109 self.add_option("--ssh_key", action="callback",110 type="string", callback=add_key_callback,111 callback_args=(access_keys,),112 help="ssh key for access (can be supplied more than once")113 if add_cert_callback:114 self.add_option("--x509Key", action="callback",115 type="string", callback=add_cert_callback,116 callback_args=(access_keys,),117 help="X509 certificate for access " + \118 "(can be supplied more than once")119 100 self.add_option("--master", dest="master", 120 101 help="Master testbed in the federation") 121 self.add_option("--username", action="store", dest="user",122 type="string", help="Use this username instead of the uid")123 102 124 103 class fedd_split_opts(fedd_create_opts): 125 def __init__(self, access_keys, add_key_callback=None, 126 add_cert_callback=None): 127 fedd_create_opts.__init__(self, access_keys, add_key_callback, 128 add_cert_callback) 104 def __init__(self ): 105 fedd_create_opts.__init__(self) 129 106 self.add_option('--fedkit', action='store_true', dest='fedkit', 130 107 default=False, … … 136 113 137 114 class fedd_access_opts(fedd_create_opts): 138 def __init__(self, access_keys, node_descs, add_key_callback=None, 139 add_cert_callback=None, add_node_callback=None): 140 fedd_create_opts.__init__(self, access_keys, add_key_callback, 141 add_cert_callback) 142 self.add_option("--anonymous", action="store_true", 143 dest="anonymous", default=False, 144 help="Do not include a user in the request") 115 def __init__(self): 116 fedd_create_opts.__init__(self) 145 117 self.add_option("--label", action="store", dest="label", 146 118 type="string", help="Label for output") … … 219 191 220 192 class fedd_ns_image_opts(fedd_split_opts): 221 def __init__(self, access_keys, add_key_callback=None, 222 add_cert_callback=None): 223 fedd_split_opts.__init__(self, access_keys, add_key_callback, 224 add_cert_callback) 193 def __init__(self): 194 fedd_split_opts.__init__(self) 225 195 self.add_option("--output", dest="outfile", type="string", 226 196 help="output image file") … … 298 268 299 269 300 def add_ssh_key(self, option, opt_str, value, parser, access_keys):301 try:302 access_keys.append(access_method(file=value,303 type=access_method.type_ssh))304 except IOError, (errno, strerror):305 raise OptionValueError("Cannot generate sshPubkey from %s: "\306 "%s (%d)" % (value,strerror,errno))307 308 def add_x509_cert(self, option, opt_str, value, parser, access_keys):309 try:310 access_keys.append(access_method(file=value,311 type=access_method.type_x509))312 except IOError, (errno, strerror):313 raise OptionValueError("Cannot read x509 cert from %s: %s (%d)" %314 (value,strerror,errno))315 270 def add_node_desc(self, option, opt_str, value, parser, node_descs): 316 271 def none_if_zero(x): … … 325 280 raise OptionValueError("Bad node description: %s" % value) 326 281 327 def get_user_info(self , access_keys=None):282 def get_user_info(self): 328 283 pw = pwd.getpwuid(os.getuid()); 329 284 try_cert=None … … 335 290 if not os.access(try_cert, os.R_OK): 336 291 try_cert = None 337 if access_keys is not None and len(access_keys) == 0:338 for k in ["%s/.ssh/id_rsa.pub", "%s/.ssh/id_dsa.pub",339 "%s/.ssh/identity.pub"]:340 try_key = k % pw[5];341 if os.access(try_key, os.R_OK):342 access_keys.append(access_method(file=try_key,343 type=access_method.type_ssh))344 break345 292 return (user, try_cert) 346 293 … … 474 421 if opts.debug > 0: opts.tracefile=sys.stderr 475 422 476 (user, cert) = self.get_user_info( [])423 (user, cert) = self.get_user_info() 477 424 478 425 if opts.cert != None: cert = opts.cert … … 577 524 if opts.debug > 0: opts.tracefile=sys.stderr 578 525 579 (user, cert) = self.get_user_info( [])526 (user, cert) = self.get_user_info() 580 527 581 528 if opts.cert != None: cert = opts.cert … … 637 584 if opts.debug > 0: opts.tracefile=sys.stderr 638 585 639 (user, cert) = self.get_user_info( [])586 (user, cert) = self.get_user_info() 640 587 641 588 if opts.cert != None: cert = opts.cert … … 844 791 if opts.debug > 0: opts.tracefile=sys.stderr 845 792 846 (user, cert) = self.get_user_info( [])793 (user, cert) = self.get_user_info() 847 794 848 795 if opts.cert != None: cert = opts.cert … … 976 923 The control flow. Compose the request and print the response. 977 924 """ 978 access_keys = []979 925 # Process the options using the customized option parser defined above 980 parser = fedd_ns_image_opts(access_keys, self.add_ssh_key, 981 self.add_x509_cert) 926 parser = fedd_ns_image_opts() 982 927 983 928 (opts, args) = parser.parse_args() … … 989 934 if opts.debug > 0: opts.tracefile=sys.stderr 990 935 991 (user, cert) = self.get_user_info( [])936 (user, cert) = self.get_user_info() 992 937 993 938 if opts.cert != None: cert = opts.cert … … 1115 1060 The control flow. Compose the request and print the response. 1116 1061 """ 1117 access_keys = []1118 1062 # Process the options using the customized option parser defined above 1119 parser = fedd_ns_image_opts(access_keys, self.add_ssh_key, 1120 self.add_x509_cert) 1063 parser = fedd_ns_image_opts() 1121 1064 1122 1065 (opts, args) = parser.parse_args() … … 1128 1071 if opts.debug > 0: opts.tracefile=sys.stderr 1129 1072 1130 (user, cert) = self.get_user_info( [])1073 (user, cert) = self.get_user_info() 1131 1074 1132 1075 if opts.cert != None: cert = opts.cert … … 1189 1132 (opts, args) = parser.parse_args() 1190 1133 1191 (user, cert) = self.get_user_info( [])1134 (user, cert) = self.get_user_info() 1192 1135 if opts.trusted: 1193 1136 if ( not os.access(opts.trusted, os.R_OK) ) : … … 1275 1218 (opts, args) = parser.parse_args() 1276 1219 1277 (user, cert) = self.get_user_info( [])1220 (user, cert) = self.get_user_info() 1278 1221 if opts.trusted: 1279 1222 if ( not os.access(opts.trusted, os.R_OK) ) : … … 1348 1291 fedd_rpc.__init__(self) 1349 1292 def __call__(self): 1350 access_keys = []1351 1293 # Process the options using the customized option parser defined above 1352 1294 parser = fedd_new_opts() … … 1360 1302 if opts.debug > 0: opts.tracefile=sys.stderr 1361 1303 1362 (user, cert) = self.get_user_info( access_keys)1304 (user, cert) = self.get_user_info() 1363 1305 1364 1306 if opts.cert != None: cert = opts.cert … … 1417 1359 fedd_rpc.__init__(self) 1418 1360 def __call__(self): 1419 access_keys = [] 1420 parser = fedd_create_opts(access_keys, self.add_ssh_key, 1421 self.add_x509_cert) 1361 parser = fedd_create_opts() 1422 1362 1423 1363 (opts, args) = parser.parse_args() … … 1432 1372 if opts.debug > 0: opts.tracefile=sys.stderr 1433 1373 1434 (user, cert) = self.get_user_info(access_keys) 1435 1436 if opts.user: user = opts.user 1374 (user, cert) = self.get_user_info() 1437 1375 1438 1376 if opts.cert != None: cert = opts.cert … … 1509 1447 'master': opts.master, 1510 1448 'exportProject': { 'localname': opts.project }, 1511 'user' : [ {\ 1512 'userID': pack_id(user), \ 1513 'access': [ { a.type: a.buf } for a in access_keys]\ 1514 } ] 1515 } 1449 } 1516 1450 1517 1451 if e_fedid: … … 1559 1493 fedd_rpc.__init__(self) 1560 1494 def __call__(self): 1561 access_keys = []1562 1495 # Process the options using the customized option parser defined above 1563 parser = fedd_split_opts(access_keys, self.add_ssh_key, 1564 self.add_x509_cert) 1496 parser = fedd_split_opts() 1565 1497 1566 1498 (opts, args) = parser.parse_args() … … 1572 1504 if opts.debug > 0: opts.tracefile=sys.stderr 1573 1505 1574 (user, cert) = self.get_user_info( access_keys)1506 (user, cert) = self.get_user_info() 1575 1507 1576 1508 if opts.cert != None: cert = opts.cert … … 1661 1593 1662 1594 def __call__(self): 1663 access_keys = []1664 1595 node_descs = [] 1665 1596 proj = None 1666 1597 1667 1598 # Process the options using the customized option parser defined above 1668 parser = fedd_access_opts(access_keys, node_descs, self.add_ssh_key, 1669 self.add_x509_cert, self.add_node_desc) 1599 parser = fedd_access_opts() 1670 1600 1671 1601 (opts, args) = parser.parse_args() … … 1680 1610 if opts.debug > 0: opts.tracefile=sys.stderr 1681 1611 1682 (user, cert) = self.get_user_info(access_keys) 1683 1684 if opts.user: user = opts.user 1612 (user, cert) = self.get_user_info() 1685 1613 1686 1614 if opts.cert != None: cert = opts.cert … … 1699 1627 'allocID': pack_id('test alloc'), 1700 1628 'destinationTestbed': pack_id(opts.testbed), 1701 'serviceAccess' : [ { a.type: a.buf } for a in access_keys ],1702 'createAccess' : [ { a.type: a.buf } for a in access_keys ],1703 1629 } 1704 1630 … … 1712 1638 } for n in node_descs], 1713 1639 } 1714 1715 if opts.project != None:1716 if not opts.anonymous and user != None:1717 msg['project'] = {1718 'name': pack_id(opts.project),1719 'user': [ { 'userID': pack_id(user) } ],1720 }1721 else:1722 msg['project'] = { 'name': pack_id(opts.project) }1723 else:1724 if not opts.anonymous and user != None:1725 msg['user'] = [ { 'userID': pack_id(user) } ]1726 else:1727 msg['user'] = [];1728 1640 1729 1641 if opts.debug > 1: print >>sys.stderr, msg … … 1769 1681 if opts.debug > 0: opts.tracefile=sys.stderr 1770 1682 1771 (user, cert) = self.get_user_info( [])1683 (user, cert) = self.get_user_info() 1772 1684 1773 1685 if opts.cert != None: cert = opts.cert -
fedd/federation/experiment_control.py
r3bddd24 r99eb8cf 725 725 else: return None 726 726 727 def get_access(self, tb, nodes, user,tbparam, master, export_project,727 def get_access(self, tb, nodes, tbparam, master, export_project, 728 728 access_user): 729 729 """ … … 734 734 raise service_error(serice_error.server_config, 735 735 "Unknown testbed: %s" % tb) 736 737 # currently this lumps all users into one service access group738 service_keys = [ a for u in user \739 for a in u.get('access', []) \740 if a.has_key('sshPubkey')]741 742 if len(service_keys) == 0:743 raise service_error(service_error.req,744 "Must have at least one SSH pubkey for services")745 736 746 737 # Tweak search order so that if there are entries in access_user that … … 1327 1318 return hosts, ips 1328 1319 1329 def get_access_to_testbeds(self, testbeds, user,access_user,1320 def get_access_to_testbeds(self, testbeds, access_user, 1330 1321 export_project, master, allocated, tbparams): 1331 1322 """ … … 1336 1327 """ 1337 1328 for tb in testbeds: 1338 self.get_access(tb, None, user,tbparams, master,1329 self.get_access(tb, None, tbparams, master, 1339 1330 export_project, access_user) 1340 1331 allocated[tb] = 1 … … 2017 2008 "Bad key type (%s)" % self.ssh_type) 2018 2009 2019 user = req.get('user', None)2020 if user == None:2021 raise service_error(service_error.req, "No user")2022 2023 2010 master = req.get('master', None) 2024 2011 if not master: … … 2067 2054 allocated = { } # Testbeds we can access 2068 2055 topo ={ } # Sub topologies 2069 self.get_access_to_testbeds(testbeds, user,access_user,2056 self.get_access_to_testbeds(testbeds, access_user, 2070 2057 export_project, master, allocated, tbparams) 2071 2058 self.split_topology(top, topo, testbeds, eid, master, tbparams)
Note: See TracChangeset
for help on using the changeset viewer.