-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvm-start.sh
executable file
·38 lines (31 loc) · 1.14 KB
/
vm-start.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/bin/bash
# Starts a vm on the xenserver with a predefined MAC and name-label
usage() {
printf "Usage: %s: -m <mac> -n <vm name>\n" $(basename $0) >&2
exit 2
}
mac=
vmname=
while getopts 'm:n:' OPTION
do
case $OPTION in
m) mac="$OPTARG"
;;
n) vmname="$OPTARG"
;;
?) usage
exit 1
;;
esac
done
vmuuid=$(xe vm-install template=Other\ install\ media new-name-label=$vmname)
sruuid=$(xe sr-list type=lvm | grep uuid | awk '{print $5}')
vdiuuid=$(xe vdi-create name-label=$vmname sharable=0 sr-uuid=$sruuid type=user virtual-size=21474836480)
vbduuid=$(xe vbd-create bootable=true mode=RW type=DISK device=0 unpluggable=true vdi-uuid=$vdiuuid vm-uuid=$vmuuid)
nwuuid=$(xe network-list bridge=xenbr0 | grep uuid | awk '{print $5}')
xe vif-create mac=$mac network-uuid=$nwuuid device=0 vm-uuid=$vmuuid
#Boot network followed by root disk
$(xe vm-param-set HVM-boot-params:order=nc uuid=$vmuuid)
#Minimum mem requirements for RHEL/Ubuntu
$(xe vm-memory-limits-set static-min=1GiB static-max=1GiB dynamic-min=1GiB dynamic-max=1GiB uuid=$vmuuid)
$(xe vm-start uuid=$vmuuid)