Changeset eeb0088 for fedd/federation
- Timestamp:
- Feb 13, 2010 9:56:23 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- dac2316
- Parents:
- e02cd14
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/emulab_access.py
re02cd14 reeb0088 2 2 3 3 import os,sys 4 import stat # for chmod constants 4 5 import re 5 6 import string … … 7 8 import pickle 8 9 import logging 10 import subprocess 9 11 10 12 from threading import * … … 67 69 self.eventserver = config.get("access", "eventserver") 68 70 self.certdir = config.get("access","certdir") 71 self.userconfdir = config.get("access","userconfdir") 72 self.userconfcmd = config.get("access","userconfcmd") 69 73 self.ssh_privkey_file = config.get("access","ssh_privkey_file") 70 74 self.ssh_pubkey_file = config.get("access","ssh_pubkey_file") … … 101 105 self.state_lock = Lock() 102 106 # XXX: Configurable 103 self.exports = set(('SMB', 'seer', 'tmcd' ))107 self.exports = set(('SMB', 'seer', 'tmcd', 'userconfig')) 104 108 self.imports = set(('SMB', 'seer', 'tmcd')) 105 109 … … 321 325 for o in self.allocation[k].get('owners', []): 322 326 self.auth.set_attribute(o, fedid(hexstr=k)) 327 if self.allocation[k].has_key('userconfig'): 328 sfid = hexstr=self.allocation[k]['userconfig'] 329 fid = fedid(hexstr=sfid) 330 self.auth.set_attribute(fid, sfid) 323 331 324 332 … … 488 496 owners 489 497 498 def get_handler(self, path, fid): 499 self.log.info("Get handler %s %s" % (path, fid)) 500 if self.auth.check_attribute(fid, path) and self.userconfdir: 501 return ("%s/%s" % (self.userconfdir, path), "application/binary") 502 else: 503 return (None, None) 504 505 def export_userconf(self, project): 506 dev_null = None 507 confid, confcert = generate_fedid("test", dir=self.userconfdir, 508 log=self.log) 509 conffilename = "%s/%s" % (self.userconfdir, str(confid)) 510 cf = None 511 try: 512 cf = open(conffilename, "w") 513 os.chmod(conffilename, stat.S_IRUSR | stat.S_IWUSR) 514 except IOError, e: 515 raise service_error(service_error.internal, 516 "Cannot create user configuration data") 517 518 try: 519 dev_null = open("/dev/null", "a") 520 except IOError, e: 521 self.log.error("export_userconf: can't open /dev/null: %s" % e) 522 523 cmd = "%s %s" % (self.userconfcmd, project) 524 conf = subprocess.call(cmd.split(" "), 525 stdout=cf, stderr=dev_null, close_fds=True) 526 527 self.auth.set_attribute(confid, str(confid)) 528 529 return confid, confcert 530 531 490 532 def export_services(self, sreq, project, user): 491 533 exp = [ ] 492 # XXX: Filthy shortcut here using http so urlparse will give the right 534 state = { } 535 # XXX: Filthy shortcut here using http: so urlparse will give the right 493 536 # answers. 494 537 for s in sreq: … … 510 553 elif sname == 'tmcd': 511 554 outs['server'] = "http://boss:7777" 555 elif sname == 'userconfig': 556 if self.userconfdir and self.userconfcmd: 557 cid, cert = self.export_userconf(project) 558 outs['server'] = "%s/%s" %(self.testbed, str(cid)) 559 outs['fedAttr'] = [ 560 { 'attribute': 'cert', 'value': cert }, 561 ] 562 state['userconfig'] = unicode(cid) 512 563 exp.append(outs) 513 return exp564 return (exp, state) 514 565 515 566 def build_response(self, alloc_id, ap, services): … … 708 759 709 760 self.allocation[aid]['owners'] = owners 761 services, svc_state = self.export_services(req.get('service',[]), 762 pname, uname) 763 # Store services state in global state 764 for k, v in svc_state.items(): 765 self.allocation[aid][k] = v 710 766 self.write_state() 711 767 self.state_lock.release() … … 719 775 raise service_error(service_error.internal, 720 776 "Can't open %s/%s : %s" % (self.certdir, aid, e)) 721 services = self.export_services(req.get('service',[]), pname, uname)722 777 resp = self.build_response({ 'fedid': allocID } , ap, services) 723 778 return resp
Note: See TracChangeset
for help on using the changeset viewer.