Changeset 49051fb for fedd/federation
- Timestamp:
- May 24, 2010 7:12:13 AM (15 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 8fc0606
- Parents:
- 8dbbdc5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/emulab_access.py
r8dbbdc5 r49051fb 90 90 self.local_seer_image = config.get("access", "local_seer_image") 91 91 self.local_seer_start = config.get("access", "local_seer_start") 92 self.seer_master_start = config.get("access", "seer_master_start") 92 93 self.ssh_privkey_file = config.get("access","ssh_privkey_file") 93 94 self.ssh_pubkey_file = config.get("access","ssh_pubkey_file") … … 130 131 # XXX: Configurable 131 132 self.exports = set(('SMB', 'seer', 'tmcd', 'userconfig', 132 'project_export', 'local_seer_control')) 133 self.imports = set(('SMB', 'seer', 'userconfig')) 134 135 if not self.local_seer_image or not self.local_seer_software or \ 136 not self.local_seer_start: 133 'project_export', 'local_seer_control', 'seer_master')) 134 self.imports = set(('SMB', 'seer', 'userconfig', 'seer_master')) 135 136 if not self.local_seer_image or not self.local_seer_software: 137 137 self.exports.discard('local_seer_control') 138 self.exports.discard('seer_master') 139 140 if not self.local_seer_start: 141 self.exports.discard('local_seer_control') 142 143 if not self.seer_master_start: 144 self.exports.discard('seer_master') 138 145 139 146 if auth: self.auth = auth … … 605 612 } 606 613 614 def export_seer_master(self, id, state, project, user): 615 return { 616 'id': id, 617 'name': 'seer_master', 618 'visibility': 'export', 619 'server': 'http://seer_master:16606', 620 } 621 607 622 def export_tmcd(self, id, state, project, user): 608 623 return { … … 657 672 elif sname == 'local_seer_control': 658 673 exp.append(self.export_local_seer(id, state, project, 674 user)) 675 elif sname == 'seer_master': 676 exp.append(self.export_seer_master(id, state, project, 659 677 user)) 660 678 return (exp, state) … … 1055 1073 print >>f, "Service: %s" % s['name'] 1056 1074 1075 def client_seer_master(f, s): 1076 print >>f, 'PortalAlias: seer_master'; 1077 1057 1078 def client_smb(f, s): 1058 1079 print >>f, "Service: %s" % s['name'] … … 1079 1100 'userconfig': client_null, 1080 1101 'project_export': client_null, 1102 'seer_master': client_seer_master, 1103 } 1104 1105 def client_seer_master_export(f, s): 1106 print >>f, "AddedNode: seer_master" 1107 1108 def client_seer_local_export(f, s): 1109 print >>f, "AddedNode: control" 1110 1111 client_export_service_out = { 1112 'seer_master': client_seer_master_export, 1113 'seer_local': client_seer_local_export, 1081 1114 } 1082 1115 … … 1096 1129 'project_export': server_null, 1097 1130 'seer': server_seer, 1131 'seer_master': server_port, 1098 1132 } 1099 1133 # XXX: end un hardcode this … … 1109 1143 for e in [ e for e in topo.elements \ 1110 1144 if isinstance(e, topdl.Computer) and e.get_attribute('portal')]: 1111 myname = e.name [0]1145 myname = e.name 1112 1146 type = e.get_attribute('portal_type') 1113 1147 … … 1167 1201 s.get('visibility','') == 'import': 1168 1202 client_service_out[s['name']](f, s) 1203 if s.get('name', '') in self.exports and \ 1204 s.get('visibility', '') == 'export' and \ 1205 s['name'] in client_export_service_out: 1206 client_export_service_out[s['name']](f, s) 1169 1207 # Seer uses this. 1170 1208 if mproj and meid: … … 1192 1230 s = "" 1193 1231 if isinstance(e, topdl.Computer): 1194 if self.node_info.has_key(e.name [0]):1195 i = self.node_info[e.name [0]]1232 if self.node_info.has_key(e.name): 1233 i = self.node_info[e.name] 1196 1234 for ifname, vlan, type in i: 1197 1235 for i in e.interface: … … 1203 1241 raise service_error(service_error.internal, 1204 1242 "No interface %s on element %s" % \ 1205 (ifname, e.name [0]))1243 (ifname, e.name)) 1206 1244 # XXX: do netmask right 1207 1245 if type =='link': 1208 1246 s = ("tb-allow-external $%s dragonportal " + \ 1209 1247 "ip %s vlan %s netmask 255.255.255.0\n") % \ 1210 (e.name [0], addr, vlan)1248 (e.name, addr, vlan) 1211 1249 elif type =='lan': 1212 1250 s = ("tb-allow-external $%s dragonportal " + \ 1213 1251 "ip %s vlan %s usurp %s\n") % \ 1214 (e.name [0], addr, vlan, subs)1252 (e.name, addr, vlan, subs) 1215 1253 else: 1216 1254 raise service_error(service_error_internal, … … 1223 1261 1224 1262 def __call__(self, e): 1225 return e.name [0]not in self.nodes1263 return e.name not in self.nodes 1226 1264 1227 1265 … … 1284 1322 e.set_attribute('startup', node_cmd) 1285 1323 1286 dinf = [i[0] for i in dragon_map.get(e.name [0], []) ]1324 dinf = [i[0] for i in dragon_map.get(e.name, []) ] 1287 1325 # Remove portal interfaces that do not connect to DRAGON 1288 1326 e.interface = [i for i in e.interface \ … … 1415 1453 'Bad Services missing info for import %s' % c) 1416 1454 1455 def configure_userconf(self, services): 1456 """ 1457 If the userconf service was imported, collect the configuration data. 1458 """ 1459 for s in services: 1460 s_name = s.get('name', '') 1461 s_vis = s.get('visibility','') 1462 if s_name == 'userconfig' and s_vis == 'import': 1463 # Collect ther server and certificate info. 1464 u = s.get('server', None) 1465 for a in s.get('fedAttr', []): 1466 if a.get('attribute',"") == 'cert': 1467 cert = a.get('value', None) 1468 break 1469 else: 1470 cert = None 1471 1472 if cert: 1473 # Make a temporary certificate file for get_url. The 1474 # finally clause removes it whether something goes 1475 # wrong (including an exception from get_url) or not. 1476 try: 1477 tfos, tn = tempfile.mkstemp(suffix=".pem") 1478 tf = os.fdopen(tfos, 'w') 1479 print >>tf, cert 1480 tf.close() 1481 self.log.debug("Getting userconf info: %s" % u) 1482 get_url(u, tn, tmpdir, "userconf") 1483 self.log.debug("Got userconf info: %s" % u) 1484 except IOError, e: 1485 raise service_error(service.error.internal, 1486 "Cannot create temp file for " + 1487 "userconfig certificates: %s e") 1488 except: 1489 t, v, st = sys.exc_info() 1490 raise service_error(service_error.internal, 1491 "Error retrieving %s: %s" % (s, v)) 1492 finally: 1493 if tn: os.remove(tn) 1494 else: 1495 raise service_error(service_error.req, 1496 "No certificate for retreiving userconfig") 1497 break 1498 1499 def add_seer_node(self, topo, name, startup): 1500 """ 1501 Add a seer node to the given topology, with the startup command passed 1502 in. 1503 """ 1504 c_node = topdl.Computer( 1505 name=name, 1506 os= topdl.OperatingSystem( 1507 attribute=[ 1508 { 'attribute': 'osid', 1509 'value': self.local_seer_image }, 1510 ]), 1511 attribute=[ 1512 { 'attribute': 'startup', 'value': startup }, 1513 ] 1514 ) 1515 self.add_kit(c_node, self.local_seer_software) 1516 topo.elements.append(c_node) 1517 1518 def configure_seer_services(self, services, topo, softdir): 1519 local_seer = False 1520 collect_seer = False 1521 seer_master= False 1522 for s in services: 1523 s_name = s.get('name', '') 1524 s_vis = s.get('visibility','') 1525 1526 if s_name == 'local_seer_control' and s_vis == 'export': 1527 local_seer = True 1528 elif s_name == 'seer_master': 1529 if s_vis == 'import': 1530 collect_seer = True 1531 elif s_vis == 'export': 1532 seer_master = True 1533 1534 # We've got the whole picture now, so add nodes if needed and configure 1535 # them to interconnect properly. 1536 if local_seer or seer_master: 1537 # Copy local seer control node software to the tempdir 1538 for l, f in self.local_seer_software: 1539 base = os.path.basename(f) 1540 copy_file(f, "%s/%s" % (softdir, base)) 1541 # If we're collecting seers somewhere the controllers need to talk to 1542 # the master. In testbeds that export the service, that will be a 1543 # local node that we'll add below. Elsewhere it will be the control 1544 # portal that will port forward to the exporting master. 1545 if local_seer: 1546 if collect_seer: 1547 startup = "%s %s" % (self.local_seer_start, "seer_master") 1548 else: 1549 startup = self.local_seer_start 1550 self.add_seer_node(topo, 'control', startup) 1551 # If this is the seer master, add that node, too. 1552 if seer_master: 1553 self.add_seer_node(topo, 'seer_master', self.seer_master_start) 1554 1555 1556 1417 1557 def StartSegment(self, req, fid): 1418 1558 … … 1524 1664 # If the userconf service was imported, collect the configuration 1525 1665 # data. 1526 for s in services: 1527 s_name = s.get('name', '') 1528 s_vis = s.get('visibility','') 1529 if s_name == 'userconfig' and s_vis == 'import': 1530 # Collect ther server and certificate info. 1531 u = s.get('server', None) 1532 for a in s.get('fedAttr', []): 1533 if a.get('attribute',"") == 'cert': 1534 cert = a.get('value', None) 1535 break 1536 else: 1537 cert = None 1538 1539 if cert: 1540 # Make a temporary certificate file for get_url. The 1541 # finally clause removes it whether something goes 1542 # wrong (including an exception from get_url) or not. 1543 try: 1544 tfos, tn = tempfile.mkstemp(suffix=".pem") 1545 tf = os.fdopen(tfos, 'w') 1546 print >>tf, cert 1547 tf.close() 1548 self.log.debug("Getting userconf info: %s" % u) 1549 get_url(u, tn, tmpdir, "userconf") 1550 self.log.debug("Got userconf info: %s" % u) 1551 except IOError, e: 1552 raise service_error(service.error.internal, 1553 "Cannot create temp file for " + 1554 "userconfig certificates: %s e") 1555 except: 1556 t, v, st = sys.exc_info() 1557 raise service_error(service_error.internal, 1558 "Error retrieving %s: %s" % (s, v)) 1559 finally: 1560 if tn: os.remove(tn) 1561 else: 1562 raise service_error(service_error.req, 1563 "No certificate for retreiving userconfig") 1564 break 1565 if s_name == 'local_seer_control' and s_vis == 'export': 1566 # Copy local seer control node software to the tempdir 1567 for l, f in self.local_seer_software: 1568 base = os.path.basename(f) 1569 copy_file(f, "%s/%s" % (softdir, base)) 1570 1571 # Add a control node to the local topology 1572 c_node = topdl.Computer( 1573 name='control', 1574 os= topdl.OperatingSystem( 1575 attribute=[ 1576 { 'attribute': 'osid', 1577 'value': self.local_seer_image }, 1578 ]), 1579 attribute=[ 1580 { 'attribute': 'startup', 1581 'value': self.local_seer_start }, 1582 ] 1583 ) 1584 self.add_kit(c_node, self.local_seer_software) 1585 topo.elements.append(c_node) 1666 self.configure_userconf(services) 1667 self.configure_seer_services(services, topo, softdir) 1586 1668 1587 1669 proj = None
Note: See TracChangeset
for help on using the changeset viewer.