Improve handling of command line parameters, don't silently ignore unexpected arguments.

This is to avoid following behavior:

    [abb@dom0 qubes-core]$ qvm-block -l
    netvm:sda       STORAGE_DEVICE () 0 B
    dom0:sdb1       Cruzer () 3 GiB
    dom0:sdb        Cruzer () 3 GiB

    [abb@dom0 qubes-core]$ qvm-block -l
    netvm:sda       STORAGE_DEVICE () 0 B
    dom0:sdb1       Cruzer () 3 GiB
    dom0:sdb        Cruzer () 3 GiB

    [abb@dom0 qubes-core]$ qvm-block -a qdvp dom0:sdb

    [abb@dom0 qubes-core]$ qvm-block -l
    netvm:sda       STORAGE_DEVICE () 0 B
    dom0:sdb1       Cruzer () 3 GiB
    dom0:sdb        Cruzer () 3 GiB (attached to 'qdvp' as 'xvdi')

    [abb@dom0 qubes-core]$ qvm-block -d qdvp BLAHBLAH
                                          ^^^^^^^^^^^^^
    >>> The last parameter is silently ignored and all devices get detached

    [abb@dom0 qubes-core]$ qvm-block -l
    netvm:sda       STORAGE_DEVICE () 0 B
    dom0:sdb1       Cruzer () 3 GiB
    dom0:sdb        Cruzer () 3 GiB
This commit is contained in:
Alexandre Bezroutchko 2012-10-15 11:40:08 +02:00
parent abfe99756f
commit ca4367821e

View File

@ -76,8 +76,8 @@ def main():
qvm_collection.unlock_db()
if options.do_attach:
if (len (args) < 2):
parser.error ("You must provide device and vm name!")
if (len (args) != 2):
parser.error ("You must provide vm name and device!")
vm = qvm_collection.get_vm_by_name(args[0])
if vm is None:
parser.error ("Invalid VM name: %s" % args[0])
@ -111,6 +111,8 @@ def main():
elif options.do_detach:
if (len (args) < 1):
parser.error ("You must provide device or vm name!")
if len(args) > 1:
parser.error ("Too many parameters")
# Check if provided name is VM
vm = qvm_collection.get_vm_by_name(args[0])
if vm is not None:
@ -133,6 +135,8 @@ def main():
block_detach(None, attached_to['devid'], vm_xid=attached_to['xid'])
else:
# do_list
if len(args) > 0:
parser.error ("Too many parameters")
kwargs = {}
kwargs['system_disks'] = options.system_disks
for dev in block_list(**kwargs).values():