#!/usr/bin/python3 import argparse import sys from VMHelper import VMHelper helper = None def vmm_start(args): print('Starting VM {0.vmid}.'.format(args)) helper.startVM(args.vmid) def vmm_stop(args): print('Stopping VM {0.vmid}.'.format(args)) helper.stopVM(args['vmid']) def vmm_status(args): if args.v >= 1: print('Gathering status information for VM {0.vmid}.'.format(args)) print("VM ID: {0}".format(args.vmid)) print("Qemu process is running: " + ("yes (pid: {0})".format(helper.getPid(args.vmid)) if helper.process_running(args.vmid) else "no")) def vmm_cleanup(args): print('Cleaning up for VM {0.vmid}.'.format(args)) helper.teardownNetwork(args.vmid) def main(): global helper print("MC VM Manager v0.1\nCopyright (c) M. Hauschild and P. Dahlberg 2013.\n") parser = argparse.ArgumentParser(prog='mcvmm', description='Manages VMs') subparsers = parser.add_subparsers(title='subcommands') parser.add_argument('-v', action='count', default=0, help='increase verbosity') parser_start = subparsers.add_parser('start', help='starts a VM') parser_start.add_argument('vmid', action='store', help='the ID of the VM') parser_start.set_defaults(func=vmm_start) parser_stop = subparsers.add_parser('stop', help='stop a VM') parser_stop.add_argument('vmid', action='store', help='the ID of the VM') parser_stop.set_defaults(func=vmm_stop) parser_status = subparsers.add_parser('status', help='status a VM') parser_status.add_argument('-v', action='count', help='increase verbosity') parser_status.add_argument('vmid', action='store', default=0, help='the ID of the VM') parser_status.set_defaults(func=vmm_status) parser_cleanup = subparsers.add_parser('cleanup', help='cleans up stuff for a VM') parser_cleanup.add_argument('vmid', action='store', default=0, help='the ID of the VM') parser_cleanup.set_defaults(func=vmm_cleanup) helper = VMHelper() args = parser.parse_args() #TODO abfrage ob vmid existiert args.func(args) if __name__ == '__main__': main()