mbailey-ruby-xen 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/Manifest.txt +6 -4
- data/README.rdoc +1 -3
- data/lib/ruby-xen.rb +92 -18
- data/lib/templates/domu.cfg.erb +1 -1
- data/lib/templates/xen-tools.conf.erb +289 -0
- data/lib/xen/backup.rb +71 -2
- data/lib/xen/command.rb +94 -23
- data/lib/xen/config_file.rb +160 -0
- data/lib/xen/host.rb +23 -5
- data/lib/xen/instance.rb +53 -52
- data/lib/xen/lvm.rb +33 -0
- data/lib/xen/slice.rb +117 -43
- data/lib/xen/xen_tools_conf.rb +56 -0
- data/test/test_ruby-xen.rb +2 -2
- metadata +27 -8
- data/lib/xen/config.rb +0 -139
- data/lib/xen/image.rb +0 -12
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -8,9 +8,11 @@ test/test_ruby-xen.rb
|
|
8
8
|
lib/ruby-xen/domain.rb
|
9
9
|
lib/xen/backup.rb
|
10
10
|
lib/xen/command.rb
|
11
|
-
lib/xen/
|
12
|
-
lib/xen/slice.rb
|
11
|
+
lib/xen/config_file.rb
|
13
12
|
lib/xen/host.rb
|
14
|
-
lib/xen/image.rb
|
15
13
|
lib/xen/instance.rb
|
16
|
-
lib/
|
14
|
+
lib/xen/lvm.rb
|
15
|
+
lib/xen/slice.rb
|
16
|
+
lib/xen/xen_tools_conf.rb
|
17
|
+
lib/templates/domu.cfg.erb
|
18
|
+
lib/templates/xen-tools.conf.erb
|
data/README.rdoc
CHANGED
data/lib/ruby-xen.rb
CHANGED
@@ -1,3 +1,36 @@
|
|
1
|
+
class ValidationFailed < StandardError; end
|
2
|
+
|
3
|
+
|
4
|
+
module Xen
|
5
|
+
# General configuration for ruby-xen
|
6
|
+
|
7
|
+
# Location of Xen config files
|
8
|
+
XEN_DOMU_CONFIG_DIR = '/etc/xen'
|
9
|
+
# XEN_DOMU_CONFIG_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec/fixtures/xen_domu_configs'))
|
10
|
+
|
11
|
+
# We don't want out library to hit Xen too often (premature optimization perhaps?)
|
12
|
+
# so we keep information about Xen instances in an object. Specify how long before
|
13
|
+
# the object expires.
|
14
|
+
INSTANCE_OBJECT_LIFETIME = 5 # seconds
|
15
|
+
|
16
|
+
# General location for config file templates
|
17
|
+
TEMPLATE_DIR = File.expand_path(File.dirname(__FILE__) + '/../lib/templates')
|
18
|
+
|
19
|
+
# Extension for Xen domU config files
|
20
|
+
CONFIG_FILE_EXTENSION = '.cfg'
|
21
|
+
|
22
|
+
# Directory for backups of system images
|
23
|
+
BACKUP_DIR='/var/xen_images'
|
24
|
+
|
25
|
+
# File extension for backups
|
26
|
+
BACKUP_FILE_EXT = '.tar'
|
27
|
+
|
28
|
+
TEMPLATES_BASE = File.join(File.dirname(__FILE__), 'templates')
|
29
|
+
|
30
|
+
XEN_TOOLS_CONFIG_FILE = '/etc/xen-tools/xen-tools.conf'
|
31
|
+
|
32
|
+
end
|
33
|
+
|
1
34
|
class Array #:nodoc:
|
2
35
|
# Extracts options from a set of arguments. Removes and returns the last
|
3
36
|
# element in the array if it's a hash, otherwise returns a blank hash.
|
@@ -13,21 +46,44 @@ class Array #:nodoc:
|
|
13
46
|
end
|
14
47
|
end
|
15
48
|
|
16
|
-
|
17
|
-
#
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
|
25
|
-
|
26
|
-
|
49
|
+
class Hash #:nodoc:
|
50
|
+
# Converts a Hash into an array of key=val formatted strings
|
51
|
+
#
|
52
|
+
# puts { :nics => 2, :vcpus => 1, :memory => 64, :dhcp => true }.to_args
|
53
|
+
#
|
54
|
+
# produces:
|
55
|
+
#
|
56
|
+
# ["--memory=64", "--nics=2", "--vcpus=1", "--dhcp"]
|
57
|
+
def to_args
|
58
|
+
collect{|k,v| (v.to_s == 'true') ? "--#{k.to_s}" : "--#{k.to_s}=#{v}"}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
class String
|
27
63
|
|
28
|
-
#
|
29
|
-
|
64
|
+
# Convert string to megabytes
|
65
|
+
def to_megabytes
|
66
|
+
gigabytes = /(gb|gig|gigabytes?)/i
|
67
|
+
megabytes = /(mb|meg|megabytes?)/i
|
68
|
+
kilobytes = /(kb|kilobytes?)/i
|
69
|
+
bytes = /bytes?/i
|
70
|
+
|
71
|
+
if index(gigabytes)
|
72
|
+
return sub(gigabytes,'').to_i * 1024
|
73
|
+
elsif index(megabytes)
|
74
|
+
return sub(megabytes,'').to_i
|
75
|
+
elsif index(kilobytes)
|
76
|
+
return sub(kilobytes,'').to_i / 1024
|
77
|
+
elsif index(bytes)
|
78
|
+
return sub(bytes,'').to_i / (1024*1024)
|
79
|
+
else
|
80
|
+
return self.to_i
|
81
|
+
end
|
82
|
+
end
|
30
83
|
|
84
|
+
end
|
85
|
+
|
86
|
+
module Xen
|
31
87
|
# DRY up some classes (children of Slice) with some module funkiness.
|
32
88
|
module Parentable
|
33
89
|
# Returns the parent Slice object (d) for a sub-object.
|
@@ -39,7 +95,7 @@ module Xen
|
|
39
95
|
# i.object_id == s.instance.object_id # true
|
40
96
|
#
|
41
97
|
def slice
|
42
|
-
d = Xen::Slice.new(name)
|
98
|
+
d = Xen::Slice.new(:name => name)
|
43
99
|
# Insert the current object into the newly created Slice's attributes
|
44
100
|
d.instance_variable_set("@#{self.class.to_s.sub('Xen::','').downcase}", self)
|
45
101
|
d
|
@@ -47,10 +103,28 @@ module Xen
|
|
47
103
|
end
|
48
104
|
end
|
49
105
|
|
106
|
+
class String
|
107
|
+
def underscorize
|
108
|
+
self.sub("-", "__")
|
109
|
+
end
|
110
|
+
def ununderscorize
|
111
|
+
self.sub("__", "-")
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
# We want to use Rails's stringify_keys
|
116
|
+
require "active_support/core_ext/hash/keys"
|
117
|
+
require "active_support/core_ext/hash/reverse_merge"
|
118
|
+
class Hash #:nodoc:
|
119
|
+
include ActiveSupport::CoreExtensions::Hash::Keys
|
120
|
+
include ActiveSupport::CoreExtensions::Hash::ReverseMerge
|
121
|
+
end
|
122
|
+
|
50
123
|
require "#{File.dirname(__FILE__)}/xen/backup"
|
51
124
|
require "#{File.dirname(__FILE__)}/xen/command"
|
52
|
-
require "#{File.dirname(__FILE__)}/xen/
|
53
|
-
require "#{File.dirname(__FILE__)}/xen/slice"
|
125
|
+
require "#{File.dirname(__FILE__)}/xen/config_file"
|
54
126
|
require "#{File.dirname(__FILE__)}/xen/host"
|
55
|
-
require "#{File.dirname(__FILE__)}/xen/
|
56
|
-
require "#{File.dirname(__FILE__)}/xen/
|
127
|
+
require "#{File.dirname(__FILE__)}/xen/instance"
|
128
|
+
require "#{File.dirname(__FILE__)}/xen/slice"
|
129
|
+
require "#{File.dirname(__FILE__)}/xen/xen_tools_conf"
|
130
|
+
require "#{File.dirname(__FILE__)}/xen/lvm"
|
data/lib/templates/domu.cfg.erb
CHANGED
@@ -0,0 +1,289 @@
|
|
1
|
+
<%
|
2
|
+
# This is like a Rails Helper and belongs somewhere else
|
3
|
+
def comment_if_blank(attribute)
|
4
|
+
instance_variable_get('@'+ attribute.to_s) ? '' : '# '
|
5
|
+
end
|
6
|
+
|
7
|
+
def render_config(name, default)
|
8
|
+
"#{comment_if_blank(name)}#{name.to_s.ununderscorize} = #{instance_variable_get('@'+ name.to_s) || default}"
|
9
|
+
end
|
10
|
+
%>
|
11
|
+
##
|
12
|
+
# /etc/xen-tools/xen-tools.conf
|
13
|
+
##
|
14
|
+
#
|
15
|
+
# This is the global configuration file for the scripts included
|
16
|
+
# within the xen-tools package.
|
17
|
+
#
|
18
|
+
# For more details please see:
|
19
|
+
#
|
20
|
+
# http://xen-tools.org/
|
21
|
+
#
|
22
|
+
##
|
23
|
+
|
24
|
+
|
25
|
+
##
|
26
|
+
#
|
27
|
+
# File Format
|
28
|
+
# -----------
|
29
|
+
#
|
30
|
+
# Anything following a '#' character is ignored as a comment.
|
31
|
+
#
|
32
|
+
# Otherwise the format of this file "key = value". The value of
|
33
|
+
# any keys in this file may be constructed via the output of a command.
|
34
|
+
#
|
35
|
+
# For example:
|
36
|
+
#
|
37
|
+
# kernel = /boot/vmlinuz-`uname -r`
|
38
|
+
#
|
39
|
+
##
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
#
|
44
|
+
##
|
45
|
+
# Output directory for storing loopback images.
|
46
|
+
#
|
47
|
+
# If you choose to use loopback images, which are simple to manage but
|
48
|
+
# slower than LVM partitions, then specify a directory here and uncomment
|
49
|
+
# the line.
|
50
|
+
#
|
51
|
+
# New instances will be stored in subdirectories named after their
|
52
|
+
# hostnames.
|
53
|
+
#
|
54
|
+
##
|
55
|
+
<%= render_config :dir, '/home/xen' %>
|
56
|
+
#
|
57
|
+
|
58
|
+
#
|
59
|
+
##
|
60
|
+
#
|
61
|
+
# If you don't wish to use loopback images then you may specify an
|
62
|
+
# LVM volume group here instead
|
63
|
+
#
|
64
|
+
##
|
65
|
+
<%= render_config :lvm, 'skx-vg' %>
|
66
|
+
|
67
|
+
|
68
|
+
#
|
69
|
+
##
|
70
|
+
#
|
71
|
+
# Installation method.
|
72
|
+
#
|
73
|
+
# There are four distinct methods which you may to install a new copy
|
74
|
+
# of Linux to use in your Xen guest domain:
|
75
|
+
#
|
76
|
+
# - Installation via the debootstrap command.
|
77
|
+
# - Installation via the rpmstrap command.
|
78
|
+
# - Installation via the rinse command.
|
79
|
+
# - Installation by copying a directory containing a previous installation.
|
80
|
+
# - Installation by untarring a previously archived image.
|
81
|
+
#
|
82
|
+
# NOTE That if you use the "untar", or "copy" options you should ensure
|
83
|
+
# that the image you're left with matches the 'dist' setting later in
|
84
|
+
# this file.
|
85
|
+
#
|
86
|
+
#
|
87
|
+
##
|
88
|
+
#
|
89
|
+
#
|
90
|
+
# install-method = [ debootstrap | rinse | rpmstrap | copy | tar ]
|
91
|
+
#
|
92
|
+
#
|
93
|
+
<%= render_config :install__method, 'debootstrap' %>
|
94
|
+
#
|
95
|
+
# If you're using the "copy", or "tar" installation methods you must
|
96
|
+
# need to specify the source location to copy from, or the source
|
97
|
+
# .tar file to unpack.
|
98
|
+
#
|
99
|
+
# You may specify that with a line such as:
|
100
|
+
#
|
101
|
+
# install-source = /path/to/copy
|
102
|
+
# install-source = /some/path/img.tar
|
103
|
+
#
|
104
|
+
#
|
105
|
+
<%= render_config :install__source, '/some/path/img.tar' %>
|
106
|
+
|
107
|
+
#
|
108
|
+
##
|
109
|
+
# Command definitions.
|
110
|
+
##
|
111
|
+
#
|
112
|
+
# The "rinse", and "rpmstrap" commands are hardwired into
|
113
|
+
# the script, but if you wish to modify the commands which are executed
|
114
|
+
# when installing new systems by a "copy", "debootstrap", or "tar" method
|
115
|
+
# you can do so here:
|
116
|
+
#
|
117
|
+
# (This allows you to install from a .tar.bz file, rather than a plain
|
118
|
+
# tar file, use cdebootstrap, etc.)
|
119
|
+
#
|
120
|
+
# install-method=copy:
|
121
|
+
<%= render_config :copy__cmd, '/bin/cp -a $src/* $dest' %>
|
122
|
+
#
|
123
|
+
# install-method=debootstrap:
|
124
|
+
<%= render_config :debootstrap__cmd, '/usr/sbin/debootstrap' %>
|
125
|
+
#
|
126
|
+
# install-method=tar:
|
127
|
+
<%= render_config :tar__cmd, '/bin/tar --numeric-owner -xvf $src' %>
|
128
|
+
#
|
129
|
+
#
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
#
|
134
|
+
##
|
135
|
+
# Disk and Sizing options.
|
136
|
+
##
|
137
|
+
#
|
138
|
+
<%= render_config :size, '4Gb' %> # Disk image size.
|
139
|
+
<%= render_config :memory, '128Mb' %> # Memory size.
|
140
|
+
<%= render_config :swap, '256Mb' %> # Swap size.
|
141
|
+
<%= render_config :noswap, '1' %> # Don't use swap at all for the new system.
|
142
|
+
<%= render_config :fs, 'ext3' %> # Use the EXT3 filesystem for the disk image.
|
143
|
+
<%= render_config :dist, 'etch' %> # Default distribution to install.
|
144
|
+
<%= render_config :image, 'sparse' %> # Specify sparse vs. full disk images.
|
145
|
+
|
146
|
+
#
|
147
|
+
# Currently supported and tested distributions include:
|
148
|
+
#
|
149
|
+
# via Debootstrap:
|
150
|
+
#
|
151
|
+
# Debian:
|
152
|
+
# sid, sarge, etch, lenny.
|
153
|
+
#
|
154
|
+
# Ubuntu:
|
155
|
+
# edgy, feisty, dapper.
|
156
|
+
#
|
157
|
+
# via Rinse:
|
158
|
+
# centos-4, centos-5.
|
159
|
+
# fedora-core-4, fedora-core-5, fedora-core-6, fedora-core-7
|
160
|
+
#
|
161
|
+
#
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
##
|
166
|
+
# Networking setup values.
|
167
|
+
##
|
168
|
+
|
169
|
+
#
|
170
|
+
# Uncomment and adjust these network settings if you wish to give your
|
171
|
+
# new instances static IP addresses.
|
172
|
+
#
|
173
|
+
<%= render_config :gateway, '192.168.1.1' %>
|
174
|
+
<%= render_config :netmask, '255.255.255.0' %>
|
175
|
+
<%= render_config :broadcast, '192.168.1.255' %>
|
176
|
+
#
|
177
|
+
# Uncomment this if you wish the images to use DHCP
|
178
|
+
#
|
179
|
+
<%= render_config :dhcp, 1 %>
|
180
|
+
|
181
|
+
|
182
|
+
##
|
183
|
+
# Misc options
|
184
|
+
##
|
185
|
+
|
186
|
+
#
|
187
|
+
# Uncomment the following line if you wish to disable the caching
|
188
|
+
# of downloaded .deb files when using debootstrap to install images.
|
189
|
+
#
|
190
|
+
<%= render_config :cache, 'no' %>
|
191
|
+
#
|
192
|
+
|
193
|
+
#
|
194
|
+
# Uncomment the following line if you wish to interactively setup
|
195
|
+
# a new root password for images.
|
196
|
+
#
|
197
|
+
<%= render_config :passwd, 1 %>
|
198
|
+
|
199
|
+
#
|
200
|
+
# If you'd like all accounts on your host system which are not present
|
201
|
+
# on the guest system to be copied over then uncomment the following line.
|
202
|
+
#
|
203
|
+
<%= render_config :accounts, 1 %>
|
204
|
+
#
|
205
|
+
|
206
|
+
#
|
207
|
+
# Default kernel and ramdisk to use for the virtual servers
|
208
|
+
#
|
209
|
+
<%= render_config :kernel, '/boot/vmlinuz-`uname -r`' %>
|
210
|
+
<%= render_config :initrd, '/boot/initrd.img-`uname -r`' %>
|
211
|
+
|
212
|
+
#
|
213
|
+
# The architecture to use when using debootstrap, rinse, or rpmstrap.
|
214
|
+
#
|
215
|
+
# This is most useful on 64 bit host machines, for other systems it
|
216
|
+
# doesn't need to be used.
|
217
|
+
#
|
218
|
+
<%= render_config :arch, '[i386|amd64]' %>
|
219
|
+
#
|
220
|
+
|
221
|
+
#
|
222
|
+
# The default mirror for debootstrap to install Debian-derived distributions
|
223
|
+
#
|
224
|
+
# mirror = http://ftp.us.debian.org/debian/
|
225
|
+
|
226
|
+
#
|
227
|
+
# A mirror suitable for use when installing the Dapper release of Ubuntu.
|
228
|
+
#
|
229
|
+
# mirror = http://archive.ubuntu.com/ubuntu/
|
230
|
+
|
231
|
+
<%= render_config :mirror, 'http://archive.ubuntu.com/ubuntu/' %>
|
232
|
+
|
233
|
+
|
234
|
+
#
|
235
|
+
# If you like you could use per-distribution mirrors, which will
|
236
|
+
# be more useful if you're working in an environment where you want
|
237
|
+
# to regularly use multiple distributions:
|
238
|
+
#
|
239
|
+
# mirror_sid=http://ftp.us.debian.org/debian
|
240
|
+
# mirror_sarge=http://ftp.us.debian.org/debian
|
241
|
+
# mirror_etch=http://ftp.us.debian.org/debian
|
242
|
+
# mirror_dapper=http://archive.ubuntu.com/ubuntu
|
243
|
+
# mirror_edgy=http://archive.ubuntu.com/ubuntu
|
244
|
+
# mirror_feisty=http://archive.ubuntu.com/ubuntu
|
245
|
+
# mirror_gutsy=http://archive.ubuntu.com/ubuntu
|
246
|
+
|
247
|
+
|
248
|
+
#
|
249
|
+
# Filesystem options for the different filesystems we support.
|
250
|
+
#
|
251
|
+
<%= render_config :ext3_options, 'noatime,nodiratime,errors=remount-ro' %>
|
252
|
+
<%= render_config :ext2_options, 'noatime,nodiratime,errors=remount-ro' %>
|
253
|
+
<%= render_config :xfs_options, 'defaults' %>
|
254
|
+
<%= render_config :reiser_options, 'defaults' %>
|
255
|
+
|
256
|
+
#
|
257
|
+
# Uncomment if you wish newly created images to boot once they've been
|
258
|
+
# created.
|
259
|
+
#
|
260
|
+
<%= render_config :boot, '1' %>
|
261
|
+
|
262
|
+
|
263
|
+
#
|
264
|
+
# If you're using a newer version of the Xen guest kernel you will
|
265
|
+
# need to make sure that you use 'xvc0' for the guest serial device,
|
266
|
+
# and 'xvdX' instead of 'sdX' for serial devices.
|
267
|
+
#
|
268
|
+
# You may specify the things to use here:
|
269
|
+
#
|
270
|
+
# serial_device = tty1 #default
|
271
|
+
# serial_device = xvc0
|
272
|
+
#
|
273
|
+
# disk_device = sda #default
|
274
|
+
# disk_device = xvda
|
275
|
+
#
|
276
|
+
|
277
|
+
|
278
|
+
#
|
279
|
+
# Here we specify the output directory which the Xen configuration
|
280
|
+
# files will be written to, and the suffix to give them.
|
281
|
+
#
|
282
|
+
# Historically xen-tools have created configuration files in /etc/xen,
|
283
|
+
# and given each file the name $hostname.cfg. If you want to change
|
284
|
+
# that behaviour you may do so here.
|
285
|
+
#
|
286
|
+
#
|
287
|
+
<%= render_config :output, '/etc/xen' %>
|
288
|
+
<%= render_config :extension, '.cfg' %>
|
289
|
+
#
|