Diff
Not logged in

Differences From Artifact [47bc1de06d]:

To Artifact [550bd4a08e]:


345
346
347
348
349
350
351
352
353
354
355
356
357







358
359
360

361
362
363




364
365
366
367
368
369










370
371
372
373
374
375
376
345
346
347
348
349
350
351






352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370





371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387







-
-
-
-
-
-
+
+
+
+
+
+
+



+



+
+
+
+

-
-
-
-
-
+
+
+
+
+
+
+
+
+
+







        os.system('qemu-img create -f qcow2 -b "%s" "%s"'%(backing,drive))

def cmd_commit(options):   
    #
    # Commits last snapshot changes into it's backing file
    #
    if options.stopped:
       #
       # Stoppend vm - last snapshot is commited into its backing file.
       # Backing file is made current drive image
       #
       os.chdir(options.dir)
       for drive in get_drives(options.dir):
        #
        # Stoppend vm - last snapshot is commited into its backing file.
        # Backing file is made current drive image
        #
        os.chdir(options.dir)
        found=0
        for drive in get_drives(options.dir):
            backing=get_backing(drive)
            if backing is None:
                continue
            found=1
            os.system('qemu-img commit "%s"'%drive)
            os.unlink(drive)
            os.rename(backing,drive)
        if not found:
            print >>sys.stderr,"No snapshots exist for this VM"
            sys.exit(1)
        
    else:
       #
       #
       # Check if we are running in the snapshot mode
       # 
       send_command(options.sock,"commit")
        #
        #
        # Check if we are running in the snapshot mode
        # 
        answer=send_command(options.sock,"info block")
        if re.search(": /tmp",answer):
            send_command(options.sock,"commit")
        else:
            print >>sys.stderr,"VM is not running in snapshot mode"
            sys.exit(1)

    


template="""#!/bin/sh
# Get machine name from current directory name
NAME=$(basename $(pwd))
510
511
512
513
514
515
516
517

518
519
520
521
522
523
524


525
526
527
528
529
530
531
532
533
534
535
536

537
538

539
540
541
542
543
544
545
521
522
523
524
525
526
527

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551

552
553
554
555
556
557
558
559







-
+







+
+












+

-
+







    """
    Adds a subparser and adds a machine name argument to it
    """
    p=cmds.add_parser(name,**kwargs)
    p.add_argument('machine',type=str,help='name of vm to operate on')
    return p
#
# arg parsing
# prepare defaults for config
#

arch=os.uname()[4]
if re.match("i[3-9]86",arch):
    arch="i386"
elif arch.startswith("arm"):
    arch="arm"


config=ConfigParser({'SharedVMs':'/var/cache/vws/shared',
    'AutoStartVMs':'/var/cache/vws/autostart'})
config.add_section('directories')
config.add_section('create options')
for option,value in [('net','user'),('size','20G'),('mem','1G'),
        ('diskif','virtio'),('sound','hda'),('arch',arch),
        ('vga','qxl')]:
    config.set('create options',option,value)
config.add_section('tools')
config.set('tools','viewer','remote-viewer %s')
config.set('tools','bridge_list','/sbin/brctl show')
config.set('tools','lsusb','lsusb')
# Read configration files
config.read(['/etc/vws.conf',os.environ['HOME']+'/.vwsrc'])
print config
# 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')