Revision c0448f4f

b/snf-tools/synnefo_tools/burnin.py
1324 1324
    return cls
1325 1325

  
1326 1326

  
1327
def cleanup_servers(delete_stale=False):
1327
def cleanup_servers(timeout, query_interval, delete_stale=False):
1328 1328

  
1329 1329
    c = ComputeClient(API, TOKEN)
1330 1330

  
......
1340 1340

  
1341 1341
    if delete_stale:
1342 1342
        print >> sys.stderr, "Deleting %d stale servers:" % len(stale)
1343
        for server in stale:
1344
            c.delete_server(server["id"])
1345
        print >> sys.stderr, green + "    ...done" + normal
1343

  
1344
        fail_tmout = time.time() + timeout
1345

  
1346

  
1347
        for s in stale:
1348
            c.delete_server(s["id"])
1349

  
1350
        
1351
        while True:
1352
            servers = c.list_servers()
1353
            stale = [s for s in servers if s["name"].startswith(SNF_TEST_PREFIX)]
1354
            for s in stale:
1355
                c.delete_server(s["id"])
1356

  
1357
            if len(stale)==0:
1358
                print >> sys.stderr, green + "    ...done" + normal
1359
                break
1360

  
1361
            elif time.time() > fail_tmout:
1362
                print >> sys.stderr, red + "Not all stale servers deleted. Action timed out." + normal
1363
                return 
1364
            else:
1365
                time.sleep(query_interval)
1366
                
1346 1367
    else:
1347 1368
        print >> sys.stderr, "Use --delete-stale to delete them."
1348 1369

  
1349 1370

  
1350
def cleanup_networks(delete_stale=False):
1371
def cleanup_networks(timeout, query_interval, delete_stale=False):
1351 1372

  
1352 1373
    c = CycladesClient(API, TOKEN)
1353 1374

  
......
1363 1384

  
1364 1385
    if delete_stale:
1365 1386
        print >> sys.stderr, "Deleting %d stale networks:" % len(stale)
1366
        for network in stale:
1367
            c.delete_network(network["id"])
1368
        print >> sys.stderr, green + "    ...done" + normal
1387

  
1388
        fail_tmout = time.time() + timeout
1389
        
1390
        for n in stale:
1391
            c.delete_network(n["id"])
1392

  
1393

  
1394
        while True:
1395
            networks = c.list_networks()
1396
            stale = [n for n in networks if n["name"].startswith(SNF_TEST_PREFIX)]
1397

  
1398
            if len(stale)==0:
1399
                print >> sys.stderr, green + "    ...done" + normal
1400
                break
1401

  
1402
            elif time.time() > fail_tmout:
1403
                print >> sys.stderr, red + "Not all stale networks deleted. Action timed out." + normal
1404
                return 
1405
            else:
1406
                time.sleep(query_interval)
1407

  
1369 1408
    else:
1370 1409
        print >> sys.stderr, "Use --delete-stale to delete them."
1371 1410

  
......
1547 1586

  
1548 1587
    # Cleanup stale servers from previous runs
1549 1588
    if opts.show_stale:
1550
        cleanup_servers(delete_stale=opts.delete_stale)
1551
        cleanup_networks(delete_stale=opts.delete_stale)
1589
        cleanup_servers(delete_stale=opts.delete_stale, timeout=opts.action_timeout, query_interval=opts.query_interval)
1590
        cleanup_networks(delete_stale=opts.delete_stale, timeout=opts.action_timeout, query_interval=opts.query_interval)
1552 1591
        return 0
1553 1592

  
1554 1593
    # Initialize a kamaki instance, get flavors, images

Also available in: Unified diff