Browse code

work towards simpiler uec

Jesse Andrews authored on 2011/11/06 08:05:14
Showing 3 changed files
1 1
new file mode 100755
... ...
@@ -0,0 +1,198 @@
0
+#!/usr/bin/env bash
1
+
2
+# Make sure that we have the proper version of ubuntu
3
+UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'`
4
+if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then
5
+    if [ ! "natty" = "$UBUNTU_VERSION" ]; then
6
+        echo "This script only works with oneiric and natty"
7
+        exit 1
8
+    fi
9
+fi
10
+
11
+# exit on error to stop unexpected errors
12
+set -o errexit
13
+
14
+# Keep track of the current directory
15
+TOOLS_DIR=$(cd $(dirname "$0") && pwd)
16
+TOP_DIR=`cd $TOOLS_DIR/..; pwd`
17
+
18
+# Abort if localrc is not set
19
+if [ ! -e $TOP_DIR/localrc ]; then
20
+    echo "You must have a localrc with ALL necessary passwords defined before proceeding."
21
+    echo "See stack.sh for required passwords."
22
+    exit 1
23
+fi
24
+
25
+# Install deps if needed
26
+dpkg -l kvm libvirt-bin kpartx || apt-get install -y --force-yes kvm libvirt-bin kpartx
27
+
28
+# Where to store files and instances
29
+WORK_DIR=${WORK_DIR:-/opt/kvmstack}
30
+
31
+# Where to store images
32
+IMAGES_DIR=$WORK_DIR/images
33
+
34
+# Original version of built image
35
+DIST_NAME=${DIST_NAME:oneiric}
36
+UEC_NAME=$DIST_NAME-server-cloudimg-amd64
37
+UEC_URL=http://uec-images.ubuntu.com/$DIST_NAME/current/$UEC_NAME-disk1.img
38
+BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw
39
+
40
+# download the base uec image if we haven't already
41
+if [ ! -e $BASE_IMAGE ]; then
42
+    mkdir -p $IMAGES_DIR
43
+    curl $UEC_URL -O $BASE_IMAGE
44
+fi
45
+
46
+cd $TOP_DIR
47
+
48
+# Source params
49
+source ./stackrc
50
+
51
+# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
52
+ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
53
+
54
+# Name of our instance, used by libvirt
55
+GUEST_NAME=${GUEST_NAME:-devstack}
56
+
57
+# Mop up after previous runs
58
+virsh destroy $GUEST_NAME || true
59
+
60
+# Where this vm is stored
61
+VM_DIR=$WORK_DIR/instances/$GUEST_NAME
62
+
63
+# Create vm dir and remove old disk
64
+mkdir -p $VM_DIR
65
+rm -f $VM_DIR/disk.img
66
+
67
+# Create a copy of the base image
68
+qemu-img create -f qcow2 -b ${BASE_IMAGE} $VM_DIR/disk.img
69
+
70
+# Back to devstack
71
+cd $TOP_DIR
72
+
73
+GUEST_NETWORK=${GUEST_NETWORK:-1}
74
+GUEST_RECREATE_NET=${GUEST_RECREATE_NET:-yes}
75
+GUEST_IP=${GUEST_IP:-192.168.$GUEST_NETWORK.50}
76
+GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24}
77
+GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0}
78
+GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.$GUEST_NETWORK.1}
79
+GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $GUEST_NETWORK`"}
80
+GUEST_RAM=${GUEST_RAM:-1524288}
81
+GUEST_CORES=${GUEST_CORES:-1}
82
+
83
+# libvirt.xml configuration
84
+NET_XML=$VM_DIR/net.xml
85
+cat > $NET_XML <<EOF
86
+<network>
87
+  <name>devstack-$GUEST_NETWORK</name>
88
+  <bridge name="stackbr%d" />
89
+  <forward/>
90
+  <ip address="$GUEST_GATEWAY" netmask="$GUEST_NETMASK" />
91
+</network>
92
+EOF
93
+
94
+if [[ "$GUEST_RECREATE_NET" == "yes" ]]; then
95
+    virsh net-destroy devstack-$GUEST_NETWORK || true
96
+    virsh net-create $VM_DIR/net.xml
97
+fi
98
+
99
+# libvirt.xml configuration
100
+LIBVIRT_XML=$VM_DIR/libvirt.xml
101
+cat > $LIBVIRT_XML <<EOF
102
+<domain type='kvm'>
103
+  <name>$GUEST_NAME</name>
104
+  <memory>$GUEST_RAM</memory>
105
+  <os>
106
+    <type arch='i686' machine='pc'>hvm</type>
107
+    <boot dev='hd'/>
108
+    <kernel>$VM_DIR/kernel</kernel>
109
+    <cmdline>root=/dev/vda ro init=/usr/lib/cloud-init/uncloud-init ds=nocloud ubuntu-pass=ubuntu</cmdline>
110
+  </os>
111
+  <features>
112
+    <acpi/>
113
+  </features>
114
+  <clock offset='utc'/>
115
+  <vcpu>$GUEST_CORES</vcpu>
116
+  <devices>
117
+    <disk type='file'>
118
+      <driver type='qcow2'/>
119
+      <source file='$VM_DIR/disk.img'/>
120
+      <target dev='vda' bus='virtio'/>
121
+    </disk>
122
+
123
+    <interface type='network'>
124
+      <source network='devstack-$GUEST_NETWORK'/>
125
+    </interface>
126
+        
127
+    <!-- The order is significant here.  File must be defined first -->
128
+    <serial type="file">
129
+      <source path='$VM_DIR/console.log'/>
130
+      <target port='1'/>
131
+    </serial>
132
+
133
+    <console type='pty' tty='/dev/pts/2'>
134
+      <source path='/dev/pts/2'/>
135
+      <target port='0'/>
136
+    </console>
137
+
138
+    <serial type='pty'>
139
+      <source path='/dev/pts/2'/>
140
+      <target port='0'/>
141
+    </serial>
142
+
143
+    <graphics type='vnc' port='-1' autoport='yes' keymap='en-us' listen='0.0.0.0'/>
144
+  </devices>
145
+</domain>
146
+EOF
147
+
148
+# Create the instance
149
+cd $VM_DIR && virsh create libvirt.xml
150
+
151
+# Tail the console log till we are done
152
+WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1}
153
+if [ "$WAIT_TILL_LAUNCH" = "1" ]; then
154
+    # Done creating the container, let's tail the log
155
+    echo
156
+    echo "============================================================="
157
+    echo "                          -- YAY! --"
158
+    echo "============================================================="
159
+    echo
160
+    echo "We're done launching the vm, about to start tailing the"
161
+    echo "stack.sh log. It will take a second or two to start."
162
+    echo
163
+    echo "Just CTRL-C at any time to stop tailing."
164
+
165
+    while [ ! -e "$VM_DIR/console.log" ]; do
166
+      sleep 1
167
+    done
168
+
169
+    tail -F $VM_DIR/console.log &
170
+
171
+    TAIL_PID=$!
172
+
173
+    function kill_tail() {
174
+        kill $TAIL_PID
175
+        exit 1
176
+    }
177
+
178
+    # Let Ctrl-c kill tail and exit
179
+    trap kill_tail SIGINT
180
+
181
+    set +o xtrace
182
+
183
+    echo "Waiting stack.sh to finish..."
184
+    while ! cat $VM_DIR/console.log | grep -q 'All done' ; do
185
+        sleep 1
186
+    done
187
+
188
+    set -o xtrace
189
+
190
+    kill $TAIL_PID
191
+
192
+    if ! grep -q "^stack.sh completed in" $VM_DIR/console.log; then
193
+        exit 1
194
+    fi
195
+    echo ""
196
+    echo "Finished - Zip-a-dee Doo-dah!"
197
+fi
0 198
new file mode 100644
... ...
@@ -0,0 +1,19 @@
0
+#ami-id: ami-fd4aa494
1
+#ami-launch-index: '0'
2
+#ami-manifest-path: ubuntu-images-us/ubuntu-lucid-10.04-amd64-server-20100427.1.manifest.xml
3
+#block-device-mapping: {ami: sda1, ephemeral0: sdb, ephemeral1: sdc, root: /dev/sda1}
4
+hostname: smoser-sys
5
+#instance-action: none
6
+instance-id: i-87018aed
7
+instance-type: m1.large
8
+#kernel-id: aki-c8b258a1
9
+local-hostname: smoser-sys.mosers.us
10
+#local-ipv4: 10.223.26.178
11
+#placement: {availability-zone: us-east-1d}
12
+#public-hostname: ec2-184-72-174-120.compute-1.amazonaws.com
13
+#public-ipv4: 184.72.174.120
14
+#public-keys:
15
+#  ec2-keypair.us-east-1: [ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCD9dlT00vOUC8Ttq6YH8RzUCVqPQl6HaSfWSTKYnZiVCpTBj1CaRZPLRLmkSB9Nziy4aRJa/LZMbBHXytQKnB1psvNknqC2UNlrXXMk+Vx5S4vg21MXYYimK4uZEY0Qz29QUiTyNsx18jpAaF4ocUpTpRhxPEBCcSCDmMbc27MU2XuTbasM2NjW/w0bBF3ZFhdH68dZICXdTxS2jUrtrCnc1D/QXVZ5kQO3jsmSyJg8E0nE+6Onpx2YRoVRSwjpGzVZ+BlXPnN5xBREBG8XxzhNFHJbek+RgK5TfL+k4yD4XhnVZuZu53cBAFhj+xPKhtisSd+YmaEq+Jt9uS0Ekd5
16
+#      ec2-keypair.us-east-1, '']
17
+#reservation-id: r-e2225889
18
+#security-groups: default
0 19
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+#cloud-config
1
+#apt_update: false
2
+#apt_upgrade: true
3
+#packages: [ bzr, pastebinit, ubuntu-dev-tools, ccache, bzr-builddeb, vim-nox, git-core, lftp ]
4
+
5
+apt_sources:
6
+ - source: ppa:smoser/ppa
7
+
8
+disable_root: True
9
+
10
+mounts:
11
+ - [ ephemeral0, None ]
12
+ - [ swap, None ]
13
+
14
+ssh_import_id: [smoser ]
15
+
16
+sm_misc:
17
+ - &user_setup |
18
+   set -x; exec > ~/user_setup.log 2>&1
19
+   echo "starting at $(date -R)"
20
+   echo "set -o vi" >> ~/.bashrc
21
+   cat >> ~/.profile <<EOF
22
+   export EDITOR=vi
23
+   EOF
24
+
25
+runcmd:
26
+ - [ sudo, -Hu, ubuntu, sh, -c, 'grep "cloud-init.*running" /var/log/cloud-init.log > ~/runcmd.log' ]
27
+ - [ sudo, -Hu, ubuntu, sh, -c, 'read up sleep < /proc/uptime; echo $(date): runcmd up at $up | tee -a ~/runcmd.log' ]
28
+ - [ sudo, -Hu, ubuntu, sh, -c, *user_setup ]
29
+
30
+password: passw0rd
31
+chpasswd: { expire: False }