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.
- data/Manifest.txt +6 -4
- data/README.rdoc +26 -20
- data/lib/ruby-xen.rb +60 -10
- data/lib/templates/domu.cfg.erb +1 -1
- data/lib/templates/exclude_from_backups +2 -0
- data/lib/templates/xen-tools.conf.erb +289 -0
- data/lib/xen/backup.rb +71 -33
- data/lib/xen/command.rb +94 -60
- data/lib/xen/config_file.rb +159 -0
- data/lib/xen/host.rb +59 -5
- data/lib/xen/instance.rb +53 -51
- data/lib/xen/lvm.rb +40 -0
- data/lib/xen/slice.rb +118 -65
- data/lib/xen/xen_tools_conf.rb +56 -0
- data/test/test_ruby-xen.rb +2 -2
- metadata +29 -7
- data/lib/xen/config.rb +0 -146
- data/lib/xen/image.rb +0 -12
data/lib/xen/config.rb
DELETED
@@ -1,146 +0,0 @@
|
|
1
|
-
require 'erb'
|
2
|
-
|
3
|
-
class Xen::Config
|
4
|
-
# The config files for each Xen domU
|
5
|
-
include Xen::Parentable
|
6
|
-
attr_accessor :name, :kernel, :ramdisk, :memory, :root, :vbds, :vifs, :on_poweroff, :on_reboot, :on_crash, :extra
|
7
|
-
|
8
|
-
def initialize(*args)
|
9
|
-
options = args.extract_options!
|
10
|
-
@name = args.first
|
11
|
-
@kernel = options[:kernel]
|
12
|
-
@ramdisk = options[:ramdisk]
|
13
|
-
@memory = options[:memory]
|
14
|
-
@root = options[:root]
|
15
|
-
@vbds = options[:vbds]
|
16
|
-
@vifs = options[:vifs]
|
17
|
-
@on_poweroff = options[:on_poweroff]
|
18
|
-
@on_reboot = options[:on_reboot]
|
19
|
-
@on_crash = options[:on_crash]
|
20
|
-
@extra = options[:extra]
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.find(*args)
|
24
|
-
options = args.extract_options!
|
25
|
-
case args.first
|
26
|
-
when :all then all
|
27
|
-
else find_by_name(args.first)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.all
|
32
|
-
config_files = Dir.glob("#{Xen::XEN_DOMU_CONFIG_DIR}/*#{Xen::CONFIG_FILE_EXTENSION}")
|
33
|
-
config_files.collect do |filename|
|
34
|
-
create_from_config_file(File.read(filename))
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def self.find_by_name(name)
|
39
|
-
return new('Domain-0') if name == 'Domain-0'
|
40
|
-
filename = "#{Xen::XEN_DOMU_CONFIG_DIR}/#{name}#{Xen::CONFIG_FILE_EXTENSION}"
|
41
|
-
create_from_config_file(File.read(filename)) if File.exists?(filename)
|
42
|
-
end
|
43
|
-
|
44
|
-
def config_file
|
45
|
-
"#{Xen::XEN_DOMU_CONFIG_DIR}/#{name}#{Xen::CONFIG_FILE_EXTENSION}"
|
46
|
-
end
|
47
|
-
|
48
|
-
def auto_file
|
49
|
-
"#{Xen::XEN_DOMU_CONFIG_DIR}/auto/#{name}#{Xen::CONFIG_FILE_EXTENSION}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def updated_at
|
53
|
-
File.mtime(config_file)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Set to true|false to enable|disable autostart of slice
|
57
|
-
def auto=(value)
|
58
|
-
filename = File.basename(config_file)
|
59
|
-
if value == true
|
60
|
-
File.symlink("../#{filename}", auto_file)
|
61
|
-
else
|
62
|
-
File.unlink(auto_file)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
# Returns true|false depending on whether slice is set to start automatically
|
67
|
-
def auto
|
68
|
-
File.symlink?(auto_file) && File.expand_path(File.readlink(auto_file), File.dirname(auto_file)) == config_file
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.create_from_config_file(config)
|
72
|
-
name, kernel, ramdisk, memory, root, disk, vif, on_poweroff, on_reboot, on_crash, extra = nil
|
73
|
-
eval(config)
|
74
|
-
vifs = Array(vif).collect { |v| Xen::Vif.from_str(v) }
|
75
|
-
vbds = Array(disk).collect { |d| Xen::Vbd.from_str(d) }
|
76
|
-
new(name, :disk => disk, :kernel => kernel, :ramdisk => ramdisk, :memory => memory, :root => root, :vbds => vbds, :vifs => vifs, :on_poweroff => on_poweroff, :on_reboot => on_reboot, :on_crash => on_crash, :extra => extra)
|
77
|
-
end
|
78
|
-
|
79
|
-
def save
|
80
|
-
template = ERB.new IO.read(Xen::TEMPLATE_DIR + '/domu.cfg.erb')
|
81
|
-
File.open(config_file, 'w'){ |f| f.write template.result(binding) }
|
82
|
-
end
|
83
|
-
|
84
|
-
end
|
85
|
-
|
86
|
-
|
87
|
-
# Virtual Network Interface
|
88
|
-
#
|
89
|
-
# http://wiki.xensource.com/xenwiki/XenNetworking
|
90
|
-
#
|
91
|
-
class Xen::Vif
|
92
|
-
attr_accessor :ip, :mac, :bridge, :vifname
|
93
|
-
def initialize(*args)
|
94
|
-
options = args.extract_options!
|
95
|
-
@ip = options[:ip]
|
96
|
-
@mac = options[:mac]
|
97
|
-
@bridge = options[:bridge]
|
98
|
-
@vifname = options[:vifname]
|
99
|
-
end
|
100
|
-
|
101
|
-
def self.from_str(value)
|
102
|
-
options = value.scan(/(\w+)=([^,]+)/).inject({}){ |m, (k, v)| m[k.to_sym] = v; m }
|
103
|
-
new(options)
|
104
|
-
end
|
105
|
-
|
106
|
-
def to_str
|
107
|
-
%w(ip mac bridge vifname).collect { |key|
|
108
|
-
"#{key}=#{instance_variable_get('@' + key)}" if !instance_variable_get('@'+key).nil?
|
109
|
-
}.compact.join(',')
|
110
|
-
end
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
# Virtual Block Device
|
115
|
-
#
|
116
|
-
# We're only supporting Logical Volumes. No loopback devices.
|
117
|
-
#
|
118
|
-
# http://wiki.xensource.com/xenwiki/XenStorage
|
119
|
-
#
|
120
|
-
# == Example
|
121
|
-
#
|
122
|
-
# disk = [ 'phy:xendisks/example-disk,sda1,w',
|
123
|
-
# 'phy:xendisks/example-swap,sda2,w',
|
124
|
-
# 'phy:assets/example-assets,sdb1,w' ]
|
125
|
-
class Xen::Vbd
|
126
|
-
attr_accessor :name, :vg, :domu, :mode
|
127
|
-
def initialize(name, vg, domu, mode='w')
|
128
|
-
@name, @vg, @domu, @mode = name, vg, domu, mode
|
129
|
-
end
|
130
|
-
|
131
|
-
def self.from_str(value)
|
132
|
-
dom0, domu, mode = value.split(',')
|
133
|
-
vg, name = dom0.split(/[\/:]/).slice(-2, 2)
|
134
|
-
new(name, vg, domu, mode)
|
135
|
-
end
|
136
|
-
|
137
|
-
def size
|
138
|
-
Xen::Command.lv_size(@vg, @name)
|
139
|
-
end
|
140
|
-
|
141
|
-
def to_str
|
142
|
-
"phy:#{vg}/#{lv},#{domu},#{mode}"
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
|