- Timestamp:
- May 28, 2010 10:11:49 AM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 3551ae1
- Parents:
- a20a20f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/access.py
ra20a20f r623a2c9 68 68 self.state_lock = Lock() 69 69 self.state = { } 70 # subclasses fill with what and how they export. 71 self.exports = { } 70 72 # XXX: Configurable 71 self.exports = set(('SMB', 'seer', 'tmcd', 'userconfig',72 'project_export', 'local_seer_control', 'seer_master',73 'hide_hosts'))74 73 self.imports = set(('SMB', 'seer', 'userconfig', 'seer_master', 75 74 'hide_hosts')) … … 361 360 362 361 def export_SMB(self, id, state, project, user, attrs): 363 return { 364 'id': id, 365 'name': 'SMB', 366 'visibility': 'export', 367 'server': 'http://fs:139', 368 'fedAttr': [ 369 { 'attribute': 'SMBSHARE', 'value': 'USERS' }, 370 { 'attribute': 'SMBUSER', 'value': user }, 371 { 'attribute': 'SMBPROJ', 'value': project }, 372 ] 373 } 362 if project and user: 363 return [{ 364 'id': id, 365 'name': 'SMB', 366 'visibility': 'export', 367 'server': 'http://fs:139', 368 'fedAttr': [ 369 { 'attribute': 'SMBSHARE', 'value': 'USERS' }, 370 { 'attribute': 'SMBUSER', 'value': user }, 371 { 'attribute': 'SMBPROJ', 'value': project }, 372 ] 373 }] 374 else: 375 self.log.warn("Cannot export SMB w/o user and project") 376 return [ ] 374 377 375 378 def export_seer(self, id, state, project, user, attrs): 376 return {379 return [{ 377 380 'id': id, 378 381 'name': 'seer', 379 382 'visibility': 'export', 380 383 'server': 'http://control:16606', 381 } 384 }] 382 385 383 386 def export_local_seer(self, id, state, project, user, attrs): 384 return {387 return [{ 385 388 'id': id, 386 389 'name': 'local_seer_control', 387 390 'visibility': 'export', 388 391 'server': 'http://control:16606', 389 } 392 }] 390 393 391 394 def export_seer_master(self, id, state, project, user, attrs): 392 return {395 return [{ 393 396 'id': id, 394 397 'name': 'seer_master', 395 398 'visibility': 'export', 396 399 'server': 'http://seer-master:17707', 397 } 400 }] 398 401 399 402 def export_tmcd(self, id, state, project, user, attrs): 400 return {403 return [{ 401 404 'id': id, 402 405 'name': 'seer', 403 406 'visibility': 'export', 404 407 'server': 'http://boss:7777', 405 } 408 }] 406 409 407 410 def export_userconfig(self, id, state, project, user, attrs): … … 410 413 cid, cert = self.export_userconf(project) 411 414 state['userconfig'] = unicode(cid) 412 return {415 return [{ 413 416 'id': id, 414 417 'name': 'userconfig', … … 418 421 { 'attribute': 'cert', 'value': cert }, 419 422 ] 420 } 423 }] 421 424 else: 422 return None425 return [ ] 423 426 424 427 def export_hide_hosts(self, id, state, project, user, attrs): 425 return {428 return [{ 426 429 'id': id, 427 430 'name': 'hide_hosts', … … 429 432 'fedAttr': [ x for x in attrs \ 430 433 if x.get('attribute', "") == 'hosts'], 431 } 432 433 def export_services(self, sreq, project, user): 434 }] 435 436 def export_project_export(self, id, state, project, user, attrs): 437 rv = [ ] 438 rv.extend(self.export_SMB(id, state, project, user, attrs)) 439 rv.extend(self.export_userconfig(id, state, project, user, attrs)) 440 return rv 441 442 def export_services(self, sreq, project=None, user=None): 434 443 exp = [ ] 435 444 state = { } 436 # XXX: Filthy shortcut here using http: so urlparse will give the right437 # answers.438 445 for s in sreq: 439 446 sname = s.get('name', '') … … 443 450 if sname in self.exports: 444 451 id = s.get('id', 'no_id') 445 if sname == 'SMB': 446 exp.append(self.export_SMB(id, state, project, user, 452 exp.extend(self.exports[sname](id, state, project, user, 447 453 sattrs)) 448 elif sname == 'seer': 449 exp.append(self.export_seer(id, state, project, user, 450 sattrs)) 451 elif sname == 'tmcd': 452 exp.append(self.export_tmcd(id, state, project, user, 453 sattrs)) 454 elif sname == 'userconfig': 455 exp.append(self.export_userconfig(id, state, 456 project, user, sattrs)) 457 elif sname == 'project_export': 458 exp.append(self.export_SMB(id, state, project, user, 459 sattrs)) 460 #exp.append(self.export_seer(id, state, project, user, 461 #sattrs)) 462 exp.append(self.export_userconfig(id, state, 463 project, user, sattrs)) 464 elif sname == 'local_seer_control': 465 exp.append(self.export_local_seer(id, state, project, 466 user, sattrs)) 467 elif sname == 'seer_master': 468 exp.append(self.export_seer_master(id, state, project, 469 user, sattrs)) 470 elif sname == 'hide_hosts': 471 exp.append(self.export_hide_hosts(id, state, project, 472 user, sattrs)) 454 473 455 return (exp, state) 474 456 … … 497 479 'value': self.dragon_endpoint}) 498 480 if self.deter_internal: 499 print 'adding internal'500 481 msg['fedAttr'].append({'attribute': 'deter_internal', 501 482 'value': self.deter_internal}) 502 else: print "internal: %s" % self.deter_internal503 483 #XXX: ?? 504 484 if self.dragon_vlans: … … 689 669 raise service_error(service_error.internal, 690 670 "Cannot write client.conf: %s" %s) 671 672 def configure_userconf(self, services, tmpdir): 673 """ 674 If the userconf service was imported, collect the configuration data. 675 """ 676 for s in services: 677 s_name = s.get('name', '') 678 s_vis = s.get('visibility','') 679 if s_name == 'userconfig' and s_vis == 'import': 680 # Collect ther server and certificate info. 681 u = s.get('server', None) 682 for a in s.get('fedAttr', []): 683 if a.get('attribute',"") == 'cert': 684 cert = a.get('value', None) 685 break 686 else: 687 cert = None 688 689 if cert: 690 # Make a temporary certificate file for get_url. The 691 # finally clause removes it whether something goes 692 # wrong (including an exception from get_url) or not. 693 try: 694 tfos, tn = tempfile.mkstemp(suffix=".pem") 695 tf = os.fdopen(tfos, 'w') 696 print >>tf, cert 697 tf.close() 698 self.log.debug("Getting userconf info: %s" % u) 699 get_url(u, tn, tmpdir, "userconf") 700 self.log.debug("Got userconf info: %s" % u) 701 except EnvironmentError, e: 702 raise service_error(service.error.internal, 703 "Cannot create temp file for " + 704 "userconfig certificates: %s" % e) 705 except: 706 t, v, st = sys.exc_info() 707 raise service_error(service_error.internal, 708 "Error retrieving %s: %s" % (u, v)) 709 finally: 710 if tn: os.remove(tn) 711 else: 712 raise service_error(service_error.req, 713 "No certificate for retreiving userconfig") 714 break 691 715 692 716 def import_store_info(self, cf, connInfo): … … 737 761 raise service_error(service_error.internal, 738 762 'Bad Services missing info for import %s' % c) 763 764 def remove_dirs(self, dir): 765 """ 766 Remove the directory tree and all files rooted at dir. Log any errors, 767 but continue. 768 """ 769 self.log.debug("[removedirs]: removing %s" % dir) 770 try: 771 for path, dirs, files in os.walk(dir, topdown=False): 772 for f in files: 773 os.remove(os.path.join(path, f)) 774 for d in dirs: 775 os.rmdir(os.path.join(path, d)) 776 os.rmdir(dir) 777 except EnvironmentError, e: 778 self.log.error("Error deleting directory tree in %s" % e);
Note: See TracChangeset
for help on using the changeset viewer.