Browse code

xenapi - cleanup

Add error on unitialised variable to the scripts. This way some issues
were identified. Also modify README with fresh variables. The patch
includes:
- Add SWIFT_HASH to the README
- Add XENAPI_CONNECTION_URL to the README
- Add VNCSERVER_PROXYCLIENT_ADDRESS to the README
- Introduce UBUNTU_INST_IFACE which is the OpenStack VM interface used
for the netinstall. It defaults to eth3. Previously this parameter
was set by the combination of HOST_IP_IFACE and the undocumented
NETINSTALL_IP
- get rid of NETINSTALL_IP
- xenrc includes CLEAN_TEMPLATES
- xenrc no longer tries to change directory
- remove chrooting from prepare_guest.sh (STAGING_DIR was always / )
- remove DO_TGZ variable from prepare_guest.sh
- use arguments to call prepare_guest.sh, instead of env vars
- Fix backslash escaping in prepare_guest_template.sh

NOTE: networking is about to be addressed in a separate change.

Related to blueprint xenapi-devstack-cleanup

Change-Id: Ie9a75321c7f41cc9a0cc051398d1e6ec2c88adfa

Mate Lakat authored on 2013/05/08 00:58:17
Showing 6 changed files
... ...
@@ -1,5 +1,4 @@
1
-Getting Started With XenServer 5.6 and Devstack
2
-===============================================
1
+# Getting Started With XenServer 5.6 and Devstack
3 2
 The purpose of the code in this directory it to help developers bootstrap
4 3
 a XenServer 5.6 (or greater) + Openstack development environment.  This file gives
5 4
 some pointers on how to get started.
... ...
@@ -9,8 +8,7 @@ The Openstack services are configured to run within a "privileged" virtual
9 9
 machine on the Xenserver host (called OS domU). The VM uses the XAPI toolstack
10 10
 to communicate with the host.
11 11
 
12
-Step 1: Install Xenserver
12
+## Step 1: Install Xenserver
13 13
 Install XenServer 5.6+ on a clean box. You can get XenServer by signing
14 14
 up for an account on citrix.com, and then visiting:
15 15
 https://www.citrix.com/English/ss/downloads/details.asp?downloadId=2311504&productId=683148
... ...
@@ -25,16 +23,14 @@ getting started (Settings like this have been used with a laptop + cheap wifi ro
25 25
 * XenServer Gateway: 192.168.1.1
26 26
 * XenServer DNS: 192.168.1.1
27 27
 
28
-Step 2: Download devstack
28
+## Step 2: Download devstack
29 29
 On your XenServer host, run the following commands as root:
30 30
 
31 31
     wget --no-check-certificate https://github.com/openstack-dev/devstack/zipball/master
32 32
     unzip -o master -d ./devstack
33 33
     cd devstack/*/
34 34
 
35
-Step 3: Configure your localrc inside the devstack directory
35
+## Step 3: Configure your localrc inside the devstack directory
36 36
 Devstack uses a localrc for user-specific configuration.  Note that
37 37
 the XENAPI_PASSWORD must be your dom0 root password.
38 38
 Of course, use real passwords if this machine is exposed.
... ...
@@ -43,12 +39,18 @@ Of course, use real passwords if this machine is exposed.
43 43
     MYSQL_PASSWORD=my_super_secret
44 44
     SERVICE_TOKEN=my_super_secret
45 45
     ADMIN_PASSWORD=my_super_secret
46
-    SERVICE_PASSWORD=$ADMIN_PASSWORD
46
+    SERVICE_PASSWORD=my_super_secret
47 47
     RABBIT_PASSWORD=my_super_secret
48
-    # This is the password for your guest (for both stack and root users)
48
+    SWIFT_HASH="66a3d6b56c1f479c8b4e70ab5c2000f5"
49
+    # This is the password for the OpenStack VM (for both stack and root users)
49 50
     GUEST_PASSWORD=my_super_secret
51
+
52
+    # XenAPI parameters
50 53
     # IMPORTANT: The following must be set to your dom0 root password!
51
-    XENAPI_PASSWORD=my_super_secret
54
+    XENAPI_PASSWORD=my_xenserver_root_password
55
+    XENAPI_CONNECTION_URL="http://address_of_your_xenserver"
56
+    VNCSERVER_PROXYCLIENT_ADDRESS=address_of_your_xenserver
57
+
52 58
     # Do not download the usual images yet!
53 59
     IMAGE_URLS=""
54 60
     # Explicitly set virt driver here
... ...
@@ -60,34 +62,32 @@ Of course, use real passwords if this machine is exposed.
60 60
     # Host Interface, i.e. the interface on the nova vm you want to expose the
61 61
     # services on. Usually eth2 (management network) or eth3 (public network) and
62 62
     # not eth0 (private network with XenServer host) or eth1 (VM traffic network)
63
-    # This is also used as the interface for the Ubuntu install
64 63
     # The default is eth3.
65 64
     # HOST_IP_IFACE=eth3
65
+
66
+    # Settings for netinstalling Ubuntu
67
+    # UBUNTU_INST_RELEASE=precise
68
+
66 69
     # First time Ubuntu network install params
67
-    NETINSTALLIP="dhcp"
68
-    NAMESERVERS=""
69
-    NETMASK=""
70
-    GATEWAY=""
70
+    # UBUNTU_INST_IFACE="eth3"
71
+    # UBUNTU_INST_IP="dhcp"
71 72
     EOF
72 73
 
73
-Step 4: Run ./install_os_domU.sh from the tools/xen directory
74
-cd tools/xen
75
-./install_os_domU.sh
74
+## Step 4: Run `./install_os_domU.sh` from the `tools/xen` directory
76 75
 
77
-Once this script finishes executing, log into the VM (openstack domU)
78
-that it installed and tail the run.sh.log file. You will need to wait
79
-until it run.sh has finished executing.
76
+    cd tools/xen
77
+    ./install_os_domU.sh
80 78
 
79
+Once this script finishes executing, log into the VM (openstack domU) that it
80
+installed and tail the run.sh.log file. You will need to wait until it run.sh
81
+has finished executing.
81 82
 
82
-Step 5: Do cloudy stuff!
83
+## Step 5: Do cloudy stuff!
83 84
 * Play with horizon
84 85
 * Play with the CLI
85 86
 * Log bugs to devstack and core projects, and submit fixes!
86 87
 
87
-Step 6: Run from snapshot
88
+## Step 6: Run from snapshot
88 89
 If you want to quicky re-run devstack from a clean state,
89 90
 using the same settings you used in your previous run,
90
-you can revert the DomU to the snapshot called "before_first_boot"
91
+you can revert the DomU to the snapshot called `before_first_boot`
... ...
@@ -1,15 +1,13 @@
1 1
 #!/bin/bash
2 2
 
3
-# This script is a level script
4
-# It must be run on a XenServer or XCP machine
3
+# This script must be run on a XenServer or XCP machine
5 4
 #
6 5
 # It creates a DomU VM that runs OpenStack services
7 6
 #
8 7
 # For more details see: README.md
9 8
 
10
-# Exit on errors
11 9
 set -o errexit
12
-# Echo commands
10
+set -o nounset
13 11
 set -o xtrace
14 12
 
15 13
 # Abort if localrc is not set
... ...
@@ -31,13 +29,12 @@ THIS_DIR=$(cd $(dirname "$0") && pwd)
31 31
 # xapi functions
32 32
 . $THIS_DIR/functions
33 33
 
34
-
35 34
 #
36 35
 # Get Settings
37 36
 #
38 37
 
39 38
 # Source params - override xenrc params in your localrc to suit your taste
40
-source xenrc
39
+source $THIS_DIR/xenrc
41 40
 
42 41
 xe_min()
43 42
 {
... ...
@@ -10,54 +10,51 @@
10 10
 # creating the user called "stack",
11 11
 # and shuts down the VM to signal the script has completed
12 12
 
13
-set -x
14
-# Echo commands
13
+set -o errexit
14
+set -o nounset
15 15
 set -o xtrace
16 16
 
17 17
 # Configurable nuggets
18
-GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
19
-STAGING_DIR=${STAGING_DIR:-stage}
20
-DO_TGZ=${DO_TGZ:-1}
21
-XS_TOOLS_PATH=${XS_TOOLS_PATH:-"/root/xs-tools.deb"}
22
-STACK_USER=${STACK_USER:-stack}
18
+GUEST_PASSWORD="$1"
19
+XS_TOOLS_PATH="$2"
20
+STACK_USER="$3"
23 21
 
24 22
 # Install basics
25
-chroot $STAGING_DIR apt-get update
26
-chroot $STAGING_DIR apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
27
-chroot $STAGING_DIR apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
28
-chroot $STAGING_DIR pip install xenapi
23
+apt-get update
24
+apt-get install -y cracklib-runtime curl wget ssh openssh-server tcpdump ethtool
25
+apt-get install -y curl wget ssh openssh-server python-pip git vim-nox sudo
26
+pip install xenapi
29 27
 
30 28
 # Install XenServer guest utilities
31
-cp $XS_TOOLS_PATH ${STAGING_DIR}${XS_TOOLS_PATH}
32
-chroot $STAGING_DIR dpkg -i $XS_TOOLS_PATH
33
-chroot $STAGING_DIR update-rc.d -f xe-linux-distribution remove
34
-chroot $STAGING_DIR update-rc.d xe-linux-distribution defaults
29
+dpkg -i $XS_TOOLS_PATH
30
+update-rc.d -f xe-linux-distribution remove
31
+update-rc.d xe-linux-distribution defaults
35 32
 
36 33
 # Make a small cracklib dictionary, so that passwd still works, but we don't
37 34
 # have the big dictionary.
38
-mkdir -p $STAGING_DIR/usr/share/cracklib
39
-echo a | chroot $STAGING_DIR cracklib-packer
35
+mkdir -p /usr/share/cracklib
36
+echo a | cracklib-packer
40 37
 
41 38
 # Make /etc/shadow, and set the root password
42
-chroot $STAGING_DIR "pwconv"
43
-echo "root:$GUEST_PASSWORD" | chroot $STAGING_DIR chpasswd
39
+pwconv
40
+echo "root:$GUEST_PASSWORD" | chpasswd
44 41
 
45 42
 # Put the VPX into UTC.
46
-rm -f $STAGING_DIR/etc/localtime
43
+rm -f /etc/localtime
47 44
 
48 45
 # Add stack user
49
-chroot $STAGING_DIR groupadd libvirtd
50
-chroot $STAGING_DIR useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd
51
-echo $STACK_USER:$GUEST_PASSWORD | chroot $STAGING_DIR chpasswd
52
-echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> $STAGING_DIR/etc/sudoers
46
+groupadd libvirtd
47
+useradd $STACK_USER -s /bin/bash -d /opt/stack -G libvirtd
48
+echo $STACK_USER:$GUEST_PASSWORD | chpasswd
49
+echo "$STACK_USER ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
53 50
 
54 51
 # Give ownership of /opt/stack to stack user
55
-chroot $STAGING_DIR chown -R $STACK_USER /opt/stack
52
+chown -R $STACK_USER /opt/stack
56 53
 
57 54
 # Make our ip address hostnames look nice at the command prompt
58
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/opt/stack/.bashrc
59
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/root/.bashrc
60
-echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $STAGING_DIR/etc/profile
55
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> /opt/stack/.bashrc
56
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> /root/.bashrc
57
+echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> /etc/profile
61 58
 
62 59
 function setup_vimrc {
63 60
     if [ ! -e $1 ]; then
... ...
@@ -72,20 +69,15 @@ EOF
72 72
 }
73 73
 
74 74
 # Setup simple .vimrcs
75
-setup_vimrc $STAGING_DIR/root/.vimrc
76
-setup_vimrc $STAGING_DIR/opt/stack/.vimrc
77
-
78
-if [ "$DO_TGZ" = "1" ]; then
79
-    # Compress
80
-    rm -f stage.tgz
81
-    tar cfz stage.tgz stage
82
-fi
75
+setup_vimrc /root/.vimrc
76
+setup_vimrc /opt/stack/.vimrc
83 77
 
84 78
 # remove self from local.rc
85 79
 # so this script is not run again
86 80
 rm -rf /etc/rc.local
87
-mv /etc/rc.local.preparebackup /etc/rc.local
88
-cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.backup
81
+
82
+# Restore rc.local file
83
+cp /etc/rc.local.preparebackup /etc/rc.local
89 84
 
90 85
 # shutdown to notify we are done
91 86
 shutdown -h now
... ...
@@ -15,9 +15,8 @@
15 15
 # The resultant image is started by install_os_domU.sh,
16 16
 # and once the VM has shutdown, build_xva.sh is run
17 17
 
18
-# Exit on errors
19 18
 set -o errexit
20
-# Echo commands
19
+set -o nounset
21 20
 set -o xtrace
22 21
 
23 22
 # This directory
... ...
@@ -75,7 +74,8 @@ cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.preparebackup
75 75
 
76 76
 # run prepare_guest.sh on boot
77 77
 cat <<EOF >$STAGING_DIR/etc/rc.local
78
-GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ \
79
-    DO_TGZ=0 XS_TOOLS_PATH=$XS_TOOLS_PATH \
80
-    bash /opt/stack/prepare_guest.sh > /opt/stack/prepare_guest.log 2>&1
78
+#!/bin/sh -e
79
+bash /opt/stack/prepare_guest.sh \\
80
+    "$GUEST_PASSWORD" "$XS_TOOLS_PATH" "$STACK_USER" \\
81
+    > /opt/stack/prepare_guest.log 2>&1
81 82
 EOF
... ...
@@ -7,9 +7,8 @@
7 7
 # Based on a script by: David Markey <david.markey@citrix.com>
8 8
 #
9 9
 
10
-# Exit on errors
11 10
 set -o errexit
12
-# Echo commands
11
+set -o nounset
13 12
 set -o xtrace
14 13
 
15 14
 # This directory
... ...
@@ -54,11 +53,11 @@ disk_size=$(($OSDOMU_VDI_GB * 1024 * 1024 * 1024))
54 54
 pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 \
55 55
 console-setup/ask_detect=false locale=${UBUNTU_INST_LOCALE} \
56 56
 keyboard-configuration/layoutcode=${UBUNTU_INST_KEYBOARD} \
57
-netcfg/choose_interface=${HOST_IP_IFACE} \
57
+netcfg/choose_interface=${UBUNTU_INST_IFACE} \
58 58
 netcfg/get_hostname=os netcfg/get_domain=os auto \
59 59
 url=${preseed_url}"
60 60
 
61
-if [ "$NETINSTALLIP" != "dhcp" ]; then
61
+if [ "$UBUNTU_INST_IP" != "dhcp" ]; then
62 62
     netcfgargs="netcfg/disable_autoconfig=true \
63 63
 netcfg/get_nameservers=${UBUNTU_INST_NAMESERVERS} \
64 64
 netcfg/get_ipaddress=${UBUNTU_INST_IP} \
... ...
@@ -8,6 +8,9 @@
8 8
 # Name of this guest
9 9
 GUEST_NAME=${GUEST_NAME:-DevStackOSDomU}
10 10
 
11
+# Template cleanup
12
+CLEAN_TEMPLATES=${CLEAN_TEMPLATES:-false}
13
+
11 14
 # Size of image
12 15
 VDI_MB=${VDI_MB:-5000}
13 16
 OSDOMU_MEM_MB=1024
... ...
@@ -19,7 +22,6 @@ GUEST_PASSWORD=${GUEST_PASSWORD:-secrete}
19 19
 # Host Interface, i.e. the interface on the nova vm you want to expose the
20 20
 # services on. Usually eth2 (management network) or eth3 (public network) and
21 21
 # not eth0 (private network with XenServer host) or eth1 (VM traffic network)
22
-# This is also used as the interface for the Ubuntu install
23 22
 HOST_IP_IFACE=${HOST_IP_IFACE:-eth3}
24 23
 
25 24
 #
... ...
@@ -65,12 +67,11 @@ UBUNTU_INST_ARCH="amd64"
65 65
 UBUNTU_INST_REPOSITORY="http://archive.ubuntu.net/ubuntu"
66 66
 UBUNTU_INST_LOCALE="en_US"
67 67
 UBUNTU_INST_KEYBOARD="us"
68
-# network configuration for HOST_IP_IFACE during install
68
+# network configuration for ubuntu netinstall
69
+UBUNTU_INST_IFACE="eth3"
69 70
 UBUNTU_INST_IP="dhcp"
70 71
 UBUNTU_INST_NAMESERVERS=""
71 72
 UBUNTU_INST_NETMASK=""
72 73
 UBUNTU_INST_GATEWAY=""
73 74
 
74
-# Load stackrc defaults
75
-# then override with settings from localrc
76
-cd ../.. && source ./stackrc && cd $TOP_DIR
75
+source ../../stackrc