ruby-xen 0.0.3 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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/config.rb
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/templates/domu.cfg.erb
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
@@ -1,6 +1,4 @@
1
- = ruby-xen
2
-
3
- # Warning! Not ready yet - project started Sep 2008
1
+ = ruby-xen (born sep 2008 - still immature!)
4
2
 
5
3
  http://github.com/mbailey/ruby-xen
6
4
 
@@ -24,13 +22,19 @@ ruby-xen can also be used by ruby code or from irb.
24
22
 
25
23
  require 'rubygems'
26
24
  require 'ruby-xen'
25
+ include Xen
27
26
 
28
- slice = Xen::Slice.find(:example)
27
+ slice = Slice.find :example
29
28
  slice.running? # true
30
29
  slice.stop
31
30
  slice.running? # false
32
31
  slice.start
33
32
  slice.running? # true
33
+
34
+ slice.backups # => [#<Xen::Backup:0xb7a96520 @name=:example, @version="20090118">]
35
+ s.create_backup # => #<Xen::Backup:0xb7a922a4 @name=:example, @version="20090123">
36
+
37
+
34
38
 
35
39
  == REQUIREMENTS:
36
40
 
@@ -43,23 +47,25 @@ sudo gem install ruby-xen
43
47
 
44
48
  == LICENSE:
45
49
 
46
- ruby-xen is licenced under the GPL. This means that you can use it in commercial
47
- or open source applications. More details found here:
48
- http://www.gnu.org/licenses/gpl.html
50
+ (The MIT License)
49
51
 
50
- ruby-xen
51
- Copyright (C) 2008 Mike Bailey and Nick Marfleet
52
+ Copyright (c) 2008-2009 Mike Bailey
52
53
 
53
- This program is free software; you can redistribute it and/or
54
- modify it under the terms of the GNU General Public License
55
- as published by the Free Software Foundation; either version 2
56
- of the License, or (at your option) any later version.
54
+ Permission is hereby granted, free of charge, to any person obtaining
55
+ a copy of this software and associated documentation files (the
56
+ 'Software'), to deal in the Software without restriction, including
57
+ without limitation the rights to use, copy, modify, merge, publish,
58
+ distribute, sublicense, and/or sell copies of the Software, and to
59
+ permit persons to whom the Software is furnished to do so, subject to
60
+ the following conditions:
57
61
 
58
- This program is distributed in the hope that it will be useful,
59
- but WITHOUT ANY WARRANTY; without even the implied warranty of
60
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
61
- GNU General Public License for more details.
62
+ The above copyright notice and this permission notice shall be
63
+ included in all copies or substantial portions of the Software.
62
64
 
63
- You should have received a copy of the GNU General Public License
64
- along with this program; if not, write to the Free Software
65
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
65
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
66
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
67
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
68
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
69
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
70
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
71
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,3 +1,6 @@
1
+ class ValidationFailed < StandardError; end
2
+
3
+
1
4
  module Xen
2
5
  # General configuration for ruby-xen
3
6
 
@@ -17,10 +20,15 @@ module Xen
17
20
  CONFIG_FILE_EXTENSION = '.cfg'
18
21
 
19
22
  # Directory for backups of system images
20
- BACKUP_DIR='/var/xen_images'
23
+ BACKUP_DIR='/var/backups/xen'
21
24
 
22
- # FIle extension for backups
25
+ # File extension for backups
23
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
+
24
32
  end
25
33
 
26
34
  class Array #:nodoc:
@@ -41,14 +49,38 @@ end
41
49
  class Hash #:nodoc:
42
50
  # Converts a Hash into an array of key=val formatted strings
43
51
  #
44
- # puts { :nics => 2, :vcpus => 1, :memory => 64 }.to_args
52
+ # puts { :nics => 2, :vcpus => 1, :memory => 64, :dhcp => true }.to_args
45
53
  #
46
54
  # produces:
47
55
  #
48
- # ["memory=64", "nics=2", "vcpus=1"]
56
+ # ["--memory=64", "--nics=2", "--vcpus=1", "--dhcp"]
49
57
  def to_args
50
- collect{|k,v| "#{k}=#{v}"}
58
+ collect{|k,v| (v.to_s == 'true') ? "--#{k.to_s}" : "--#{k.to_s}=#{v}"}
59
+ end
60
+ end
61
+
62
+ class String
63
+
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
51
82
  end
83
+
52
84
  end
53
85
 
54
86
  module Xen
@@ -63,7 +95,7 @@ module Xen
63
95
  # i.object_id == s.instance.object_id # true
64
96
  #
65
97
  def slice
66
- d = Xen::Slice.new(name)
98
+ d = Xen::Slice.new(:name => name)
67
99
  # Insert the current object into the newly created Slice's attributes
68
100
  d.instance_variable_set("@#{self.class.to_s.sub('Xen::','').downcase}", self)
69
101
  d
@@ -71,10 +103,28 @@ module Xen
71
103
  end
72
104
  end
73
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
+
74
123
  require "#{File.dirname(__FILE__)}/xen/backup"
75
124
  require "#{File.dirname(__FILE__)}/xen/command"
76
- require "#{File.dirname(__FILE__)}/xen/config"
77
- require "#{File.dirname(__FILE__)}/xen/slice"
125
+ require "#{File.dirname(__FILE__)}/xen/config_file"
78
126
  require "#{File.dirname(__FILE__)}/xen/host"
79
- require "#{File.dirname(__FILE__)}/xen/image"
80
- require "#{File.dirname(__FILE__)}/xen/instance"
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"
@@ -37,4 +37,4 @@ on_poweroff = '<%= on_poweroff %>'
37
37
  on_reboot = '<%= on_reboot %>'
38
38
  on_crash = '<%= on_crash %>'
39
39
 
40
- extra = '<%= extra %>'
40
+ extra = '<%= extra %>'
@@ -0,0 +1,2 @@
1
+ ./proc
2
+ ./etc/udev/rules.d/70-persistent-net.rules
@@ -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
+ #