565
566
567
568
569
570
571
572
573
574
575
576
577
578
|
cmd_start(start_opts)
print name," ",
finally:
# pylint: disable=no-member
start_opts.sock.shutdown(socket.SHUT_RDWR)
print ""
TEMPLATE = """#!/bin/sh
# Get machine name from current directory name
NAME=$(basename $(pwd))
# if remote access is enabled, then there should be
# SPICE_PASSWORD=password
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
|
cmd_start(start_opts)
print name," ",
finally:
# pylint: disable=no-member
start_opts.sock.shutdown(socket.SHUT_RDWR)
print ""
def cmd_shutdown(options):
""" Search for all running machines and stops all of them """
dirlist=[config.get("directories","AutostartVMs"),
config.get("directories","SharedVms")]
if os.getresuid()[1] == 0:
import grp
dirlist += map(lambda x: os.path.expanduser("~"+x)+"/VWs",
grp.getgrnam(config.get("permissions","vm_group")).gr_mem)
else:
dirlist.append(os.path.expanduser("~")+"/VWs")
count = 1 #Fake positive values for there is not postcondition loop in the python
forced_finish=time.time()+options.timeout
while count > 0:
count = 0
if time.time() < forced_finish:
command = "system_powerdown"
else:
command = "quit"
for dirname in dirlist:
if not os.access(dirname, os.X_OK):
continue
for vm in os.listdir(dirname):
mon = os.path.join(dirname,vm,"monitor")
if os.access(mon,os.W_OK):
sock=socket.socket(socket.AF_UNIX)
try:
sock.connect(mon)
except IOError as ex:
# virtual machine is not running
continue
count += 1
try:
send_command(sock,command)
except IOError:
#When hard_stopping,socket might be closed by way
pass
sock.shutdown(socket.SHUT_RDWR)
sock.close()
if not options.wait:
return
time.sleep(10)
TEMPLATE = """#!/bin/sh
# Get machine name from current directory name
NAME=$(basename $(pwd))
# if remote access is enabled, then there should be
# SPICE_PASSWORD=password
|
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
|
# Parse argument
args = ArgumentParser(description="Manage Virtual Workstations")
cmds = args.add_subparsers(dest='command', help="sub-command help")
p = cmds.add_parser("list", help="List existing VWs",
description="List existing VWs")
p.add_argument("--state", action='store_const', const=True, default=False,
dest='state', help='Show state of the machine')
p.add_argument("--addr", action='store_const', const=True, default=False,
dest='addr', help='Show mac address and spice port')
p.add_argument("--usb", action='store_const', const=True, default=False,
dest='usb', help='Show connected USB devices')
p = cmds.add_parser("version", help="show vws version")
p = cmds.add_parser("autostart",help="Autostart all VMs marked as autostartable")
# Power management
p = new_command(cmds, 'start', help='Start VW and connect to console',
description="Start VW if not running and connect " +
"to the console")
p.add_argument('--no-gui', dest='gui', action='store_const', const=False,
default=True, help='do not open console window')
p.add_argument('--cdrom', metavar='filename.iso', dest='cdrom', nargs=1,
|
<
<
>
>
>
>
>
|
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
|
# Parse argument
args = ArgumentParser(description="Manage Virtual Workstations")
cmds = args.add_subparsers(dest='command', help="sub-command help")
p = cmds.add_parser("list", help="List existing VWs",
description="List existing VWs")
p.add_argument("--state", action='store_const', const=True, default=False,
dest='state', help='Show state of the machine')
p.add_argument("--usb", action='store_const', const=True, default=False,
dest='usb', help='Show connected USB devices')
p = cmds.add_parser("version", help="show vws version")
p = cmds.add_parser("autostart",help="Autostart all VMs marked as autostartable")
p = cmds.add_parser("shutdown",help="shut down all running VMs")
p.add_argument("--wait",help="wait until all machines would be shoutdown",
action="store_const", const=True, default=False, dest="wait")
p.add_argument("--timeout",type=int,default=90,
help="how long to way for VMs shutdown before forcing it off")
# Power management
p = new_command(cmds, 'start', help='Start VW and connect to console',
description="Start VW if not running and connect " +
"to the console")
p.add_argument('--no-gui', dest='gui', action='store_const', const=False,
default=True, help='do not open console window')
p.add_argument('--cdrom', metavar='filename.iso', dest='cdrom', nargs=1,
|