libvirt-ruby 0.0.1 → 0.0.2
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/LICENSE +20 -0
- data/README.rdoc +22 -3
- data/lib/libvirt-ruby.rb +3 -5
- data/lib/libvirt-ruby/connect.rb +11 -4
- data/lib/libvirt-ruby/domain.rb +11 -4
- data/lib/libvirt-ruby/exceptions.rb +8 -0
- data/lib/libvirt-ruby/exceptions/invalid_function.rb +11 -0
- data/lib/libvirt-ruby/exceptions/missing_lib.rb +11 -0
- data/lib/libvirt-ruby/network.rb +11 -4
- data/lib/libvirt-ruby/storage_pool.rb +11 -4
- data/lib/libvirt-ruby/storage_vol.rb +11 -4
- data/lib/libvirt-ruby/util.rb +15 -0
- data/lib/libvirt-ruby/version.rb +1 -1
- data/libvirt-ruby.gemspec +1 -0
- data/spec/libvirt-ruby/connect_spec.rb +19 -11
- data/spec/libvirt-ruby/domain_spec.rb +19 -11
- data/spec/libvirt-ruby/network_spec.rb +19 -11
- data/spec/libvirt-ruby/storage_pool_spec.rb +19 -11
- data/spec/libvirt-ruby/storage_vol_spec.rb +19 -11
- data/spec/spec_helper.rb +2 -1
- metadata +24 -8
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
(The MIT License)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
'Software'), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
17
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
18
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
19
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
20
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
CHANGED
@@ -6,18 +6,37 @@ Rails gem to map functions from libvirt's library to ruby.
|
|
6
6
|
|
7
7
|
gem install libvirt-ruby
|
8
8
|
|
9
|
+
== Dependencies
|
10
|
+
|
11
|
+
This gem has as a dependencie the libvirt package. Google it and u will find how to install it on your distro.
|
12
|
+
|
9
13
|
== Usage
|
10
14
|
|
11
15
|
You should one of the classes defined and call method dispatcher passing parameters:
|
12
|
-
first -> the method just like the one from Libvirt in C as a string
|
16
|
+
first -> the method just like the one from Libvirt in C as a string except the vir and the name of the Class just like 'Close' from 'virConnectClose'
|
13
17
|
second -> the args of the function in C in the same order
|
14
18
|
|
15
19
|
Your second parameter must be an array where the last value is a symbol of what the function should return.
|
16
20
|
|
17
21
|
== Experimental
|
18
22
|
|
19
|
-
This Gem still experimental, so if you have
|
23
|
+
This Gem still experimental, so if you have some problem, feel free to create a new issue.
|
24
|
+
|
25
|
+
== Tests
|
26
|
+
|
27
|
+
The test have been made only on Debian Squeeze. When it got a bit larger, i will test it for another distros.
|
28
|
+
Give it a try in another distro and let me know if it works.
|
20
29
|
|
21
30
|
== Future
|
22
31
|
|
23
|
-
Add Support for a ton of thigs. =D
|
32
|
+
Add Support for a ton of thigs. =D
|
33
|
+
Improve a lot of things:
|
34
|
+
* Use method missing and deprecate dispatcher.
|
35
|
+
* Find a way to make the test suit pass without the lib. By now it only works if u have it installed.
|
36
|
+
* Create more Exceptions for another type of errors.
|
37
|
+
* Create pages on Wiki teaching how to isntall libvirt on each distro.
|
38
|
+
...
|
39
|
+
|
40
|
+
== Contribute
|
41
|
+
|
42
|
+
Fork the project and send me a Pull Request. =D
|
data/lib/libvirt-ruby.rb
CHANGED
@@ -1,16 +1,14 @@
|
|
1
|
-
require "ffi"
|
2
1
|
require "libvirt-ruby/version"
|
2
|
+
require "ffi"
|
3
3
|
|
4
4
|
module Libvirt
|
5
5
|
module Ruby
|
6
|
-
|
7
|
-
extend FFI::Library
|
8
|
-
ffi_lib "libvirt"
|
9
|
-
|
10
6
|
autoload :Connect, 'libvirt-ruby/connect'
|
11
7
|
autoload :Domain, 'libvirt-ruby/domain'
|
8
|
+
autoload :Exceptions, 'libvirt-ruby/exceptions'
|
12
9
|
autoload :Network, 'libvirt-ruby/network'
|
13
10
|
autoload :StoragePool, 'libvirt-ruby/storage_pool'
|
14
11
|
autoload :StorageVol, 'libvirt-ruby/storage_vol'
|
12
|
+
autoload :Util, 'libvirt-ruby/util'
|
15
13
|
end
|
16
14
|
end
|
data/lib/libvirt-ruby/connect.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
module Libvirt
|
2
2
|
module Ruby
|
3
3
|
module Connect
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
extend Libvirt::Ruby::Util
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
begin
|
8
|
+
ffi_lib "libvirt.so.0"
|
9
|
+
rescue LoadError
|
10
|
+
raise Libvirt::Ruby::Exceptions::MissingLib
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.klass
|
14
|
+
"virConnect"
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
data/lib/libvirt-ruby/domain.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
module Libvirt
|
2
2
|
module Ruby
|
3
3
|
module Domain
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
extend Libvirt::Ruby::Util
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
begin
|
8
|
+
ffi_lib "libvirt.so.0"
|
9
|
+
rescue LoadError
|
10
|
+
raise Libvirt::Ruby::Exceptions::MissingLib
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.klass
|
14
|
+
"virDomain"
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
data/lib/libvirt-ruby/network.rb
CHANGED
@@ -1,10 +1,17 @@
|
|
1
1
|
module Libvirt
|
2
2
|
module Ruby
|
3
3
|
module Network
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
extend Libvirt::Ruby::Util
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
begin
|
8
|
+
ffi_lib "libvirt.so.0"
|
9
|
+
rescue LoadError
|
10
|
+
raise Libvirt::Ruby::Exceptions::MissingLib
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.klass
|
14
|
+
"virNetwork"
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
module Libvirt
|
2
2
|
module Ruby
|
3
3
|
module StoragePool
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
extend Libvirt::Ruby::Util
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
begin
|
8
|
+
ffi_lib "libvirt.so.0"
|
9
|
+
rescue LoadError
|
10
|
+
raise Libvirt::Ruby::Exceptions::MissingLib
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.klass
|
14
|
+
"virStoragePool"
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
module Libvirt
|
2
2
|
module Ruby
|
3
3
|
module StorageVol
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
extend Libvirt::Ruby::Util
|
5
|
+
extend FFI::Library
|
6
|
+
|
7
|
+
begin
|
8
|
+
ffi_lib "libvirt.so.0"
|
9
|
+
rescue LoadError
|
10
|
+
raise Libvirt::Ruby::Exceptions::MissingLib
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.klass
|
14
|
+
"virStorageVol"
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Ruby
|
3
|
+
module Util
|
4
|
+
def dispatcher(method, args = [])
|
5
|
+
begin
|
6
|
+
return_type = args.delete(args.last)
|
7
|
+
attach_function (self.klass + method.to_s), (self.klass + method.to_s), args, return_type
|
8
|
+
send((self.klass + method.to_s), args)
|
9
|
+
rescue FFI::NotFoundError
|
10
|
+
raise Libvirt::Ruby::Exceptions::InvalidFunction.new(self.klass + method.to_s)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/libvirt-ruby/version.rb
CHANGED
data/libvirt-ruby.gemspec
CHANGED
@@ -4,21 +4,29 @@ describe Libvirt::Ruby::Connect do
|
|
4
4
|
let(:connect) { Libvirt::Ruby::Connect }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
context "with a valid libvirt function" do
|
8
|
+
before :each do
|
9
|
+
connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
10
|
+
connect.stub(:send).with("virConnectClose", [])
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
after :each do
|
14
|
+
connect.dispatcher('Close', [:int])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should attach it as a binding for C's function" do
|
18
|
+
connect.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
it "should call the new attached method" do
|
22
|
+
connect.should_receive(:send).with("virConnectClose", [])
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
context "with an invalid libvirt function" do
|
27
|
+
it "should return an invalid function message" do
|
28
|
+
lambda { connect.dispatcher('Abc', [:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -4,21 +4,29 @@ describe Libvirt::Ruby::Domain do
|
|
4
4
|
let(:domain) { Libvirt::Ruby::Domain }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
context "with a valid libvirt function" do
|
8
|
+
before :each do
|
9
|
+
domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
10
|
+
domain.stub(:send).with("virDomainCreate", [])
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
after :each do
|
14
|
+
domain.dispatcher('Create', [:int])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should attach it as a binding for C's function" do
|
18
|
+
domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
it "should call the new attached method" do
|
22
|
+
domain.should_receive(:send).with("virDomainCreate", [])
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
context "with an invalid libvirt function" do
|
27
|
+
it "should return an invalid function message" do
|
28
|
+
lambda { domain.dispatcher('Abc', [:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -4,21 +4,29 @@ describe Libvirt::Ruby::Network do
|
|
4
4
|
let(:network) { Libvirt::Ruby::Network }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
context "with a valid libvirt function" do
|
8
|
+
before :each do
|
9
|
+
network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
10
|
+
network.stub(:send).with("virNetworkRef", [])
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
after :each do
|
14
|
+
network.dispatcher('Ref', [:int])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should attach it as a binding for C's function" do
|
18
|
+
network.should_receive(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
it "should call the new attached method" do
|
22
|
+
network.should_receive(:send).with("virNetworkRef", [])
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
context "with an invalid libvirt function" do
|
27
|
+
it "should return an invalid function message" do
|
28
|
+
lambda { network.dispatcher('Abc', [:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -4,21 +4,29 @@ describe Libvirt::Ruby::StoragePool do
|
|
4
4
|
let(:storage_pool) { Libvirt::Ruby::StoragePool }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
context "with a valid libvirt function" do
|
8
|
+
before :each do
|
9
|
+
storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
10
|
+
storage_pool.stub(:send).with("virStoragePoolRefresh", [])
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
after :each do
|
14
|
+
storage_pool.dispatcher('Refresh', [:int])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should attach it as a binding for C's function" do
|
18
|
+
storage_pool.should_receive(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
it "should call the new attached method" do
|
22
|
+
storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
context "with an invalid libvirt function" do
|
27
|
+
it "should return an invalid function message" do
|
28
|
+
lambda { storage_pool.dispatcher('Abc', [:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
@@ -4,21 +4,29 @@ describe Libvirt::Ruby::StorageVol do
|
|
4
4
|
let(:storage_vol) { Libvirt::Ruby::StorageVol }
|
5
5
|
|
6
6
|
context "when calling method #dispatcher" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
context "with a valid libvirt function" do
|
8
|
+
before :each do
|
9
|
+
storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
10
|
+
storage_vol.stub(:send).with("virStorageVolResize", [])
|
11
|
+
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
13
|
+
after :each do
|
14
|
+
storage_vol.dispatcher('Resize', [:int])
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should attach it as a binding for C's function" do
|
18
|
+
storage_vol.should_receive(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
|
19
|
+
end
|
15
20
|
|
16
|
-
|
17
|
-
|
21
|
+
it "should call the new attached method" do
|
22
|
+
storage_vol.should_receive(:send).with("virStorageVolResize", [])
|
23
|
+
end
|
18
24
|
end
|
19
25
|
|
20
|
-
|
21
|
-
|
26
|
+
context "with an invalid libvirt function" do
|
27
|
+
it "should return an invalid function message" do
|
28
|
+
lambda { storage_vol.dispatcher('Abc', [:int]) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
|
29
|
+
end
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libvirt-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-02-
|
12
|
+
date: 2012-02-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement: &
|
16
|
+
requirement: &12651960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *12651960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &12651440 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *12651440
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &12650440 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,18 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *12650440
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: fakefs
|
49
|
+
requirement: &12649920 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *12649920
|
47
58
|
description: Access Libvirt's C Library through ruby classes and methods
|
48
59
|
email: plribeiro3000@gmail.com
|
49
60
|
executables: []
|
@@ -54,14 +65,19 @@ files:
|
|
54
65
|
- .rspec
|
55
66
|
- .rvmrc
|
56
67
|
- Gemfile
|
68
|
+
- LICENSE
|
57
69
|
- README.rdoc
|
58
70
|
- Rakefile
|
59
71
|
- lib/libvirt-ruby.rb
|
60
72
|
- lib/libvirt-ruby/connect.rb
|
61
73
|
- lib/libvirt-ruby/domain.rb
|
74
|
+
- lib/libvirt-ruby/exceptions.rb
|
75
|
+
- lib/libvirt-ruby/exceptions/invalid_function.rb
|
76
|
+
- lib/libvirt-ruby/exceptions/missing_lib.rb
|
62
77
|
- lib/libvirt-ruby/network.rb
|
63
78
|
- lib/libvirt-ruby/storage_pool.rb
|
64
79
|
- lib/libvirt-ruby/storage_vol.rb
|
80
|
+
- lib/libvirt-ruby/util.rb
|
65
81
|
- lib/libvirt-ruby/version.rb
|
66
82
|
- libvirt-ruby.gemspec
|
67
83
|
- spec/libvirt-ruby/connect_spec.rb
|