-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcleanup.py
More file actions
91 lines (79 loc) · 2.78 KB
/
cleanup.py
File metadata and controls
91 lines (79 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from __future__ import absolute_import
from __future__ import print_function
from simulation import (
cancel_simulation, delete_simulation, delete_simulation_files,
load_simulations, cleanup_sim_output, cleanup_sim_workspace,
cleanup_free_nodes
)
import json
import sys
import logging
from utils import load_sys_cfg
conf = load_sys_cfg()
sims_path = conf['sims_path']
def cleanup_delete(sim_id):
simulations = load_simulations(sims_path)
try:
logging.info('Deleting simulation %s' % sim_id)
sim_info = simulations[sim_id]
delete_simulation(sim_info,conf)
except KeyError:
logging.error('Simulation %s not found.' % sim_id)
delete_simulation_files(sim_id,conf) # rm any stray files
def cleanup_cancel(sim_id):
simulations = load_simulations(sims_path)
try:
logging.info('Canceling simulation %s' % sim_id)
sim_info = simulations[sim_id]
cancel_simulation(sim_info,conf)
except KeyError:
logging.error('Simulation %s not found.' % sim_id)
def cleanup_output(sim_id):
simulations = load_simulations(sims_path)
try:
logging.info('Cleanup output for %s' % sim_id)
sim_info = simulations[sim_id]
cleanup_sim_output(sim_info,conf)
except KeyError:
logging.error('Simulation %s not found.' % sim_id)
def cleanup_workspace(sim_id):
simulations = load_simulations(sims_path)
try:
logging.info('Cleanup workspace for %s' % sim_id)
sim_info = simulations[sim_id]
cleanup_sim_workspace(sim_info,conf)
except KeyError:
logging.error('Simulation %s not found.' % sim_id)
def cleanup_free():
logging.info('Checking available nodes in the cluster')
free = cleanup_free_nodes(conf)
return free
def cleanup_list():
simulations = load_simulations(sims_path)
print('%-30s desc' % 'id')
print('-' * 40)
for k in sorted(simulations):
print('%-30s %s' % (k, simulations[k]['description']))
if __name__ == '__main__':
if len(sys.argv) < 2:
print('usage: %s [list|delete|cancel|output|workspace|free] <name>' % sys.argv[0])
sys.exit(1)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
if sys.argv[1] == 'delete':
sim_id = sys.argv[2]
cleanup_delete(sim_id)
elif sys.argv[1] == 'cancel':
sim_id=sys.argv[2]
cleanup_cancel(sim_id)
elif sys.argv[1] == 'output':
sim_id=sys.argv[2]
cleanup_output(sim_id)
elif sys.argv[1] == 'workspace':
sim_id=sys.argv[2]
cleanup_workspace(sim_id)
elif sys.argv[1] == 'list':
cleanup_list()
elif sys.argv[1] == 'free':
cleanup_free()
else:
logging.error('command line not understood %s' % sys.argv)