def list(tablefmt): """ Lists all virtual machines and their status """ all_vms = listdir(VM_DIR) vms = [] i = 0 for vm_name in all_vms: thisvm = VM(vm_name) vms.append( OrderedDict([ ('name', thisvm.name), ('status', thisvm.status()), ('ncpus', thisvm.ncpus), ('memory', thisvm.memory), ])) i = i + 1 click.echo(tabulate(vms, headers='keys', tablefmt=tablefmt))
def test_vm_stop_non_graceful_fail(monkeypatch): # We want to catch the VM fp = abspath('tests/freebsd.conf') test_freebsd_vm = VM(fp) if test_freebsd_vm.status() == "Stopped": test_freebsd_vm.start() def mockfalse(): return 111 monkeypatch.setattr(test_freebsd_vm, 'get_pid', mockfalse) with pytest.raises(OSError, match="VM did not die when it was supposed to"): test_freebsd_vm.stop() monkeypatch.undo()
def status(vm_name): """ Status a VM """ myvm = VM(vm_name) click.echo(myvm.status())
def stop(vm_name): """ Stop a VM """ myvm = VM(vm_name) myvm.stop()
def start(vm_name): """ Start a VM """ myvm = VM(vm_name) myvm.start()
def restart(vm_name): """ Restart a VM """ myvm = VM(vm_name) myvm.restart()
def destroy(vm_name): """ Destroys a VM """ myvm = VM(vm_name) myvm.delete()
def create(name, onboot, com1, com2, disk, iso, memory, ncpus, network): """ Creates a VM """ myvm = VM(None) myvm.name = name myvm.auto_start = onboot myvm.com1 = com1 myvm.com2 = com2 myvm.iso = iso myvm.memory = memory myvm.ncpus = ncpus for disc in disk: myvm.disk.append(Disk(disc, 'ahci-hd')) for nic in network: myvm.network.append(Nic(nic, 'virtio-net')) myvm.save() click.echo("VM Created")
def test_bad_vm(): with pytest.raises(OSError, match="does not exist"): myvm = VM('blahalsdjf')