dom0/qvm-block: change order of parameters (#514)

This commit is contained in:
Marek Marczykowski 2012-03-31 19:01:51 +02:00
parent 8105fad646
commit e5a2209cab

View File

@ -30,15 +30,16 @@ import os
def main():
usage = "usage: %prog -l [options]\n"\
"usage: %prog -a [options] <device> <vm-name>\n"\
"usage: %prog -d [options] <device>\n"\
"usage: %prog -a [options] <vm-name> <device-vm-name>:<device>\n"\
"usage: %prog -A [options] <vm-name> <file-vm-name>:<file>\n"\
"usage: %prog -d [options] <device-vm-name>:<device>\n"\
"usage: %prog -d [options] <vm-name>\n"\
"List/set VM PCI devices."
parser = OptionParser (usage)
parser.add_option ("-l", "--list", action="store_true", dest="do_list", default=False)
parser.add_option ("-A", "--attach-file", action="store", dest="file_path", default=None,
help="Attach specified file instead of physical device (syntax: qvm-block -A file backend-VM frontend-VM)")
parser.add_option ("-A", "--attach-file", action="store_true", dest="do_file_attach", default=False,
help="Attach specified file instead of physical device")
parser.add_option ("-a", "--attach", action="store_true", dest="do_attach", default=False)
parser.add_option ("-d", "--detach", action="store_true", dest="do_detach", default=False)
parser.add_option ("-f", "--frontend", dest="frontend",
@ -66,19 +67,21 @@ def main():
if options.do_attach:
if (len (args) < 2):
parser.error ("You must provide device and vm name!")
vm = qvm_collection.get_vm_by_name(args[1])
vm = qvm_collection.get_vm_by_name(args[0])
if vm is None:
parser.error ("Invalid VM name: %s" % args[1])
if options.file_path:
parser.error ("Invalid VM name: %s" % args[0])
# FIXME: here we assume that device is always in form "domain:dev", which can be changed in the future
if args[1].find(":") < 0:
parser.error ("Invalid device syntax" % args[1])
if options.do_file_attach:
dev = {}
dev['vm'] = args[0]
dev['device'] = options.file_path
(dev['vm'], dev['device']) = args[1].split(":")
dev['mode'] = 'w'
else:
dev_list = block_list()
if not args[0] in dev_list.keys():
parser.error ("Invalid device name: %s" % args[0])
dev = dev_list[args[0]]
if not args[1] in dev_list.keys():
parser.error ("Invalid device name: %s" % args[1])
dev = dev_list[args[1]]
backend_vm = qvm_collection.get_vm_by_name(dev['vm'])
assert backend_vm is not None
kwargs = {}