dom0: move NetVM shutdown sanity check code to qvm-core
This commit is contained in:
parent
e6bbc83e0b
commit
3063ef35b7
@ -1082,7 +1082,7 @@ class QubesVm(object):
|
|||||||
|
|
||||||
return xid
|
return xid
|
||||||
|
|
||||||
def shutdown(self):
|
def shutdown(self, force=False):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -1495,6 +1495,16 @@ class QubesNetVm(QubesVm):
|
|||||||
|
|
||||||
return xid
|
return xid
|
||||||
|
|
||||||
|
def shutdown(self, force=False):
|
||||||
|
if dry_run:
|
||||||
|
return
|
||||||
|
|
||||||
|
connected_vms = [vm for vm in self.connected_vms.values() if vm.is_running()]
|
||||||
|
if connected_vms and not force:
|
||||||
|
raise QubesException("There are other VMs connected to this VM: " + str([vm.name for vm in connected_vms]))
|
||||||
|
|
||||||
|
super(QubesNetVm, self).shutdown(force=force)
|
||||||
|
|
||||||
def add_external_ip_permission(self, xid):
|
def add_external_ip_permission(self, xid):
|
||||||
if int(xid) < 0:
|
if int(xid) < 0:
|
||||||
return
|
return
|
||||||
|
@ -80,7 +80,14 @@ def vm_run_cmd(vm, cmd, options):
|
|||||||
if options.shutdown:
|
if options.shutdown:
|
||||||
if options.verbose:
|
if options.verbose:
|
||||||
print >> sys.stderr, "Shutting down VM: '{0}'...".format(vm.name)
|
print >> sys.stderr, "Shutting down VM: '{0}'...".format(vm.name)
|
||||||
vm.shutdown()
|
try:
|
||||||
|
vm.shutdown(force=options.force)
|
||||||
|
except (QubesException) as err:
|
||||||
|
# "There are other VMs connected to this VM:"
|
||||||
|
print >> sys.stderr, "ERROR: {0}".format(err)
|
||||||
|
if str(err).startswith("There are other VMs connected"):
|
||||||
|
print >> sys.stderr, "Shutdown them first or use --force switch"
|
||||||
|
exit(1)
|
||||||
return
|
return
|
||||||
|
|
||||||
if options.pause:
|
if options.pause:
|
||||||
@ -222,15 +229,6 @@ def main():
|
|||||||
print >> sys.stderr, "A VM with the name '{0}' does not exist in the system!".format(vmname)
|
print >> sys.stderr, "A VM with the name '{0}' does not exist in the system!".format(vmname)
|
||||||
exit(1)
|
exit(1)
|
||||||
vms_list.append(vm)
|
vms_list.append(vm)
|
||||||
|
|
||||||
# If stopping NetVM - stop connected VMs too
|
|
||||||
if options.shutdown and vm.is_netvm():
|
|
||||||
connected_vms = [vm for vm in qvm_collection.get_vms_connected_to(vm.qid) if vm.is_running()]
|
|
||||||
if connected_vms and not options.force:
|
|
||||||
print >> sys.stderr, "ERROR: There are other VMs connected to this VM, "
|
|
||||||
print >> sys.stderr, " shutdown them first or use --force option"
|
|
||||||
print >> sys.stderr, "VMs list: " + str([vm.name for vm in connected_vms])
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
if takes_cmd_argument:
|
if takes_cmd_argument:
|
||||||
cmd = "{user}:{cmd}".format(user=options.user, cmd=cmdstr)
|
cmd = "{user}:{cmd}".format(user=options.user, cmd=cmdstr)
|
||||||
|
@ -27,6 +27,10 @@ import sys
|
|||||||
def main():
|
def main():
|
||||||
usage = "usage: %prog [options] <vm-name>"
|
usage = "usage: %prog [options] <vm-name>"
|
||||||
parser = OptionParser (usage)
|
parser = OptionParser (usage)
|
||||||
|
|
||||||
|
parser.add_option ("--force", action="store_true", dest="force", default=False,
|
||||||
|
help="Force operation, even if may damage other VMs (eg shutdown of NetVM)")
|
||||||
|
|
||||||
(options, args) = parser.parse_args ()
|
(options, args) = parser.parse_args ()
|
||||||
if (len (args) != 1):
|
if (len (args) != 1):
|
||||||
parser.error ("You must specify VM name!")
|
parser.error ("You must specify VM name!")
|
||||||
@ -43,7 +47,7 @@ def main():
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
vm.shutdown()
|
vm.shutdown(force=options.force)
|
||||||
except (IOError, OSError) as err:
|
except (IOError, OSError) as err:
|
||||||
print >> sys.stderr, "ERROR: {0}".format(err)
|
print >> sys.stderr, "ERROR: {0}".format(err)
|
||||||
exit (1)
|
exit (1)
|
||||||
|
Loading…
Reference in New Issue
Block a user