#!/usr/bin/python2.2 import sys from vh3 import virthost from vh3.modules import diskquota import vh3.modules.reseller as mreseller DUSED = 0 DTOTAL = 0 DPCT = 0 SITES = 0 if len(sys.argv) == 2 and sys.argv[1] == "--help": print """ Usage: %s --help (this screen) %s %s --by-reseller %s --by-reseller reseller_username %s --resellers-only """ % (sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0]) sys.exit(0) def print_diskuse(index): global DTOTAL, DPCT, DUSED, SITES domain = virthost.get_domain_from_site(index) total = diskquota.get_site_quota(index) used = diskquota.get_site_used_quota(index) if total[0] == None: total = [0] if used[0] == None: used = [0] max_space = total[0] / (1024*1024) used_space = used[0] / (1024*1024) DTOTAL = DTOTAL + max_space DUSED = DUSED + used_space if max_space < 1: pct = 0 else: pct = ((used_space +0.00000001) / (max_space + 0.00000001)) * 100.00 print "%-30s %6ld %6ld %5.2f" % ( domain, max_space, used_space, pct) SITES = SITES + 1 DPCT = DPCT + pct def header(): print """\ ================================================================= DOMAIN NAME QUOTA USED % SPACE (MB) (MB) USED =================================================================""" def show_usage(indeces): for index in indeces: print_diskuse(index) def footer(): global DTOTAL, DUSED, DPCT, SITES print """\ ================================================================= TOTALS %4.2f GB %4.2f GB %5.2f %% %6s %6s %4s =================================================================""" % ( ((DTOTAL + 0.000000001)/1024), ((DUSED + 0.000000001)/1024), (DPCT/SITES), 'ALLOC', 'IN USE', '(AVG)') if len(sys.argv) < 2: header() show_usage(virthost.get_domain_list()) footer() elif sys.argv[1] == "--by-reseller" or sys.argv[1] == "--resellers-only": resellers = mreseller.get_reseller_list() wanted = None if len(sys.argv) == 3: wanted = sys.argv[2] by_reseller = 0 if sys.argv[1] == "--by-reseller": by_reseller = 1 if by_reseller == 0: header() for reseller in resellers: if reseller['username'] == None: continue rused = reseller['alloc_quota'] / (1024 * 1024) rtotal = reseller['total_quota'] / (1024 * 1024) pct = 0 if rtotal > 1: pct = ((rused +0.00000001) / (rtotal + 0.00000001)) * 100.00 username = "" if by_reseller == 1: if wanted != None: if reseller['username'] != wanted: continue DTOTAL = 0 DPCT = 0 DUSED = 0 SITES = 0 username = "Reseller: %s" % reseller['username'] else: username = reseller['username'] DTOTAL = DTOTAL + rtotal DUSED = DUSED + rused SITES = SITES + 1 DPCT = DPCT + pct if by_reseller == 1: header() print """\ %-30s %6ld %6ld %5.2f""" % (username, rtotal, rused, pct) if by_reseller == 1: print \ "=================================================================" siteIds = map( lambda x: "site%d" % x['site_id'], mreseller.get_reseller_sites(reseller['reseller_id']) ) show_usage(siteIds) footer() print if by_reseller == 0: footer()