8367978c9681e13279c928bc274b8cca11874774
[sfa.git] / cmdline / getNodes.py
1 #!/usr/bin/python
2 import sys
3 import os
4 import traceback
5 from datetime import datetime
6 from optparse import OptionParser
7 from geni.util.rspec import Rspec
8
9 sfi_dir = os.path.expanduser("~/.sfi/")
10
11 def create_parser():
12     command = sys.argv[0]
13     argv = sys.argv[1:]
14     usage = "%(command)s [options]" % locals()
15     description = """getNodes will query comon and generate a list of nodes 
16 (plain or rspec) that meet the specified crieteria. If no criteria is 
17 specified, the default action is to return node comon considers 'alive' 
18 (resptime > 0)"""
19     options = ['alive']
20     cmp_options = ['rwfs', 'uptime', 'loads', 'meminfo', 'kernver', 'cpuspeed', 'txrate', 'rxrate', 'numslices', 'liveslices']
21      
22
23     parser = OptionParser(usage=usage,description=description)
24     for opt in options:
25         parser.add_option("--%s" % opt, dest="%s" % opt, action="store_true", 
26                           help = "available options [%s]" % ",".join(cmp_options))
27    return parser    
28
29 def get_comon_data()
30     date = datetime.now()
31     year = str(date.year)
32     month = str(date.month)
33     day = str(date.day)
34     for num in [year, month, day]:
35         if len(num) == 1:
36             num = "0" + num
37      
38     comon_data_file = sfi_dir + os.sep + "comon_data.dat" 
39     comon_url = "http://comon.cs.princeton.edu/status/dump_comon_%s%s%s" % (year, month, day)
40     
41     # wget comon data and save it 
42     # wget(comon_url)
43     #  
44
45 def main():
46     parser = create_parser()
47
48     get_comon_data()
49     
50
51 if __name__ == '__main__':
52     main()