Merge lp:~jtv/orchestra/odev-restart into lp:~orchestra/orchestra/odev

Proposed by Jeroen T. Vermeulen
Status: Merged
Merged at revision: 104
Proposed branch: lp:~jtv/orchestra/odev-restart
Merge into: lp:~orchestra/orchestra/odev
Diff against target: 248 lines (+148/-62)
5 files modified
HOWTO (+38/-62)
bin/authorize-ssh (+39/-0)
bin/start-odev (+26/-0)
bin/system-setup (+27/-0)
bin/virsh-listener (+18/-0)
To merge this branch: bzr merge lp:~jtv/orchestra/odev-restart
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+91050@code.launchpad.net

Commit message

Easier restart. Automatic ssh key setup. Automated wait until cobbler server is running.

Description of the change

This should make it easier to restart a previously initialized odev environment without re-creating it, or editing the HOWTO. It reduces the steps in the script by moving the details into scripts in ./bin/ so that they're easier to run manually after, say, a reboot. All the user interaction stays in HOWTO.

Actually, two other things change here:

1. Automated help for setting up your ssh keys in the virtual cobbler instance. The HOWTO prompts you for a Launchpad user name to import keys from, but alternatively you can have it jam your ~/.ssh/id_*.pub into the cobbler server's ~/.ssh/authorized_keys.

2. The script now waits for the cobbler server's ssh server to come up before continuing. Hopefully this will prove a bit more reliable that the fixed-length sleep I inserted earlier!

Alas, the virsh-listener isn't quite working for me yet. The "range" argument (left unchanged from the original here) seems to preclude connections from the host system. Was it meant to be run on the virtual cobbler server?

To post a comment you must log in.
lp:~jtv/orchestra/odev-restart updated
103. By Jeroen T. Vermeulen

Cosmetic.

104. By Jeroen T. Vermeulen

Typo.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HOWTO'
2--- HOWTO 2012-01-30 18:25:17 +0000
3+++ HOWTO 2012-02-01 14:48:37 +0000
4@@ -2,75 +2,51 @@
5 #
6 # This file documents how to get odev running on your system. But it's also
7 # a script; you may find that you can just run it and get a working setup.
8-#
9-## install some dependencies
10-pkgs=""
11-pkgs="$pkgs genisoimage coreutils" # for cloud-init's 'make-iso'
12-pkgs="$pkgs python-libvirt libvirt-bin" # for libvirt interaction
13-pkgs="$pkgs socat" # for libvirt-> cobbler
14-pkgs="$pkgs python-cheetah" # for setup.py
15-
16-sudo apt-get update -qq || /bin/true
17-sudo apt-get install -y $pkgs </dev/null
18-
19-## add your user to libvirtd group
20-sudo adduser $USER libvirtd
21-sudo adduser $USER kvm # this is really only necessary for zimmer-build
22-
23-##
24-## NOTE: you have to log out and log back in for this to take affect
25-##
26-
27-## build a zimmer image by following readme in zimmer-build
28-cd zimmer-build
29+
30+## System-level setup. This needs to be done only once.
31+./bin/system-setup
32+
33+# The user may need to log out at this point.
34+echo "Ctrl-C if you want to log out now. Otherwise, press <enter>."
35+read
36+
37+## Build a zimmer image in this branch.
38+pushd zimmer-build
39 ./build zimmer-disk0.img
40-cd ..
41-
42-## create libvirt xml files for nodes, zimmer, network
43-./setup.py libvirt-setup
44-
45-## start odev-net network
46-virsh -c qemu:///system net-start odev-net
47-
48-## create zimmer disk image qcow backing against pristine version
49-qemu-img create -f qcow2 -b zimmer-build/zimmer-disk0.img zimmer-disk0.img
50-
51-## start zimmer instance / orchestra server
52-virsh -c qemu:///system start zimmer
53-
54+popd
55+
56+## Get zimmer and cobbler running.
57+./bin/start-odev
58+
59+cobblerlogin=ubuntu@192.168.123.2
60 cat <<EOF
61-Starting orchestra server.
62-You can now ssh ubuntu@192.168.123.2 (password: passw0rd).
63-If you do that, you may run 'ssh-import-id' to import your ssh key.
64-
65-Access the cobbler UI on http://192.168.123.2/cobbler_web
66-and log in with 'cobbler:xcobbler'.
67+While we're waiting for the server to come up, let's set up ssh login to
68+the cobbler server at $cobblerlogin.
69+
70+Please enter your Launchpad login name to import your ssh keys from Launchpad,
71+or an asterisk ("*") to import your local public ssh keys. Enter nothing to
72+skip this step.
73+
74+(If the server prompts you for a password, the default is "passw0rd")
75 EOF
76-
77-## Give the server some time to start up.
78-sleep 20
79-echo
80+read keyowner
81+./bin/authorize-ssh $cobblerlogin $keyowner
82
83 ## populate the nodes into the cobbler server
84 ./setup.py cobbler-setup
85
86-## * libvirt from the cobbler system:
87-## after 'cobbler-setup' above is done, the cobbler system will know about
88-## all the nodes and it will believe it can control them via the 'virsh'
89-## power module. It is configured
90-## to talk to qemu+tcp://192.168.123.1:65001/system . In order to allow
91-## that to be valid we have to make libvirt listen on that port/interface.
92-## This can be done moderately securely with 'socat'. Below, we tell socat
93-## to forward tcp connections on 192.168.123.1:65001 to the libvirt unix
94-## socket . It restricts connections to zimmer's IP address.
95-
96-socat -d -d \
97- TCP4-LISTEN:65001,bind=192.168.123.1,range=192.168.123.2/32,fork \
98- UNIX-CONNECT:/var/run/libvirt/libvirt-sock
99-
100-## You can verify this is working by powering a sytem on from the web-ui or
101-## the following on the cobbler server:
102-## zimmmer$ virsh -c qemu+tcp://192.168.123.1:65001/system
103+cat <<EOF
104+Starting virsh listener.
105+
106+You can verify this is working by powering a sytem on from the web-ui or
107+the following on the cobbler server:
108+
109+zimmmer$ virsh -c qemu+tcp://192.168.123.1:65001/system
110+EOF
111+
112+## Listen for libvirt requests from the Cobbler server.
113+./bin/virsh-listener
114+
115
116 ## at this point you may want to modify zimmer to provide a proxy
117 ## other than itself to things installing from it (LP: #914202).
118
119=== added directory 'bin'
120=== added file 'bin/authorize-ssh'
121--- bin/authorize-ssh 1970-01-01 00:00:00 +0000
122+++ bin/authorize-ssh 2012-02-01 14:48:37 +0000
123@@ -0,0 +1,39 @@
124+#! /bin/bash -e
125+#
126+# Wait for the virtual cobbler instance's ssh server to start up, and set up
127+# passwordless login if desired.
128+#
129+# Usage:
130+# authorize-ssh <cobbler-ssh-login> <key-owner>
131+#
132+# Where:
133+# * cobbler-ssh-login is an ssh user/hostname, e.g. ubuntu@192.168.123.2
134+# * key-owner is a Launchpad login name, or * to use local keys, or nothing.
135+#
136+# If a Launchpad login name is given, import the associated ssh keys into the
137+# cobbler instance. If key-owner is an asterisk, import the local public ssh
138+# keys from ~/.ssh/id_*.pub
139+
140+cobblerlogin=$1
141+keyowner=$2
142+
143+if test -z "$keyowner"
144+then
145+ echo "Not setting up ssh keys."
146+ echo "I'll still test a login to Cobbler though."
147+ inputfiles=/dev/null
148+ remotecmd="uptime"
149+elif test "$keyowner" = "*"
150+then
151+ inputfiles=`ls ~/.ssh/id_*.pub`
152+ echo "Copying public key(s): $inputfiles"
153+ remotecmd="tee .ssh/authorized_keys"
154+else
155+ inputfiles=/dev/null
156+ remotecmd="ssh-import-id $keyowner"
157+fi
158+
159+while ! cat $inputfiles | ssh $cobblerlogin -o StrictHostKeyChecking=no $remotecmd
160+do
161+ sleep 5
162+done
163
164=== added file 'bin/start-odev'
165--- bin/start-odev 1970-01-01 00:00:00 +0000
166+++ bin/start-odev 2012-02-01 14:48:37 +0000
167@@ -0,0 +1,26 @@
168+#! /bin/bash -e
169+#
170+# Get zimmer and cobbler running, assuming that zimmer has already been set up.
171+
172+## create libvirt xml files for nodes, zimmer, network
173+./setup.py libvirt-setup
174+
175+## start odev-net network
176+virsh -c qemu:///system net-start odev-net
177+
178+## create zimmer disk image qcow backing against pristine version
179+qemu-img create -f qcow2 -b zimmer-build/zimmer-disk0.img zimmer-disk0.img
180+
181+## start zimmer instance / orchestra server
182+virsh -c qemu:///system start zimmer
183+
184+cat <<EOF
185+Starting orchestra server.
186+You can now ssh ubuntu@192.168.123.2 (password: passw0rd).
187+If you do that, you may run 'ssh-import-id' to import your ssh key.
188+
189+Access the cobbler UI on http://192.168.123.2/cobbler_web
190+and log in with 'cobbler:xcobbler'.
191+EOF
192+
193+
194
195=== added file 'bin/system-setup'
196--- bin/system-setup 1970-01-01 00:00:00 +0000
197+++ bin/system-setup 2012-02-01 14:48:37 +0000
198@@ -0,0 +1,27 @@
199+#! /bin/bash -e
200+#
201+# System-wide setup for odev. This requires sudo.
202+
203+## install some dependencies
204+pkgs=""
205+pkgs="$pkgs genisoimage coreutils" # for cloud-init's 'make-iso'
206+pkgs="$pkgs python-libvirt libvirt-bin" # for libvirt interaction
207+pkgs="$pkgs socat" # for libvirt-> cobbler
208+pkgs="$pkgs python-cheetah" # for setup.py
209+
210+sudo apt-get update -qq || /bin/true
211+sudo apt-get install -y $pkgs </dev/null
212+
213+## add your user to libvirtd group
214+sudo adduser $USER libvirtd
215+sudo adduser $USER kvm # this is really only necessary for zimmer-build
216+
217+cat <<EOF
218+Done.
219+
220+The script just added you to the system's libvirtd and kvm groups if you
221+weren't already in them.
222+
223+If you were not previously in the libvirtd and kvm groups, log out now and
224+log back in again to make the changes take effect.
225+EOF
226
227=== added file 'bin/virsh-listener'
228--- bin/virsh-listener 1970-01-01 00:00:00 +0000
229+++ bin/virsh-listener 2012-02-01 14:48:37 +0000
230@@ -0,0 +1,18 @@
231+#! /bin/bash -e
232+
233+## * libvirt from the cobbler system:
234+## after 'cobbler-setup' above is done, the cobbler system will know about
235+## all the nodes and it will believe it can control them via the 'virsh'
236+## power module. It is configured
237+## to talk to qemu+tcp://192.168.123.1:65001/system . In order to allow
238+## that to be valid we have to make libvirt listen on that port/interface.
239+## This can be done moderately securely with 'socat'. Below, we tell socat
240+## to forward tcp connections on 192.168.123.1:65001 to the libvirt unix
241+## socket . It restricts connections to zimmer's IP address.
242+
243+sock="/var/run/libvirt/libvirt-sock"
244+
245+echo "Listening for libvirt requests on $sock."
246+socat -d -d \
247+ TCP4-LISTEN:65001,bind=192.168.123.1,range=192.168.123.2/32,fork \
248+ UNIX-CONNECT:$sock

Subscribers

People subscribed via source and target branches

to all changes: