marabunta 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +22 -0
- data/README.md +36 -0
- data/Rakefile +133 -0
- data/examples/kvm-deploy.rb +28 -0
- data/jars/jna-3.0.9.jar +0 -0
- data/jars/libvirt-0.4.6.jar +0 -0
- data/lib/capistrano/recipes/deploy/strategy/marabunta.rb +18 -0
- data/lib/marabunta.rb +26 -0
- data/lib/marabunta/kvm.rb +57 -0
- data/lib/marabunta/kvm_domain.erb +36 -0
- data/lib/marabunta/marabunta.rb +25 -0
- data/marabunta.gemspec +83 -0
- data/spec/marabunta/kvm_spec.rb +61 -0
- data/spec/marabunta/marabunta_spec.rb +27 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +16 -0
- metadata +132 -0
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
== Marabunta
|
2
|
+
|
3
|
+
Copyright (c) 2010 David Calavera
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Marabunta
|
2
|
+
---------
|
3
|
+
|
4
|
+
Large scale cloud nodes distribution and deployment using Bittorrent, Capistrano and Libvirt.
|
5
|
+
|
6
|
+
How it works
|
7
|
+
------------
|
8
|
+
|
9
|
+
Marabunta relies on Murder, http://github.com/lg/murder, to distribute
|
10
|
+
the virtual disks to the cloud nodes and uses the Libvirt api to deploy
|
11
|
+
and start the images once they are distributed.
|
12
|
+
|
13
|
+
Currently Marabunta just supports deployments on Kvm but it can support as many hypervisors
|
14
|
+
as Libvirt supports.
|
15
|
+
|
16
|
+
It uses the libvirt jar library rather than ruby-libvirt because it's
|
17
|
+
more up to date so the tasks must be run with JRuby.
|
18
|
+
|
19
|
+
Configuration
|
20
|
+
-------------
|
21
|
+
|
22
|
+
The most simple way to use Marabunta is setting the deployment strategy
|
23
|
+
to `:marabunta`. It also requires to set the name of the `:hypervisor`.
|
24
|
+
|
25
|
+
There are some deployment configuration templates into the directory `examples`.
|
26
|
+
|
27
|
+
Marabunta can also be used without the deployment strategy. Follow the
|
28
|
+
steps that Murder requires for the manual usage and then run the
|
29
|
+
marabunta deploy task:
|
30
|
+
|
31
|
+
$ jruby -S cap marabunta:deploy tag="MURDER_TAG_NAME"
|
32
|
+
|
33
|
+
Copyright
|
34
|
+
---------
|
35
|
+
|
36
|
+
Copyright (c) 2010 David Calavera<calavera@apache.org>. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'date'
|
4
|
+
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Standard tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
task :default => :spec
|
47
|
+
|
48
|
+
require 'spec/rake/spectask'
|
49
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
50
|
+
spec.libs << 'lib' << 'spec'
|
51
|
+
spec.spec_opts = ['--options', 'spec/spec.opts']
|
52
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
53
|
+
end
|
54
|
+
|
55
|
+
require 'rake/rdoctask'
|
56
|
+
Rake::RDocTask.new do |rdoc|
|
57
|
+
rdoc.rdoc_dir = 'rdoc'
|
58
|
+
rdoc.title = "#{name} #{version}"
|
59
|
+
rdoc.rdoc_files.include('README*')
|
60
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Open an irb session preloaded with this library"
|
64
|
+
task :console do
|
65
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
66
|
+
end
|
67
|
+
|
68
|
+
#############################################################################
|
69
|
+
#
|
70
|
+
# Custom tasks (add your own tasks here)
|
71
|
+
#
|
72
|
+
#############################################################################
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
#############################################################################
|
77
|
+
#
|
78
|
+
# Packaging tasks
|
79
|
+
#
|
80
|
+
#############################################################################
|
81
|
+
|
82
|
+
task :release => :build do
|
83
|
+
unless `git branch` =~ /^\* master$/
|
84
|
+
puts "You must be on the master branch to release!"
|
85
|
+
exit!
|
86
|
+
end
|
87
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
88
|
+
sh "git tag v#{version}"
|
89
|
+
sh "git push origin master"
|
90
|
+
sh "git push --tags"
|
91
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
92
|
+
end
|
93
|
+
|
94
|
+
task :build => :gemspec do
|
95
|
+
sh "mkdir -p pkg"
|
96
|
+
sh "gem build #{gemspec_file}"
|
97
|
+
sh "mv #{gem_file} pkg"
|
98
|
+
end
|
99
|
+
|
100
|
+
task :gemspec => :validate do
|
101
|
+
# read spec file and split out manifest section
|
102
|
+
spec = File.read(gemspec_file)
|
103
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
104
|
+
|
105
|
+
# replace name version and date
|
106
|
+
replace_header(head, :name)
|
107
|
+
replace_header(head, :version)
|
108
|
+
replace_header(head, :date)
|
109
|
+
#comment this out if your rubyforge_project has a different name
|
110
|
+
replace_header(head, :rubyforge_project)
|
111
|
+
|
112
|
+
# determine file list from git ls-files
|
113
|
+
files = `git ls-files`.
|
114
|
+
split("\n").
|
115
|
+
sort.
|
116
|
+
reject { |file| file =~ /^\./ }.
|
117
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
118
|
+
map { |file| " #{file}" }.
|
119
|
+
join("\n")
|
120
|
+
|
121
|
+
# piece file back together and write
|
122
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
123
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
124
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
125
|
+
puts "Updated #{gemspec_file}"
|
126
|
+
end
|
127
|
+
|
128
|
+
task :validate do
|
129
|
+
unless Dir['VERSION*'].empty?
|
130
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
131
|
+
exit!
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'marabunta'
|
2
|
+
|
3
|
+
set :user, 'marabunta'
|
4
|
+
|
5
|
+
set :scm, :none
|
6
|
+
set :repository, '/tmp/disks'
|
7
|
+
|
8
|
+
#
|
9
|
+
# MURDER CONFIGURATION
|
10
|
+
#
|
11
|
+
set :remote_murder_path, '/var/lib/murder'
|
12
|
+
after 'deploy:setup', 'murder:distribute_files'
|
13
|
+
|
14
|
+
before 'murder:start_seeding', 'murder:start_tracker'
|
15
|
+
after 'murder:stop_seeding', 'murder:stop_tracker'
|
16
|
+
|
17
|
+
role :peers, 'localhost', '10.60.1.76'
|
18
|
+
role :seeder, 'localhost'
|
19
|
+
role :tracker, 'localhost'
|
20
|
+
|
21
|
+
set :default_destination_path, '/var/lib/virt'
|
22
|
+
set :default_seeder_files_path, '/tmp/disks'
|
23
|
+
|
24
|
+
#
|
25
|
+
# MARABUNTA CONFIGURATION
|
26
|
+
#
|
27
|
+
set :deploy_via, :marabunta
|
28
|
+
set :hypervisor, 'Kvm'
|
data/jars/jna-3.0.9.jar
ADDED
Binary file
|
Binary file
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'murder'
|
2
|
+
require 'capistrano/recipes/deploy/strategy/murder'
|
3
|
+
|
4
|
+
module Capistrano
|
5
|
+
module Recipes
|
6
|
+
module Deploy
|
7
|
+
module Strategy
|
8
|
+
class Marabunta < Murder
|
9
|
+
def upload(filename, remote_filename)
|
10
|
+
super(filename, remote_filename)
|
11
|
+
|
12
|
+
marabunta.deploy
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/marabunta.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Marabunta
|
2
|
+
VERSION = '0.1.0'
|
3
|
+
end
|
4
|
+
|
5
|
+
require File.expand_path('../marabunta/marabunta', __FILE__)
|
6
|
+
|
7
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
8
|
+
|
9
|
+
# currently just 'Kvm' is supported
|
10
|
+
set :hypervisor, ''
|
11
|
+
|
12
|
+
namespace :marabunta do
|
13
|
+
desc 'Deploy disks into the target machines'
|
14
|
+
task :deploy, :role => :seeder do
|
15
|
+
require_tag
|
16
|
+
|
17
|
+
# TODO: find a better way to know the disks to deploy
|
18
|
+
disks = capture("ls #{default_seeder_files_path}").chomp
|
19
|
+
|
20
|
+
destination_path = File.join(default_destination_path, tag)
|
21
|
+
disks = disks.split("\s+").map {|file| File.join(destination_path, file) }
|
22
|
+
|
23
|
+
Marabunta.deploy(roles[:peers].to_ary, hypervisor, disks)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Marabunta
|
2
|
+
module Hypervisor
|
3
|
+
require 'erb'
|
4
|
+
|
5
|
+
import org.libvirt.Connect
|
6
|
+
import java.util.UUID
|
7
|
+
|
8
|
+
class Kvm
|
9
|
+
attr_reader :address
|
10
|
+
|
11
|
+
TCP = "qemu+tcp://%s/system?no_tty"
|
12
|
+
|
13
|
+
def self.connect(address)
|
14
|
+
Kvm.new(address).connect
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(ip_address, protocol = TCP)
|
18
|
+
@address = protocol % ip_address
|
19
|
+
end
|
20
|
+
|
21
|
+
def connect
|
22
|
+
@connection = Connect.new(@address, false)
|
23
|
+
self
|
24
|
+
end
|
25
|
+
|
26
|
+
def disconnect
|
27
|
+
@connection.close
|
28
|
+
end
|
29
|
+
|
30
|
+
def deploy(disks_path)
|
31
|
+
disks_path.each do |disk|
|
32
|
+
domain = KvmDomain[disk]
|
33
|
+
|
34
|
+
@connection.domainDefineXML(domain).create
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class KvmDomain
|
40
|
+
def self.[](disk)
|
41
|
+
KvmDomain.new(disk).create
|
42
|
+
end
|
43
|
+
|
44
|
+
def initialize(disk)
|
45
|
+
@uuid = UUID.randomUUID.to_s
|
46
|
+
@name = File.basename(disk)
|
47
|
+
@volume_path = disk
|
48
|
+
# TODO: allow more configuration options
|
49
|
+
end
|
50
|
+
|
51
|
+
def create
|
52
|
+
template = ERB.new(File.read(File.expand_path('../kvm_domain.erb', __FILE__)))
|
53
|
+
template.result(binding)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
<domain type="kvm">
|
2
|
+
<name><%= @name %></name>
|
3
|
+
<uuid><%= @uuid %></uuid>
|
4
|
+
<memory>524288</memory>
|
5
|
+
<currentMemory>524288</currentMemory>
|
6
|
+
<vcpu>1</vcpu>
|
7
|
+
<os>
|
8
|
+
<type>hvm</type>
|
9
|
+
<boot dev="hd"/>
|
10
|
+
<loader>/usr/bin/qemu-kvm</loader>
|
11
|
+
</os>
|
12
|
+
<features>
|
13
|
+
<acpi/>
|
14
|
+
<apic/>
|
15
|
+
<pae/>
|
16
|
+
</features>"
|
17
|
+
<clock offset="utc"/>
|
18
|
+
<on_poweroff>destroy</on_poweroff>
|
19
|
+
<on_reboot>restart</on_reboot>
|
20
|
+
<on_crash>destroy</on_crash>
|
21
|
+
<devices>
|
22
|
+
<emulator>/usr/bin/qemu-kvm</emulator>
|
23
|
+
<input type="mouse" bus="ps2"/>
|
24
|
+
<!--graphics type='vnc' port='???' listen='???'/-->
|
25
|
+
<serial type="pty">
|
26
|
+
<target port="0"/>
|
27
|
+
</serial>
|
28
|
+
<console type="pty">
|
29
|
+
<target port="0"/>
|
30
|
+
</console>
|
31
|
+
<disk device="disk" type="file">
|
32
|
+
<target dev="hda" bus="ide"/>
|
33
|
+
<source file="<%= @volume_path %>"/>
|
34
|
+
</disk>
|
35
|
+
</devices>
|
36
|
+
</domain>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Marabunta
|
2
|
+
require 'java'
|
3
|
+
|
4
|
+
__JARS__ = File.expand_path('../../../jars', __FILE__)
|
5
|
+
require File.expand_path('jna-3.0.9.jar', __JARS__)
|
6
|
+
require File.expand_path('libvirt-0.4.6.jar', __JARS__)
|
7
|
+
require File.expand_path('../kvm', __FILE__)
|
8
|
+
|
9
|
+
|
10
|
+
def self.deploy(machines, hypervisor, disks_path)
|
11
|
+
unless Marabunta::Hypervisor.const_defined?(hypervisor)
|
12
|
+
raise "Unsupported hypervisor: #{hypervisor}"
|
13
|
+
end
|
14
|
+
|
15
|
+
hypervisor = Marabunta::Hypervisor.const_get(hypervisor)
|
16
|
+
|
17
|
+
machines.each do |machine|
|
18
|
+
connection = hypervisor.connect(machine)
|
19
|
+
|
20
|
+
connection.deploy(disks_path)
|
21
|
+
|
22
|
+
connection.disconnect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/marabunta.gemspec
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
+
## all of the comments. Some sections require modification, and others can
|
3
|
+
## be deleted if you don't need them. Once you understand the contents of
|
4
|
+
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
+
## You can find comprehensive Gem::Specification documentation, at
|
6
|
+
## http://docs.rubygems.org/read/chapter/20
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
+
s.rubygems_version = '1.3.5'
|
11
|
+
|
12
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
+
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
+
## the sub! line in the Rakefile
|
15
|
+
s.name = 'marabunta'
|
16
|
+
s.version = '0.1.0'
|
17
|
+
s.date = '2010-09-24'
|
18
|
+
s.rubyforge_project = 'marabunta'
|
19
|
+
|
20
|
+
## Make sure your summary is short. The description may be as long
|
21
|
+
## as you like.
|
22
|
+
s.summary = "Cloud nodes deployment using BitTorrent, Capistrano and Libvirt"
|
23
|
+
s.description = "Large scale distribution and deployment of virtual disks using BitTorrent, Capistrano and Libvirt"
|
24
|
+
|
25
|
+
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
+
## better to set the email to an email list or something. If you don't have
|
27
|
+
## a custom homepage, consider using your GitHub URL or the like.
|
28
|
+
s.authors = ["David Calavera"]
|
29
|
+
s.email = 'calavera@apache.org'
|
30
|
+
s.homepage = 'http://github.com/calavera/marabunta'
|
31
|
+
|
32
|
+
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
+
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
+
s.require_paths = %w[lib]
|
35
|
+
|
36
|
+
## If your gem includes any executables, list them here.
|
37
|
+
#s.executables = ["name"]
|
38
|
+
#s.default_executable = 'name'
|
39
|
+
|
40
|
+
## Specify any RDoc options here. You'll want to add your README and
|
41
|
+
## LICENSE files to the extra_rdoc_files list.
|
42
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
43
|
+
s.extra_rdoc_files = %w[README.md LICENSE]
|
44
|
+
|
45
|
+
## List your runtime dependencies here. Runtime dependencies are those
|
46
|
+
## that are needed for an end user to actually USE your code.
|
47
|
+
s.add_dependency('capistrano')
|
48
|
+
s.add_dependency('murder')
|
49
|
+
|
50
|
+
## List your development dependencies here. Development dependencies are
|
51
|
+
## those that are only needed during development
|
52
|
+
s.add_development_dependency('rspec')
|
53
|
+
s.add_development_dependency('mocha')
|
54
|
+
|
55
|
+
|
56
|
+
## Leave this section as-is. It will be automatically generated from the
|
57
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
58
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
59
|
+
# = MANIFEST =
|
60
|
+
s.files = %w[
|
61
|
+
LICENSE
|
62
|
+
README.md
|
63
|
+
Rakefile
|
64
|
+
examples/kvm-deploy.rb
|
65
|
+
jars/jna-3.0.9.jar
|
66
|
+
jars/libvirt-0.4.6.jar
|
67
|
+
lib/capistrano/recipes/deploy/strategy/marabunta.rb
|
68
|
+
lib/marabunta.rb
|
69
|
+
lib/marabunta/kvm.rb
|
70
|
+
lib/marabunta/kvm_domain.erb
|
71
|
+
lib/marabunta/marabunta.rb
|
72
|
+
marabunta.gemspec
|
73
|
+
spec/marabunta/kvm_spec.rb
|
74
|
+
spec/marabunta/marabunta_spec.rb
|
75
|
+
spec/spec.opts
|
76
|
+
spec/spec_helper.rb
|
77
|
+
]
|
78
|
+
# = MANIFEST =
|
79
|
+
|
80
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
81
|
+
## matches what you actually use.
|
82
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
|
83
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Marabunta::Hypervisor::Kvm do
|
4
|
+
before(:each) do
|
5
|
+
end
|
6
|
+
|
7
|
+
it "creates a new instance for each connection" do
|
8
|
+
org.libvirt.Connect.expects(:new).twice.returns(mock)
|
9
|
+
|
10
|
+
conn1 = Marabunta::Hypervisor::Kvm.connect('localhost')
|
11
|
+
conn2 = Marabunta::Hypervisor::Kvm.connect('localhost')
|
12
|
+
|
13
|
+
conn1.should_not == conn2
|
14
|
+
end
|
15
|
+
|
16
|
+
it "uses tcp connection by default" do
|
17
|
+
org.libvirt.Connect.expects(:new).returns(mock)
|
18
|
+
conn = Marabunta::Hypervisor::Kvm.connect('localhost')
|
19
|
+
|
20
|
+
conn.address.should == (Marabunta::Hypervisor::Kvm::TCP % 'localhost')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "creates a new domain for each disk" do
|
24
|
+
connection_mock = mock
|
25
|
+
domain_mock = mock
|
26
|
+
|
27
|
+
domain_mock.expects(:create).twice
|
28
|
+
connection_mock.expects(:domainDefineXML).twice.
|
29
|
+
returns(domain_mock)
|
30
|
+
|
31
|
+
org.libvirt.Connect.expects(:new).returns(connection_mock)
|
32
|
+
|
33
|
+
conn = Marabunta::Hypervisor::Kvm.connect('localhost')
|
34
|
+
conn.deploy(['disk1', 'disk2'])
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'domain' do
|
38
|
+
it "generates an uuid for each disk" do
|
39
|
+
domain1 = Marabunta::Hypervisor::KvmDomain.new('disk1').create
|
40
|
+
domain2 = Marabunta::Hypervisor::KvmDomain.new('disk2').create
|
41
|
+
|
42
|
+
xml_value(domain1, 'uuid').should_not == xml_value(domain2, 'uuid')
|
43
|
+
end
|
44
|
+
|
45
|
+
it "uses the basename of the disk as domain name" do
|
46
|
+
domain = Marabunta::Hypervisor::KvmDomain.new('/tmp/disk').create
|
47
|
+
|
48
|
+
xml_value(domain, 'name').should == 'disk'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "uses the full disk path as volume path" do
|
52
|
+
domain = Marabunta::Hypervisor::KvmDomain.new('/tmp/disk').create
|
53
|
+
|
54
|
+
domain[%r{<source file="([^"]+)"}, 1].should == '/tmp/disk'
|
55
|
+
end
|
56
|
+
|
57
|
+
def xml_value(xml, node)
|
58
|
+
xml[%r{<(#{node})>(.+)</\1>}, 2]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
2
|
+
|
3
|
+
describe Marabunta do
|
4
|
+
it "does nothing if the hypervisor is not supported" do
|
5
|
+
lambda {
|
6
|
+
Marabunta.deploy([], 'Xen', '/tmp')
|
7
|
+
}.should raise_error
|
8
|
+
end
|
9
|
+
|
10
|
+
it "loads the hypervisor if it's supported" do
|
11
|
+
lambda {
|
12
|
+
Marabunta.deploy([], 'Kvm', '/tmp')
|
13
|
+
}.should_not raise_error
|
14
|
+
end
|
15
|
+
|
16
|
+
it "connects with each machine's hypervisor" do
|
17
|
+
kvm = mock
|
18
|
+
kvm.expects(:deploy)
|
19
|
+
kvm.expects(:disconnect)
|
20
|
+
|
21
|
+
Marabunta::Hypervisor::Kvm.expects(:connect).
|
22
|
+
with('localhost').
|
23
|
+
returns(kvm)
|
24
|
+
|
25
|
+
Marabunta.deploy(['localhost'], 'Kvm', '/tmp')
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
begin
|
3
|
+
require 'spec'
|
4
|
+
rescue LoadError
|
5
|
+
gem 'rspec'
|
6
|
+
require 'spec'
|
7
|
+
end
|
8
|
+
|
9
|
+
$:.unshift(File.dirname(__FILE__) + '/../lib')
|
10
|
+
|
11
|
+
require 'marabunta/marabunta'
|
12
|
+
require 'mocha'
|
13
|
+
|
14
|
+
Spec::Runner.configure do |config|
|
15
|
+
config.mock_with :mocha
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: marabunta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- David Calavera
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-24 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: capistrano
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :runtime
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: murder
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :runtime
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: mocha
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
type: :development
|
71
|
+
version_requirements: *id004
|
72
|
+
description: Large scale distribution and deployment of virtual disks using BitTorrent, Capistrano and Libvirt
|
73
|
+
email: calavera@apache.org
|
74
|
+
executables: []
|
75
|
+
|
76
|
+
extensions: []
|
77
|
+
|
78
|
+
extra_rdoc_files:
|
79
|
+
- README.md
|
80
|
+
- LICENSE
|
81
|
+
files:
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- examples/kvm-deploy.rb
|
86
|
+
- jars/jna-3.0.9.jar
|
87
|
+
- jars/libvirt-0.4.6.jar
|
88
|
+
- lib/capistrano/recipes/deploy/strategy/marabunta.rb
|
89
|
+
- lib/marabunta.rb
|
90
|
+
- lib/marabunta/kvm.rb
|
91
|
+
- lib/marabunta/kvm_domain.erb
|
92
|
+
- lib/marabunta/marabunta.rb
|
93
|
+
- marabunta.gemspec
|
94
|
+
- spec/marabunta/kvm_spec.rb
|
95
|
+
- spec/marabunta/marabunta_spec.rb
|
96
|
+
- spec/spec.opts
|
97
|
+
- spec/spec_helper.rb
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://github.com/calavera/marabunta
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options:
|
104
|
+
- --charset=UTF-8
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
none: false
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
segments:
|
121
|
+
- 0
|
122
|
+
version: "0"
|
123
|
+
requirements: []
|
124
|
+
|
125
|
+
rubyforge_project: marabunta
|
126
|
+
rubygems_version: 1.3.7
|
127
|
+
signing_key:
|
128
|
+
specification_version: 2
|
129
|
+
summary: Cloud nodes deployment using BitTorrent, Capistrano and Libvirt
|
130
|
+
test_files:
|
131
|
+
- spec/marabunta/kvm_spec.rb
|
132
|
+
- spec/marabunta/marabunta_spec.rb
|