Changeset b709861
- Timestamp:
- Nov 30, 2011 4:45:15 PM (13 years ago)
- Branches:
- compt_changes, info-ops, master
- Children:
- 1ae1aa2
- Parents:
- 22a1a77
- Location:
- fedd/federation
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
fedd/federation/emulab_access.py
r22a1a77 rb709861 102 102 self.stop_segment = proxy_emulab_segment.stop_segment 103 103 self.info_segment = proxy_emulab_segment.info_segment 104 self.operation_segment = proxy_emulab_segment.operation_segment 104 105 elif self.access_type == 'local_emulab': 105 106 self.start_segment = local_emulab_segment.start_segment 106 107 self.stop_segment = local_emulab_segment.stop_segment 107 108 self.info_segment = local_emulab_segment.info_segment 109 self.operation_segment = local_emulab_segment.operation_segment 108 110 else: 109 111 self.start_segment = None 110 112 self.stop_segment = None 111 113 self.info_segment = None 114 self.operation_segment = None 112 115 113 116 self.restricted = [ ] … … 185 188 self.TerminateSegment), 186 189 'InfoSegment': soap_handler("InfoSegment", self.InfoSegment), 190 'OperationSegment': soap_handler("OperationSegment", 191 self.OperationSegment), 187 192 } 188 193 self.xmlrpc_services = {\ … … 195 200 self.TerminateSegment), 196 201 'InfoSegment': xmlrpc_handler("InfoSegment", self.InfoSegment), 202 'OperationSegment': xmlrpc_handler("OperationSegment", 203 self.OperationSegment), 197 204 } 198 205 … … 1060 1067 'allocationLog': logv, 1061 1068 'segmentdescription': { 1062 'topdldescription': t. clone().to_dict()1069 'topdldescription': t.to_dict() 1063 1070 }, 1064 1071 'proof': proof.to_dict(), 1065 1072 } 1066 self.allocation[aid]['topo'] = t opo.clone()1073 self.allocation[aid]['topo'] = t 1067 1074 retval = copy.copy(self.allocation[aid]['started']) 1068 1075 self.write_state() … … 1239 1246 user = self.allocation[aid].get('user', None) 1240 1247 ename = self.allocation[aid].get('experiment', None) 1241 nonce = self.allocation[aid].get('nonce', False)1242 1248 else: 1243 1249 proj = None 1244 1250 user = None 1245 1251 ename = None 1246 nonce = False1252 topo = None 1247 1253 self.state_lock.release() 1248 1254 … … 1270 1276 'proof': proof.to_dict(), 1271 1277 } 1278 1279 def OperationSegment(self, req, fid): 1280 def get_pname(e): 1281 """ 1282 Get the physical name of a node 1283 """ 1284 if e.localname: 1285 return re.sub('\..*','', e.localname[0]) 1286 else: 1287 return None 1288 1289 try: 1290 req = req['OperationSegmentRequestBody'] 1291 except KeyError: 1292 raise service_error(server_error.req, "Badly formed request") 1293 1294 auth_attr = req['allocID']['fedid'] 1295 aid = "%s" % auth_attr 1296 1297 access_ok, proof = self.auth.check_attribute(fid, auth_attr, 1298 with_proof=True) 1299 if not access_ok: 1300 raise service_error(service_error.access, "Access denied") 1301 1302 op = req.get('operation', None) 1303 targets = req.get('target', None) 1304 params = req.get('parameter', None) 1305 1306 if op is None : 1307 raise service_error(service_error.req, "missing operation") 1308 elif targets is None: 1309 raise service_error(service_error.req, "no targets") 1310 1311 if aid in self.allocation: 1312 topo = self.allocation[aid].get('topo', None) 1313 if topo: topo = topo.clone() 1314 else: 1315 topo = None 1316 1317 targets = copy.copy(targets) 1318 ptargets = { } 1319 for e in topo.elements: 1320 if isinstance(e, topdl.Computer): 1321 if e.name in targets: 1322 targets.remove(e.name) 1323 pn = get_pname(e) 1324 if pn: ptargets[e.name] = pn 1325 1326 status = [ operation_status(t, operation_status.no_target) \ 1327 for t in targets] 1328 1329 ops = self.operation_segment(keyfile=self.ssh_privkey_file, 1330 debug=self.create_debug, boss=self.boss, 1331 cert=self.xmlrpc_cert) 1332 ops(self, op, ptargets, params) 1333 1334 status.extend(ops.status) 1335 1336 return { 1337 'allocID': req['allocID'], 1338 'status': [s.to_dict() for s in status], 1339 'proof': proof.to_dict(), 1340 } -
fedd/federation/emulab_segment.py
r22a1a77 rb709861 14 14 from federation.util import fedd_ssl_context 15 15 from federation import service_error 16 from federation.operation_status import operation_status 16 17 17 18 class emulab_segment: … … 32 33 self.debug = getattr(self, 'debug', False) 33 34 self.node = { } 35 self.status = [ ] 34 36 35 37 def emulab_call(self, method, params): … … 103 105 if self.debug: 104 106 if self.log: 105 self.log.debug("[make_null_experiment]: (debug) Creating experiment") 107 self.log.debug("[make_null_experiment]: " + \ 108 "(debug) Creating experiment") 106 109 return True 107 110 else: … … 243 246 "Cannot get node mapping of segment:%s/%s" % (pid, eid)) 244 247 248 def do_operation(self, op, lnode, pnode, params): 249 """ 250 Carry out operation on node in the given experiment. 251 """ 252 def get_param(params, name): 253 if params is None: 254 return None 255 for d in params: 256 if 'attribute' in d and d['attribute'] == name: 257 return d.get('value', None) 258 else: 259 return None 260 261 op = op.lower() 262 263 if op == 'restore': 264 state = get_param(params, 'state') 265 if state is None: 266 self.status.append(operation_status(lnode, 267 operation_status.bad_param, 'No state to restore')) 268 return False 269 elif state == 'initial': 270 self.status.append(operation_status(lnode, 271 operation_status.unsupp, 'Image load unsupported')) 272 return False 273 elif state == 'boot': 274 p = {'nodes': pnode, 'wait': False} 275 code, result = self.emulab_call('node.reboot', p) 276 if code == 0: 277 self.status.append(operation_status(lnode, 278 operation_status.success, 'rebooting')) 279 return True 280 else: 281 self.status.append(operation_status(lnode, 282 operation_status.federant, 'Error code: %d' % code)) 283 return False 284 else: 285 self.status.append(operation_status(lnode, 286 operation_status.bad_param, 287 "Unsupported state %s" % state)) 288 return False 289 else: 290 self.status.append(operation_status(lnode, operation_status.unsupp)) 291 return False 292 -
fedd/federation/experiment_control.py
r22a1a77 rb709861 2391 2391 results.append(operation_status(t, 2392 2392 operation_status.federant, 2393 'Unexpected error ion %s' % tb))2393 'Unexpected error on %s' % tb)) 2394 2394 # Clean up the tmpdir no matter what 2395 2395 finally: … … 2412 2412 else: return { } 2413 2413 2414 def element_name(e): 2415 if isinstance(e, topdl.Computer): return e.name 2416 elif isinstance(e, topdl.Testbed): 2417 if e.localname: return e.localname[0] 2418 else: return None 2419 else: return None 2420 2414 2421 req = req.get('OperationRequestBody', None) 2415 2422 if not req: … … 2418 2425 exp = req.get('experiment', None) 2419 2426 op = req.get('operation', None) 2420 target = set(req.get('target', []))2427 targets = set(req.get('target', [])) 2421 2428 params = req.get('parameter', None) 2422 2429 … … 2433 2440 raise service_error(service_error.req, "No request?") 2434 2441 2435 if op is None or not target 2442 if op is None or not targets: 2436 2443 raise service_error(service_error.req, "No request?") 2437 2444 … … 2440 2447 if key in self.state: 2441 2448 d1, op_params, cert, d2 = \ 2442 self.get_segment_info(self.state[key], need_lock=False) 2449 self.get_segment_info(self.state[key], need_lock=False, 2450 key='tb') 2443 2451 top = self.state[key].top 2444 2452 if top is not None: … … 2453 2461 results = [] 2454 2462 for e in top.elements: 2455 if e.name in targets: 2463 ename = element_name(e) 2464 if ename in targets: 2456 2465 tb = element_to_tb(e) 2466 targets.remove(ename) 2457 2467 if tb is not None: 2458 if tb in testbeds: testbeds[tb].append(e .name)2459 else: testbeds[tb] = [ e .name ]2468 if tb in testbeds: testbeds[tb].append(ename) 2469 else: testbeds[tb] = [ ename ] 2460 2470 else: 2461 2471 results.append(operation_status(e.name, … … 2463 2473 description='Cannot map target to testbed')) 2464 2474 2475 for t in targets: 2476 results.append(operation_status(t, operation_status.no_target)) 2477 2465 2478 self.operate_on_segments(op_params, cert, op, testbeds, params, 2466 2479 results) … … 2468 2481 return { 2469 2482 'experiment': exp, 2470 'status': [make_dict(r) for r in results] 2483 'status': [make_dict(r) for r in results], 2471 2484 'proof': proof.to_dict() 2472 2485 } … … 2524 2537 "Experiment has no status!?") 2525 2538 2526 def get_segment_info(self, fed_exp, need_lock=True ):2539 def get_segment_info(self, fed_exp, need_lock=True, key='aid'): 2527 2540 ids = [] 2528 2541 term_params = { } … … 2537 2550 uri = fed.uri 2538 2551 aid = fed.allocID 2539 term_params[aid] = (uri, aid) 2552 if key == 'aid': term_params[aid] = (uri, aid) 2553 elif key == 'tb': term_params[fed.tb] = (uri, aid) 2554 2540 2555 if need_lock: self.state_lock.release() 2541 2556 return ids, term_params, expcert, repo -
fedd/federation/local_emulab_segment.py
r22a1a77 rb709861 132 132 self.get_mapping(pid,eid) 133 133 return True 134 135 class operation_segment(local_segment, emulab_segment): 136 def __init__(self, log=None, keyfile=None, debug=False, boss=None, 137 cert=None): 138 local_segment.__init__(self, log=log, keyfile=keyfile, debug=debug) 139 emulab_segment.__init__(self, boss=boss, cert=cert) 140 141 def __call__(self, parent, op, targets, param): 142 for l, p in targets.items(): 143 self.log.info("[operation_segment]: Calling op on %s(%s)" % (l,p)) 144 self.do_operation(op, l, p, param) 145 return True
Note: See TracChangeset
for help on using the changeset viewer.