-
Notifications
You must be signed in to change notification settings - Fork 3
/
prep-base-domain
executable file
·123 lines (96 loc) · 4.01 KB
/
prep-base-domain
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/bin/bash
srcdir=$(readlink -m $(dirname $0))
source $srcdir/common
print_help() {
echo "$0 [os type]"
echo
echo "This script prepares a base qcow2 image of the given type for use"
echo "in deploying multiple guests in a virtual datacenter for demos."
echo
echo "Valid os types are: $IMG_TYPES"
exit 0
}
[ "-h" == "$1" ] && print_help
TYPE=$1
checktype $TYPE
test -z $VMS_DIR && error "VMS_DIR is not set"
vm=zzz-$TYPE
sub=$(getsub $TYPE)
privsub=$(( $sub - 50 ))
ipaddr=192.168.$sub.100
addhost $vm $ipaddr
mac=$(grep "zzz-@NAME@" $srcdir/net-mgmt \
| sed 's/.*mac="\(.*\)" name=.*/\1/' | sed "s/@MAC@/$privsub/")
[ -n "$mac" ] && macopt=",mac=$mac"
{
$VIRSH destroy $vm
$VIRSH undefine $vm
foreach_host $TYPE 10 "$VIRSH destroy"
foreach_host $TYPE 10 "$VIRSH undefine"
} > /dev/null 2>&1
$srcdir/prep-networks $TYPE || error
refresh-storage-pools
sudo chown $USER $VMS_DIR/$vm.img 2> /dev/null
IMPORT_IMG=$VMS_DIR/bak/$TYPE-guest.img
if [ "$TYPE" == "rhel6" ]; then
test -f $IMPORT_IMG || error "$IMPORT_IMG not present"
rsync -LaP $IMPORT_IMG $VMS_DIR/$vm.img || error
elif [ "$TYPE" == "rhel7" ]; then
test -f $IMPORT_IMG || error "$IMPORT_IMG not present"
rsync -LaP $IMPORT_IMG $VMS_DIR/$vm.img || error
elif [ "$TYPE" == "centos6" ]; then
sudo virt-builder --hostname $vm --format qcow2 --size 15G --update \
--root-password password:password --selinux-relabel \
-o $VMS_DIR/$vm.img centos-6 || error
elif [ "$TYPE" == "centos7" ]; then
# NOTE: virt-builder version of CentOS7 is broken, using downloaded
# qcow2 from centos.org site instead
#sudo virt-builder --hostname $vm --format qcow2 --size 15G --update \
# --root-password password:password --selinux-relabel \
# -o $VMS_DIR/$vm.img centos-7.0 || error
test -f $IMPORT_IMG || error "$IMPORT_IMG not present"
rsync -LaP $IMPORT_IMG $VMS_DIR/$vm.img || error
elif [ "$TYPE" == "fedora20" ]; then
# NOTE: It appears that the image used by virt-builder for F20
# is totally broken and not the same one that is actually shipped
# by the Fedora team
# sudo virt-builder --hostname $vm --format qcow2 --size 15G --update \
# --root-password password:password --selinux-relabel \
# -o $VMS_DIR/$vm.img fedora-20 || error
pushd $VMS_DIR/bak
$srcdir/os-dl-fedora
popd
test -f $IMPORT_IMG || error "$IMPORT_IMG not present"
rsync -LaP $IMPORT_IMG $VMS_DIR/$vm.img || error
# NOTE: The Fedora cloud image is 2GB rootfs. virt-builder would resize
# this for us but since virt-builder has a broken image, we do it manually
rm -fv $vm-tmp.img
qemu-img create -f qcow2 $VMS_DIR/$vm-tmp.img 15G
sudo virt-resize --expand /dev/sda1 $VMS_DIR/$vm.img $VMS_DIR/$vm-tmp.img
mv -fv $VMS_DIR/$vm-tmp.img $VMS_DIR/$vm.img
fi
sudo virt-sysprep --selinux-relabel --operations defaults,-ssh-userdir \
--root-password password:password \
--script $srcdir/sysprep-$TYPE \
--firstboot $srcdir/firstboot-$TYPE \
-a $VMS_DIR/$vm.img || error
sudo virt-install -n $vm -r 2048 --vcpus 2 --noautoconsole \
-w network=$TYPE-mgmt$macopt -w network=$TYPE-priv \
--os-variant=$(osvariant $TYPE) --graphics spice \
--import --disk path=$VMS_DIR/$vm.img \
$(use_nested_virt) || error
ssh-clean $vm
sshwait admin@$vm
$ssh admin@$vm sudo yum install yum deltarpm -y
$ssh admin@$vm sudo yum update --disablerepo=epel -y
$ssh admin@$vm sudo yum install --enablerepo=epel git-all git -y
$ssh admin@$vm sudo yum install --enablerepo=*server-opt \
nfs-utils emacs-color-theme fpaste \
yum-config-manager yum-utils yum-plugin-priorities -y
$ssh admin@$vm git clone https://github.com/pmyers/rdo-demo-helper.git
$ssh admin@$vm "echo 'export PATH=$PATH:~/rdo-demo-helper' >> .bashrc"
$VIRSH shutdown $vm > /dev/null 2>&1
virsh_shutdown_wait $vm
sudo TMPDIR=$VMS_DIR virt-sparsify --compress $VMS_DIR/$vm.img \
$VMS_DIR/$vm-sparse.img || error
sudo mv -v $VMS_DIR/$vm-sparse.img $VMS_DIR/$vm.img