Skip to content

Instantly share code, notes, and snippets.

@sameo
Last active March 2, 2020 19:11
Show Gist options
  • Save sameo/7fed75c38e897f86c0a3a2c02a9942fd to your computer and use it in GitHub Desktop.
Save sameo/7fed75c38e897f86c0a3a2c02a9942fd to your computer and use it in GitHub Desktop.

Create a guest VM

The VM is created, but not booted

#!/bin/bash

curl --unix-socket $1 -i \
     -X PUT 'http://localhost/api/v1/vm.create' \
     -H 'Accept: application/json'           \
     -H 'Content-Type: application/json'     \
     -d '{
     	"cpus":4,
	"kernel":{"path":"/home/samuel/devlp/kernels/linux-nemu/vmlinux"},
	"cmdline":{"args":"console=hvc0 reboot=k panic=1 nomodules i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd root=/dev/vda3"},
	"disks":[{"path":"/home/samuel/devlp/hypervisor/images/clear-30080-kvm.img"}],
	"net":[{"ip":"192.168.10.10", "mask":"255.255.255.0", "mac":"12:34:56:78:90:01"}]
       	}'

Boot a VM

#!/bin/bash

curl --unix-socket $1 -i -X PUT 'http://localhost/api/v1/vm.boot'

Shut a VM down

#!/bin/bash

curl --unix-socket $1 -i -X PUT 'http://localhost/api/v1/vm.shutdown'

Reboot a VM

#!/bin/bash

curl --unix-socket $1 -i -X PUT 'http://localhost/api/v1/vm.reboot'

Delete a VM

#!/bin/bash

curl --unix-socket $1 -i -X PUT 'http://localhost/api/v1/vm.delete'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment