6 from datetime import datetime
7 from optparse import OptionParser
8 from geni.util.rspec import Rspec
10 sfi_dir = os.path.expanduser("~/.sfi/")
15 usage = "%(command)s [options]" % locals()
16 description = """getNodes will query comon and generate a list of nodes
17 (plain or rspec) that meet the specified crieteria. If no criteria is
18 specified, the default action is to return node comon considers 'alive'
20 cmp_options = ['rwfs', 'uptime', 'loads', 'meminfo', 'kernver', 'cpuspeed', 'txrate', 'rxrate', 'numslices', 'liveslices']
21 option = ['numslices', 'liveslices', 'gbfree']
23 parser = OptionParser(usage=usage,description=description)
25 parser.add_option("--%s" % opt, dest="%s" % opt, action="store_true",
26 help = "available options [%s]" % ",".join(cmp_options))
31 def download_file(url, localFile):
32 webFile = urllib.urlopen(url)
33 localFile = open(localFile, 'w')
34 localFile.write(webFile.read())
38 def generate_comon_url(options):
39 url = "select = 'resptime > 0"
41 query_dict['numslices'] = 'numslices %s= %s'
42 query_dict['liveslices'] = 'liveslices %s= %s'
43 query_dict['gbfree'] = 'gbfree %s= %s'
46 full_value = options.numslices
53 month = str(date.month)
60 comon_data_filename = sfi_dir + os.sep + "comon_data.dat"
61 comon_url = "http://comon.cs.princeton.edu/status/dump_comon_%s%s%s" % (year, month, day)
63 print "storing comon data from %s in %s" % (comon_url, comon_data_filename)
64 download_file(comon_url, comon_data_filename)
66 return comon_data_filename
69 parser = create_parser()
70 (options, args) = parser.parse_args()
71 comon_file = get_comon_data()
74 if __name__ == '__main__':