Skip to content

Commit 57a2b08

Browse files
committed
Adds WS2012R2 image build script
1 parent e7841dd commit 57a2b08

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

build-ws2012r2-image.sh

+108
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/bin/bash
2+
set -e
3+
4+
IMAGE=windows-server-2012-r2.qcow2
5+
FLOPPY=Autounattend.vfd
6+
VIRTIO_ISO=virtio-win-0.1-52.iso
7+
ISO=/mnt/hgfs/ISO/9600.16384.WINBLUE_RTM.130821-1623_X64FRE_SERVER_EVAL_EN-US-IRM_SSS_X64FREE_EN-US_DV5.ISO
8+
IMAGE_NAME="Windows Server 2012 R2 Std Eval QCOW2"
9+
VM_NAME=vm1
10+
11+
KVM=/usr/libexec/qemu-kvm
12+
if [ ! -f "$KVM" ]; then
13+
KVM=/usr/bin/kvm;
14+
fi
15+
16+
if [ -f $IMAGE ]; then
17+
rm $IMAGE
18+
fi
19+
20+
qemu-img create -f qcow2 -o preallocation=metadata $IMAGE 16G
21+
iptables -I INPUT -p tcp --dport 5901 -j ACCEPT
22+
$KVM -m 2048 -smp 2 -cdrom $ISO -drive file=$VIRTIO_ISO,index=3,media=cdrom -fda $FLOPPY $IMAGE -boot d -vga std -k en-us -vnc :1
23+
24+
if [ -n `glance image-show "$IMAGE_NAME" > /dev/null && echo "1" || true` ]; then
25+
glance image-delete "$IMAGE_NAME"
26+
fi
27+
28+
glance image-create --property hypervisor_type=qemu --name "$IMAGE_NAME" --container-format bare --disk-format qcow2 < $IMAGE
29+
30+
# Save some space and get the "master image" ready
31+
gzip "$IMAGE"
32+
#mv "$IMAGE.gz" /mnt/hgfs/Downloads/
33+
34+
#Make sure to have networking properly configured
35+
#E.g.: https://raw.github.com/cloudbase/openstack-dev-scripts/master/quantum-create-networks.sh
36+
37+
NET_ID=`neutron net-show net1 | awk '{if (NR == 5) {print $4}}'`
38+
nova boot --flavor fl4 --image "$IMAGE_NAME" --key-name key1 --nic net-id=$NET_ID --meta admin_pass=Passw0rd --poll $VM_NAME
39+
40+
VM_ID=`nova show $VM_NAME | /bin/awk '{if (NR == 16) {print $4}}'`
41+
PORT_ID=`neutron port-list -- --device_id $VM_ID | /bin/awk '{if (NR == 4) {print $2}}'`
42+
FLOAT_IP_ID=`neutron floatingip-list | /bin/awk '{if (NR == 4) {print $2}}'`
43+
neutron floatingip-associate $FLOAT_IP_ID $PORT_ID
44+
45+
FLOAT_IP=`neutron floatingip-show $FLOAT_IP_ID | /bin/awk '{if (NR == 5) {print $4}}'`
46+
47+
echo "IP address: $FLOAT_IP"
48+
49+
# Wait for cloudbase-init to run
50+
# Automated test requires the WinRM plugin, not yet available
51+
sleep 300
52+
53+
# Check password depployment
54+
PASSWORD=`nova get-password $VM_ID ~/.ssh/id_rsa_key1`
55+
if [ -z "$PASSWORD" ]; then
56+
echo "Password not set"
57+
exit 1
58+
fi
59+
60+
echo "Password: $PASSWORD"
61+
62+
#Now connect via RDP on $FLOAT_IP with creedentials Admin and $PASSWORD
63+
#This will be automated with WinRM ASAP
64+
65+
# Check VirtIO drivers
66+
#(Get-NetAdapter).DriverDescription == "Red Hat VirtIO Ethernet Adapter"
67+
68+
read
69+
70+
# Check partition extension
71+
#diskpart
72+
#list disk
73+
# Output must contain: 0 B in the "Free" column
74+
75+
read
76+
77+
#Check attach volume
78+
VOLUME_ID=`cinder create 1 | awk '{if (NR == 10) {print $4}}'`
79+
80+
VOLUME_STATUS=`cinder show $VOLUME_ID | awk '{if (NR == 19) {print $4}}'`
81+
while [ "$VOLUME_STATUS" != "available" ]; do
82+
sleep 3
83+
VOLUME_STATUS=`cinder show $VOLUME_ID | awk '{if (NR == 19) {print $4}}'`
84+
done
85+
86+
nova volume-attach $VM_ID $VOLUME_ID /dev/sdb
87+
88+
#diskpart
89+
#select disk 1
90+
#attributes disk clear readonly
91+
#online disk
92+
#create partition primary
93+
94+
read
95+
96+
# Check detach volume
97+
nova volume-detach $VM_ID $VOLUME_ID
98+
cinder delete $VOLUME_ID
99+
100+
#diskpart
101+
#list disk
102+
#Output must contain only disk 0
103+
104+
read
105+
106+
# Done
107+
nova delete $VM_ID
108+

0 commit comments

Comments
 (0)