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 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.
@@ -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 somre problem, feel free to create a new issue.
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
@@ -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
@@ -1,10 +1,17 @@
1
1
  module Libvirt
2
2
  module Ruby
3
3
  module Connect
4
- def self.dispatcher(method, args = [])
5
- return_type = args.delete(args.last)
6
- attach_function ("virConnect" + method.to_s), ("virConnect" + method.to_s), args, return_type
7
- send(("virConnect" + method.to_s), args)
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
@@ -1,10 +1,17 @@
1
1
  module Libvirt
2
2
  module Ruby
3
3
  module Domain
4
- def self.dispatcher(method, args = [])
5
- return_type = args.delete(args.last)
6
- attach_function ("virDomain" + method.to_s), ("virDomain" + method.to_s), args, return_type
7
- send(("virDomain" + method.to_s), args)
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
@@ -0,0 +1,8 @@
1
+ module Libvirt
2
+ module Ruby
3
+ module Exceptions
4
+ autoload :MissingLib, 'libvirt-ruby/exceptions/missing_lib'
5
+ autoload :InvalidFunction, 'libvirt-ruby/exceptions/invalid_function'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,11 @@
1
+ module Libvirt
2
+ module Ruby
3
+ module Exceptions
4
+ class InvalidFunction < StandardError
5
+ def initialize(function)
6
+ super("The function '#{function}' could not be found. Is it correct?")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Libvirt
2
+ module Ruby
3
+ module Exceptions
4
+ class MissingLib < StandardError
5
+ def initialize
6
+ super("The libvirt C library could not be loaded. Is it properly installed?")
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,10 +1,17 @@
1
1
  module Libvirt
2
2
  module Ruby
3
3
  module Network
4
- def self.dispatcher(method, args = [])
5
- return_type = args.delete(args.last)
6
- attach_function ("virNetwork" + method.to_s), ("virNetwork" + method.to_s), args, return_type
7
- send(("virNetwork" + method.to_s), args)
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
- def self.dispatcher(method, args = [])
5
- return_type = args.delete(args.last)
6
- attach_function ("virStoragePool" + method.to_s), ("virStoragePool" + method.to_s), args, return_type
7
- send(("virStoragePool" + method.to_s), args)
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
- def self.dispatcher(method, args = [])
5
- return_type = args.delete(args.last)
6
- attach_function ("virStorageVol" + method.to_s), ("virStorageVol" + method.to_s), args, return_type
7
- send(("virStorageVol" + method.to_s), args)
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
@@ -1,5 +1,5 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -21,4 +21,5 @@ Gem::Specification.new do |s|
21
21
  s.add_runtime_dependency "ffi"
22
22
  s.add_development_dependency "rake"
23
23
  s.add_development_dependency "rspec"
24
+ s.add_development_dependency "fakefs"
24
25
  end
@@ -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
- before :each do
8
- connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
9
- connect.stub(:send).with("virConnectClose", [])
10
- end
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
- after :each do
13
- connect.dispatcher('Close', [:int])
14
- end
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
- it "should attach it as a binding for C's function" do
17
- connect.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
21
+ it "should call the new attached method" do
22
+ connect.should_receive(:send).with("virConnectClose", [])
23
+ end
18
24
  end
19
25
 
20
- it "should call the new attached method" do
21
- connect.should_receive(:send).with("virConnectClose", [])
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
- before :each do
8
- domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
9
- domain.stub(:send).with("virDomainCreate", [])
10
- end
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
- after :each do
13
- domain.dispatcher('Create', [:int])
14
- end
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
- it "should attach it as a binding for C's function" do
17
- domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
21
+ it "should call the new attached method" do
22
+ domain.should_receive(:send).with("virDomainCreate", [])
23
+ end
18
24
  end
19
25
 
20
- it "should call the new attached method" do
21
- domain.should_receive(:send).with("virDomainCreate", [])
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
- before :each do
8
- network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
9
- network.stub(:send).with("virNetworkRef", [])
10
- end
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
- after :each do
13
- network.dispatcher('Ref', [:int])
14
- end
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
- it "should attach it as a binding for C's function" do
17
- network.should_receive(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
21
+ it "should call the new attached method" do
22
+ network.should_receive(:send).with("virNetworkRef", [])
23
+ end
18
24
  end
19
25
 
20
- it "should call the new attached method" do
21
- network.should_receive(:send).with("virNetworkRef", [])
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
- before :each do
8
- storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
9
- storage_pool.stub(:send).with("virStoragePoolRefresh", [])
10
- end
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
- after :each do
13
- storage_pool.dispatcher('Refresh', [:int])
14
- end
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
- it "should attach it as a binding for C's function" do
17
- storage_pool.should_receive(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
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
- it "should call the new attached method" do
21
- storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
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
- before :each do
8
- storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
9
- storage_vol.stub(:send).with("virStorageVolResize", [])
10
- end
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
- after :each do
13
- storage_vol.dispatcher('Resize', [:int])
14
- end
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
- it "should attach it as a binding for C's function" do
17
- storage_vol.should_receive(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
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
- it "should call the new attached method" do
21
- storage_vol.should_receive(:send).with("virStorageVolResize", [])
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
@@ -1,4 +1,5 @@
1
1
  require "rubygems"
2
2
  require "rspec"
3
+ require "ffi"
3
4
 
4
- Dir.glob(File.dirname(__FILE__) + "/../lib/libvirt-ruby/**/*.rb").each { |file| require file }
5
+ require File.dirname(__FILE__) + "/../lib/libvirt-ruby.rb"
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.1
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-22 00:00:00.000000000 Z
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: &10883940 !ruby/object:Gem::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: *10883940
24
+ version_requirements: *12651960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &10898920 !ruby/object:Gem::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: *10898920
35
+ version_requirements: *12651440
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &10895140 !ruby/object:Gem::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: *10895140
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