forked from larsks/virt-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virt-from
executable file
·61 lines (49 loc) · 1.2 KB
/
virt-from
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
base_format=raw
ram=1024
disksize=8G
force=
usage () {
echo "$0: usage: $0 [ -r ram ] [ -s disksize ] [ -w network-spec ] [ -IQ ] base name [name...]"
}
while getopts r:s:w:IhfQ ch; do
case $ch in
(r) ram=$OPTARG;;
(s) disksize=$OPTARG;;
(I) no_instance=1;;
(w) VIRT_INSTALL_ARGS="$VIRT_INSTALL_ARGS -w $OPTARG";;
(f) force=1;;
(Q) base_format=qcow2;;
(h) usage; exit;;
(\?) usage >&2; exit 2;;
esac
done
shift $(( $OPTIND - 1 ))
base=$1
shift
base_pool=${base%/*}
base_vol=${base#*/}
for name in $*; do
echo "--------------------------------------------------"
echo "$name"
echo
if [ "$force" = 1 ]; then
virsh vol-delete ${name}.img ${base_pool} > /dev/null 2>&1
fi
echo "Creating volume"
virsh vol-create-as ${base_pool} ${name}.img ${disksize} \
--format qcow2 \
--backing-vol ${base_vol} \
--backing-vol-format ${base_format} || exit 1
virsh vol-info ${name}.img ${base_pool}
if ! [ "$no_instance" = 1 ]; then
echo "Creating instance"
virt-install --noautoconsole \
-n ${name} -r ${ram} \
-w network=default,model=virtio \
--cpu host \
$VIRT_INSTALL_ARGS \
--disk vol=${base_pool}/${name}.img,format=qcow2,bus=virtio \
--import || exit 1
fi
done