From: Peter Iannucci Date: Mon, 4 Oct 2010 02:10:30 +0000 (-0400) Subject: Added "web vgcapacity" probe for disk utilization. X-Git-Tag: 0.4.7~2 X-Git-Url: http://xvm.mit.edu/gitweb/invirt/packages/invirt-remote.git/commitdiff_plain/9b2c6cb76b2935133c0c1ed1626d077614b460ec Added "web vgcapacity" probe for disk utilization. --- diff --git a/debian/changelog b/debian/changelog index bd85a61..8a010c4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +invirt-remote (0.4.6) unstable; urgency=low + + * Add method "vgcapacity" to probe available disk space. + + -- Peter A. Iannucci Sun, 03 Oct 2010 22:07:25 -0400 + invirt-remote (0.4.5) unstable; urgency=low * Changed dependency debathena-kerberos-config -> diff --git a/host/usr/sbin/invirt-lvm b/host/usr/sbin/invirt-lvm index a505978..a042f0e 100755 --- a/host/usr/sbin/invirt-lvm +++ b/host/usr/sbin/invirt-lvm @@ -22,6 +22,14 @@ def ensureoff(machine): rv = call(["/usr/sbin/xm", "destroy", prefix + machine], stderr=PIPE) +machine_specific = subcommand not in ['lvcreate-all', 'vgcapacity']: + +if machine_specific: + machine = sys.argv[2] + disk = sys.argv[3] + lvname = prefix + machine + "_" + disk + lvpath = "/dev/" + vg + "/" + lvname + if subcommand == "lvcreate-all": from invirt import database import re @@ -38,12 +46,7 @@ if subcommand == "lvcreate-all": if rv != 0: print >>sys.stderr, "Error creating LV %s\n" %(lvname,) sys.exit(1) -else: - machine = sys.argv[2] - disk = sys.argv[3] - lvname = prefix + machine + "_" + disk - lvpath = "/dev/" + vg + "/" + lvname -if subcommand == "lvremove": +elif subcommand == "lvremove": def error(): print >>sys.stderr, "Error removing LV %s\n" % lvname sys.exit(1) @@ -93,4 +96,23 @@ elif subcommand == "lvcreate": if rv != 0: print >>sys.stderr, "Error creating LV %s\n" %(lvname,) sys.exit(1) +elif subcommand == "vgcapacity": + p = Popen(["/sbin/vgs", "-o", "vg_extent_size,vg_extent_count,vg_free_count", + "--noheadings", "--units", "k", "--nosuffix", "--separator", ":", + vg], + stdout=PIPE, stderr=PIPE) + out,err = p.communicate() + + try: + fields = out.strip().split(':') + extent_size = float(fields[0]) # in kibibytes + extent_count = int(fields[1]) + free_count = int(fields[2]) + total_space_TiB = extent_size * extent_count / 1024.**3 + free_space_TiB = extent_size * free_count / 1024.**3 + print >>sys.stdout, "Total: %.3f TiB" % (total_space_TiB,) + print >>sys.stdout, "Free: %.3f TiB" % (free_space_TiB,) + except: + print >>sys.stderr, "Error obtaining vg capacity:\n%s\n" % (err,) + sys.exit(1) diff --git a/host/usr/sbin/invirt-remote b/host/usr/sbin/invirt-remote index 4c78d4e..ceb8182 100755 --- a/host/usr/sbin/invirt-remote +++ b/host/usr/sbin/invirt-remote @@ -14,7 +14,7 @@ case "$TYPE" in ;; web) case "$SERVICE" in - lvcreate|lvremove|lvrename|lvresize) + lvcreate|lvremove|lvrename|lvresize|vgcapacity) COMMAND=/usr/sbin/invirt-lvm ;; listvms) diff --git a/server/usr/sbin/invirt-remote-proxy b/server/usr/sbin/invirt-remote-proxy index f5c5248..b70eb4d 100755 --- a/server/usr/sbin/invirt-remote-proxy +++ b/server/usr/sbin/invirt-remote-proxy @@ -18,7 +18,7 @@ case "$TYPE/$SERVICE" in invirt-remote-vnccert "$@" ;; web/availability | web/avail ) invirt-remote-availability "$@" ;; - web/lvcreate | web/lvremove | web/lvrename | web/lvresize ) + web/lvcreate | web/lvremove | web/lvrename | web/lvresize | web/vgcapacity ) invirt-remote-lvm "$SERVICE" "$@" ;; control/help )