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