Changeset 617592b for fedd/federation/emulab_access.py
- Timestamp:
- Feb 20, 2010 5:27:56 PM (14 years ago)
- Branches:
- axis_example, compt_changes, info-ops, master, version-3.01, version-3.02
- Children:
- 6af3226
- Parents:
- 0f06528
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/emulab_access.py
r0f06528 r617592b 917 917 918 918 rv = None 919 print info 919 920 for i in info: 920 if i.get('portal', "") == key: 921 if key == i.get('portal', "") or \ 922 key in [e.get('element', "") \ 923 for e in i.get('member', [])]: 921 924 rv = i.copy() 922 925 break 926 923 927 else: 924 928 return rv … … 1049 1053 1050 1054 1051 def generate_ns2(self, topo, expfn, softdir, master): 1052 def dragon_commands(e): 1053 s = "" 1054 if isinstance(e, topdl.Computer): 1055 for i in e.interface: 1056 vlan = i.get_attribute('dragon_vlan') 1057 if vlan: 1058 type = i.get_attribute('dragon_type') 1059 ip = i.get_attribute('ip4_address') 1060 if type == 'link': 1061 s = ("tb-allow-external $%s dragonportal " + \ 1062 "ip %s vlan %s\n") % \ 1063 (topdl.to_tcl_name(e.name[0]), ip, vlan) 1064 elif type == 'lan': 1065 s = ("tb-allow-external $%s dragonportal " + \ 1066 "ip %s vlan %s usurp %s\n") % \ 1067 (topdl.to_tcl_name(e.name[0]), ip, vlan, 1068 i.substrate[0]) 1069 else: 1070 raise service_error(service_error_internal, 1071 "Unknown DRAGON type %s" % type) 1072 return s 1073 1074 def not_dragon(e): 1075 return all([not i.get_attribute('dragon_vlan') \ 1076 for i in e.interface]) 1055 def generate_ns2(self, topo, expfn, softdir, master, connInfo): 1056 class dragon_commands: 1057 """ 1058 Functor to spit out approrpiate dragon commands for nodes listed in 1059 the connectivity description. The constructor makes a dict mapping 1060 dragon nodes to their parameters and the __call__ checks each 1061 element in turn for membership. 1062 """ 1063 def __init__(self, map): 1064 self.node_info = map 1065 1066 def __call__(self, e): 1067 s = "" 1068 if isinstance(e, topdl.Computer): 1069 if self.node_info.has_key(e.name[0]): 1070 i = self.node_info[e.name[0]] 1071 for ifname, vlan, type in i: 1072 print "Checking %s" % e.name[0] 1073 for i in e.interface: 1074 print "interface s %s %s" % (i.name, ifname) 1075 if i.name == ifname: 1076 addr = i.get_attribute('ip4_address') 1077 subs = i.substrate[0] 1078 break 1079 else: 1080 raise service_error(service_error.internal, 1081 "No interface %s on element %s" % \ 1082 (ifname, e.name[0])) 1083 if type =='link': 1084 s = ("tb-allow-external $%s dragonportal " + \ 1085 "ip %s vlan %s\n") % \ 1086 (e.name[0], addr, vlan) 1087 elif type =='lan': 1088 s = ("tb-allow-external $%s dragonportal " + \ 1089 "ip %s vlan %s usurp %s\n") % \ 1090 (e.name[0], addr, vlan, subs) 1091 else: 1092 raise service_error(service_error_internal, 1093 "Unknown DRAGON type %s" % type) 1094 return s 1095 1096 class not_dragon: 1097 def __init__(self, map): 1098 self.nodes = set(map.keys()) 1099 1100 def __call__(self, e): 1101 return e.name[0] not in self.nodes 1077 1102 1078 1103 t = topo.clone() 1104 1105 dragon_map = { } 1106 for i in [ i for i in connInfo if i['type'] == 'transit']: 1107 for a in i.get('fedAttr', []): 1108 if a['attribute'] == 'vlan_id': 1109 vlan = a['value'] 1110 break 1111 else: 1112 raise service_error(service_error.internal, 1113 "No vlan tag") 1114 members = i.get('member', []) 1115 if len(members) > 1: type = 'lan' 1116 else: type = 'link' 1117 1118 try: 1119 for m in members: 1120 if dragon_map.has_key(m['element']): 1121 dragon_map[m['element']].append(( m['interface'], 1122 vlan, type)) 1123 else: 1124 dragon_map[m['element']] = [( m['interface'], 1125 vlan, type),] 1126 except KeyError: 1127 raise service_error(service_error.req, 1128 "Missing connectivity info") 1079 1129 1080 1130 # The startcmds for master and slave testbeds … … 1109 1159 e.set_attribute('startup', node_cmd) 1110 1160 1161 dinf = [i[0] for i in dragon_map.get(e.name[0], []) ] 1111 1162 # Remove portal interfaces that do not connect to DRAGON 1112 1163 e.interface = [i for i in e.interface \ 1113 if not i.get_attribute('portal') or \ 1114 i.get_attribute('dragon_vlan')] 1164 if not i.get_attribute('portal') or i.name in dinf ] 1115 1165 1116 1166 t.substrates = [ s.clone() for s in t.substrates ] … … 1125 1175 1126 1176 if self.attrs.has_key('dragon'): 1127 add_filter = not_dragon 1128 filters.append(dragon_commands )1177 add_filter = not_dragon(dragon_map) 1178 filters.append(dragon_commands(dragon_map)) 1129 1179 else: 1130 1180 add_filter = None … … 1312 1362 services) 1313 1363 self.generate_ns2(topo, expfile, 1314 "/proj/%s/software/%s/" % (proj, ename), master )1364 "/proj/%s/software/%s/" % (proj, ename), master, connInfo) 1315 1365 1316 1366 starter = self.start_segment(keyfile=self.ssh_privkey_file,
Note: See TracChangeset
for help on using the changeset viewer.