+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)