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

Proposed by Jeroen T. Vermeulen
Status: Merged
Merged at revision: 101
Proposed branch: lp:~jtv/orchestra/odev-executable
Merge into: lp:~orchestra/orchestra/odev
Diff against target: 283 lines (+96/-70)
3 files modified
HOWTO (+35/-24)
setup.py (+12/-14)
zimmer-build/build (+49/-32)
To merge this branch: bzr merge lp:~jtv/orchestra/odev-executable
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+90516@code.launchpad.net

Commit message

Executable HOWTO; fix architecture guess in setup.py; less wget output.

Description of the change

Here's a bundle of changes I made locally:

 * Fix a stupid mistake I made in the architecture-guessing code in setup.py. It broke.

 * Reduce wget's progress output. It's nice to have some, but the volume was insane.

 * Turn HOWTO into a proper script. The difference is small, the convenience great.

 * Wait a bit between firing up Cobbler and populating its database.

 * Clean up bits of code. Easier to follow, I hope.

This gives me an odev setup that I can get running just by executing HOWTO. There's been just one wart so far: I had "sleep 10" in the HOWTO before, and I guess that wasn't enough. The setup.py run to populate the database would fail with "no route to host," but afterwards I could ssh in and also access the web UI. I guess it just needs a little longer; 20 seconds is a wild stab in the dark.

Jeroen

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'HOWTO' (properties changed: -x to +x)
2--- HOWTO 2012-01-25 14:54:08 +0000
3+++ HOWTO 2012-01-27 19:52:03 +0000
4@@ -1,46 +1,57 @@
5+#! /bin/bash -e
6+#
7+# This file documents how to get odev running on your system. But it's also
8+# a script; you may find that you can just run it and get a working setup.
9+#
10 ## install some dependencies
11-$ pkgs=""
12-$ pkgs="$pkgs genisoimage coreutils" # for cloud-init's 'make-iso'
13-$ pkgs="$pkgs python-libvirt libvirt-bin" # for libvirt interaction
14-$ pkgs="$pkgs socat" # for libvirt-> cobbler
15-$ pkgs="$pkgs python-cheetah" # for setup.py
16+pkgs=""
17+pkgs="$pkgs genisoimage coreutils" # for cloud-init's 'make-iso'
18+pkgs="$pkgs python-libvirt libvirt-bin" # for libvirt interaction
19+pkgs="$pkgs socat" # for libvirt-> cobbler
20+pkgs="$pkgs python-cheetah" # for setup.py
21
22-$ sudo apt-get update
23-$ sudo apt-get install -y $pkgs </dev/null
24+sudo apt-get update -qq || /bin/true
25+sudo apt-get install -y $pkgs </dev/null
26
27 ## add your user to libvirtd group
28-$ sudo adduser $USER libvirtd
29-$ sudo adduser $USER kvm # this is really only necessary for zimmer-build
30+sudo adduser $USER libvirtd
31+sudo adduser $USER kvm # this is really only necessary for zimmer-build
32
33 ##
34 ## NOTE: you have to log out and log back in for this to take affect
35 ##
36
37 ## build a zimmer image by following readme in zimmer-build
38-$ cd zimmer-build
39-$ ./build zimmer-disk0.img
40-$ cd ..
41+cd zimmer-build
42+./build zimmer-disk0.img
43+cd ..
44
45 ## create libvirt xml files for nodes, zimmer, network
46-$ ./setup.py libvirt-setup
47+./setup.py libvirt-setup
48
49 ## start odev-net network
50-$ virsh -c qemu:///system net-start odev-net
51+virsh -c qemu:///system net-start odev-net
52
53 ## create zimmer disk image qcow backing against pristine version
54-$ qemu-img create -f qcow2 -b zimmer-build/zimmer-disk0.img zimmer-disk0.img
55+qemu-img create -f qcow2 -b zimmer-build/zimmer-disk0.img zimmer-disk0.img
56
57 ## start zimmer instance / orchestra server
58-$ virsh -c qemu:///system start zimmer
59-
60-## Now,
61-## * you can ssh ubuntu@192.168.123.2 (password passw0rd)
62-## Then run 'ssh-import-id' or sudo.
63-## * http://192.168.123.2/cobbler_web should have cobbler web ui,
64-## log in with 'cobbler:xcobbler'
65+virsh -c qemu:///system start zimmer
66+
67+echo
68+echo "Starting orchestra server."
69+echo "You can now ssh ubuntu@192.168.123.2 (password: passw0rd)."
70+echo "If you do that, you may run 'ssh-import-id' to import your ssh key."
71+echo
72+echo "Access the cobbler UI on http://192.168.123.2/cobbler_web"
73+echo "and log in with 'cobbler:xcobbler'."
74+
75+## Give the server some time to start up.
76+sleep 20
77+echo
78
79 ## populate the nodes into the cobbler server
80-$ ./setup.py cobbler-setup
81+./setup.py cobbler-setup
82
83 ## * libvirt from the cobbler system:
84 ## after 'cobbler-setup' above is done, the cobbler system will know about
85@@ -52,7 +63,7 @@
86 ## to forward tcp connections on 192.168.123.1:65001 to the libvirt unix
87 ## socket . It restricts connections to zimmer's IP address.
88
89-$ socat -d -d \
90+socat -d -d \
91 TCP4-LISTEN:65001,bind=192.168.123.1,range=192.168.123.2/32,fork \
92 UNIX-CONNECT:/var/run/libvirt/libvirt-sock
93
94
95=== modified file 'setup.py'
96--- setup.py 2012-01-26 16:41:33 +0000
97+++ setup.py 2012-01-27 19:52:03 +0000
98@@ -1,12 +1,9 @@
99 #!/usr/bin/python
100
101 import yaml
102-import Cheetah
103 import os
104 import re
105 import sys
106-import copy
107-import pprint
108 import libvirt
109 from Cheetah.Template import Template
110 import subprocess
111@@ -49,7 +46,8 @@
112 return ret
113
114 def toLibVirtXml(self):
115- return(Template(file=self.template, searchList=[self.dictInfo()]).respond())
116+ template = Template(file=self.template, searchList=[self.dictInfo()])
117+ return template.respond()
118
119 class Node(Domain):
120 def _setcfg(self, cfg, num):
121@@ -71,7 +69,8 @@
122 self.mem = cfg['mem'] * 1024
123
124 def renderSysDom(config, syscfg, stype="node"):
125- return(Template(file=syscfg['template'], searchList=[config, syscfg]).respond())
126+ template = Template(file=syscfg['template'], searchList=[config, syscfg])
127+ return template.respond()
128
129 # cobbler:
130 # ip: 2 # ip address must be in dhcp range
131@@ -172,8 +171,7 @@
132 """Get the system architecture for use in the cobbler setup profile."""
133 # This should, for any given system, match what the zimmer-build
134 # script does to determine the right architecture.
135- arch_text = subprocess.check_output(
136- ['/bin/uname', '-m'], stdout=subprocess.PIPE)
137+ arch_text = subprocess.check_output(['/bin/uname', '-m'])
138 if re.match('i.86', arch_text):
139 return 'i386'
140 else:
141@@ -186,12 +184,12 @@
142 profile = "precise-%s-juju" % arch
143
144 cob = System(config, "zimmer")
145- server = xmlrpclib.Server("http://%s/cobbler_api" % cob.ipaddr)
146+ cobbler_url = "http://%s/cobbler_api" % cob.ipaddr
147+ print("Connecting to %s." % cobbler_url)
148+ server = xmlrpclib.Server(cobbler_url)
149 token = server.login("cobbler","xcobbler")
150
151- systems = [ ]
152- for node in NODES_RANGE:
153- systems.append(Node(config, node))
154+ systems = [Node(config, node) for node in NODES_RANGE]
155
156 for system in systems:
157 cobbler_addsystem(server, token, system, profile, hostip)
158@@ -201,17 +199,17 @@
159 cfg_file = "settings.cfg"
160
161 if len(sys.argv) == 1:
162- print "Usage: setup.py action\n action one of: libvirt-setup, cobbler-setup"
163+ print(
164+ "Usage: setup.py action\n"
165+ "action one of: libvirt-setup, cobbler-setup")
166 sys.exit(1)
167
168 config = yaml_loadf(cfg_file)
169
170 if sys.argv[1] == "libvirt-setup":
171 libvirt_setup(config)
172- sys.exit(0)
173 elif sys.argv[1] == "cobbler-setup":
174 cobbler_setup(config)
175- sys.exit(0)
176
177 if __name__ == '__main__':
178 main()
179
180=== modified file 'zimmer-build/build'
181--- zimmer-build/build 2012-01-26 17:08:39 +0000
182+++ zimmer-build/build 2012-01-27 19:52:03 +0000
183@@ -74,6 +74,34 @@
184 error "${@}"
185 }
186
187+# Strip directory path or URL from image name, and ensure a suffix of ".zimg".
188+# So /tmp/foo.img, http://foo.bar/downloads/foo.zimg, and foo all become
189+# "foo.zimg".
190+base_zimg_name() {
191+ local BASE_NAME
192+ BASE_NAME="${1##*/}"
193+ BASE_NAME="${BASE_NAME%.img}"
194+ echo "${BASE_NAME%.zimg}.zimg"
195+}
196+
197+# Download image file.
198+# Parameters: source URL, filename to save to, directory to save to.
199+download_img() {
200+ local SOURCE DESTINATION
201+ SOURCE="$1"
202+ DESTINATION="$2"
203+
204+ if test -f "$DESTINATION"
205+ then
206+ fail "please delete $DESTINATION first or use --zimg|--img"
207+ fi
208+
209+ debug 0 "downloading $SOURCE to $DESTINATION"
210+ wget --progress=dot:mega "$SOURCE" -O "$DESTINATION.partial" &&
211+ mv -- "$DESTINATION.partial" "$DESTINATION" ||
212+ fail "failed to get $SOURCE"
213+}
214+
215 short_opts="ho:v"
216 long_opts="help,ci-bzr:,img:,log:,ud-file:,verbose,zimg:"
217 getopt_out=$(getopt --name "${0##*/}" \
218@@ -123,44 +151,33 @@
219 fail "failed to make tempdir"
220 trap cleanup EXIT
221
222-[ -d "$save_d" ] || mkdir -p "$save_d" || fail "failed to mkdir $save_d"
223+mkdir -p "$save_d" || fail "failed to mkdir $save_d"
224
225 if [ -n "$img" ]; then
226 # if img was given, then we assume good, its the backing image
227 [ -f "$img" ] || fail "$img (--img) is not a file"
228 debug 0 "using $img as uncompressed image"
229 else
230- if [ -n "$zimg" ]; then
231- case "$zimg" in
232- http://*|https://*)
233- o_zimg="${zimg}"
234- zimg="${save_d}/${o_zimg##*/}"
235- zimg=${zimg%.img}; zimg=${zimg%.zimg}.zimg
236- [ -f "$zimg" ] &&
237- fail "please delete $zimg first or use --zimg|--img"
238- debug 0 "downloading $o_zimg to $zimg"
239- wget "$o_zimg" -O "$zimg.partial" &&
240- mv "$zimg.partial" "$zimg" || fail "failed to get $o_zimg"
241- ;;
242- file://*)
243- o_zimg=${zimg}
244- zimg=${zimg#file://}
245- debug 0 "using file $o_zimg as zimg"
246- [ -f "$zimg" ] || fail "$zimg is not a file"
247- ;;
248- *) [ -f "$zimg" ] || fail "$zimg is not a file"
249- debug 0 "using file $o_zimg as zimg"
250- ;;
251- esac
252- else
253- zimg="${save_d}/${DEF_ZIMG##*/}"
254- zimg=${zimg%.img}; zimg=${zimg%.zimg}.zimg
255- [ -f "$zimg" ] &&
256- fail "please delete $zimg first or use --zimg|--img"
257- debug 0 "downloading $DEF_ZIMG to $zimg"
258- wget "$DEF_ZIMG" -O "$zimg.partial" &&
259- mv "$zimg.partial" "$zimg" || fail "failed to get $DEF_ZIMG"
260- fi
261+ if [ -z "$zimg" ]
262+ then
263+ zimg="$DEF_ZIMG"
264+ fi
265+ case "$zimg" in
266+ http://*|https://*)
267+ o_zimg="${zimg}"
268+ zimg="${save_d}/`base_zimg_name ${zimg}`"
269+ download_img "$o_zimg" "$zimg"
270+ ;;
271+ file://*)
272+ o_zimg=${zimg}
273+ zimg=${zimg#file://}
274+ debug 0 "using file $o_zimg as zimg"
275+ [ -f "$zimg" ] || fail "$zimg is not a file"
276+ ;;
277+ *) [ -f "$zimg" ] || fail "$zimg is not a file"
278+ debug 0 "using file $o_zimg as zimg"
279+ ;;
280+ esac
281 img=${zimg%.zimg}.img
282 debug 0 "creating uncompressed img $img from $zimg"
283 qemu-img convert -O qcow2 "$zimg" "$img"

Subscribers

People subscribed via source and target branches

to all changes: