libvirt-ruby 0.0.2 → 0.0.3

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/README.rdoc CHANGED
@@ -1,4 +1,4 @@
1
- = Libvirt-Ruby {<img src="https://secure.travis-ci.org/plribeiro3000/libvirt-ruby.png" />}[http://travis-ci.org/plribeiro3000/libvirt-ruby]
1
+ = Libvirt-Ruby {<img src="https://secure.travis-ci.org/plribeiro3000/libvirt-ruby.png" />}[http://travis-ci.org/plribeiro3000/libvirt-ruby]
2
2
 
3
3
  Rails gem to map functions from libvirt's library to ruby.
4
4
 
@@ -15,8 +15,7 @@ This gem has as a dependencie the libvirt package. Google it and u will find how
15
15
  You should one of the classes defined and call method dispatcher passing parameters:
16
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'
17
17
  second -> the args of the function in C in the same order
18
-
19
- Your second parameter must be an array where the last value is a symbol of what the function should return.
18
+ third -> a symbol of the retun of the function.
20
19
 
21
20
  == Experimental
22
21
 
@@ -1,15 +1,6 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- module Connect
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
-
3
+ class Connect < Libvirt::Ruby::Util
13
4
  def self.klass
14
5
  "virConnect"
15
6
  end
@@ -1,15 +1,6 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- module Domain
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
-
3
+ class Domain < Libvirt::Ruby::Util
13
4
  def self.klass
14
5
  "virDomain"
15
6
  end
@@ -1,15 +1,6 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- module Network
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
-
3
+ class Network < Libvirt::Ruby::Util
13
4
  def self.klass
14
5
  "virNetwork"
15
6
  end
@@ -1,15 +1,6 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- module StoragePool
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
-
3
+ class StoragePool < Libvirt::Ruby::Util
13
4
  def self.klass
14
5
  "virStoragePool"
15
6
  end
@@ -1,15 +1,6 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- module StorageVol
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
-
3
+ class StorageVol < Libvirt::Ruby::Util
13
4
  def self.klass
14
5
  "virStorageVol"
15
6
  end
@@ -1,13 +1,17 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- module Util
4
- def dispatcher(method, args = [])
3
+ class Util
4
+ extend FFI::Library
5
+
6
+ def self.dispatcher(method, args = [], return_type)
5
7
  begin
6
- return_type = args.delete(args.last)
8
+ ffi_lib "libvirt"
7
9
  attach_function (self.klass + method.to_s), (self.klass + method.to_s), args, return_type
8
- send((self.klass + method.to_s), args)
10
+ send (self.klass + method.to_s), args
9
11
  rescue FFI::NotFoundError
10
12
  raise Libvirt::Ruby::Exceptions::InvalidFunction.new(self.klass + method.to_s)
13
+ rescue LoadError
14
+ raise Libvirt::Ruby::Exceptions::MissingLib
11
15
  end
12
16
  end
13
17
  end
@@ -1,5 +1,5 @@
1
1
  module Libvirt
2
2
  module Ruby
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -4,28 +4,44 @@ describe Libvirt::Ruby::Connect do
4
4
  let(:connect) { Libvirt::Ruby::Connect }
5
5
 
6
6
  context "when calling method #dispatcher" do
7
- context "with a valid libvirt function" do
7
+ context "with libvirt installed" do
8
8
  before :each do
9
- connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
10
- connect.stub(:send).with("virConnectClose", [])
9
+ connect.stub(:ffi_lib).with("libvirt")
11
10
  end
12
11
 
13
- after :each do
14
- connect.dispatcher('Close', [:int])
15
- end
12
+ context "and a valid libvirt function" do
13
+ before :each do
14
+ connect.stub(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
15
+ connect.stub(:send).with("virConnectClose", [])
16
+ end
17
+
18
+ after :each do
19
+ connect.dispatcher('Close', [], :int)
20
+ end
16
21
 
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)
22
+ it "should attach it as a binding for C's function" do
23
+ connect.should_receive(:attach_function).with("virConnectClose", "virConnectClose", [], :int).and_return(true)
24
+ end
25
+
26
+ it "should call the new attached method" do
27
+ connect.should_receive(:send).with("virConnectClose", [])
28
+ end
19
29
  end
20
30
 
21
- it "should call the new attached method" do
22
- connect.should_receive(:send).with("virConnectClose", [])
31
+ context "and an invalid libvirt function" do
32
+ before :each do
33
+ connect.stub(:attach_function).with("virConnectAbc", "virConnectAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
34
+ end
35
+
36
+ it "should raise an exception" do
37
+ lambda { connect.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
38
+ end
23
39
  end
24
40
  end
25
41
 
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)
42
+ context "without libvirt installed" do
43
+ it "should raise an exception" do
44
+ lambda { connect.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
29
45
  end
30
46
  end
31
47
  end
@@ -4,28 +4,44 @@ describe Libvirt::Ruby::Domain do
4
4
  let(:domain) { Libvirt::Ruby::Domain }
5
5
 
6
6
  context "when calling method #dispatcher" do
7
- context "with a valid libvirt function" do
7
+ context "with libvirt installed" do
8
8
  before :each do
9
- domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
10
- domain.stub(:send).with("virDomainCreate", [])
9
+ domain.stub(:ffi_lib).with("libvirt")
11
10
  end
12
11
 
13
- after :each do
14
- domain.dispatcher('Create', [:int])
15
- end
12
+ context "and a valid libvirt function" do
13
+ before :each do
14
+ domain.stub(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
15
+ domain.stub(:send).with("virDomainCreate", [])
16
+ end
17
+
18
+ after :each do
19
+ domain.dispatcher('Create', [], :int)
20
+ end
16
21
 
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)
22
+ it "should attach it as a binding for C's function" do
23
+ domain.should_receive(:attach_function).with("virDomainCreate", "virDomainCreate", [], :int).and_return(true)
24
+ end
25
+
26
+ it "should call the new attached method" do
27
+ domain.should_receive(:send).with("virDomainCreate", [])
28
+ end
19
29
  end
20
30
 
21
- it "should call the new attached method" do
22
- domain.should_receive(:send).with("virDomainCreate", [])
31
+ context "and an invalid libvirt function" do
32
+ before :each do
33
+ domain.stub(:attach_function).with("virDomainAbc", "virDomainAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
34
+ end
35
+
36
+ it "should raise an exception" do
37
+ lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
38
+ end
23
39
  end
24
40
  end
25
41
 
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)
42
+ context "without libvirt installed" do
43
+ it "should raise an exception" do
44
+ lambda { domain.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
29
45
  end
30
46
  end
31
47
  end
@@ -4,28 +4,44 @@ describe Libvirt::Ruby::Network do
4
4
  let(:network) { Libvirt::Ruby::Network }
5
5
 
6
6
  context "when calling method #dispatcher" do
7
- context "with a valid libvirt function" do
7
+ context "with libvirt installed" do
8
8
  before :each do
9
- network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
10
- network.stub(:send).with("virNetworkRef", [])
9
+ network.stub(:ffi_lib).with("libvirt")
11
10
  end
12
11
 
13
- after :each do
14
- network.dispatcher('Ref', [:int])
15
- end
12
+ context "and a valid libvirt function" do
13
+ before :each do
14
+ network.stub(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
15
+ network.stub(:send).with("virNetworkRef", [])
16
+ end
17
+
18
+ after :each do
19
+ network.dispatcher('Ref', [], :int)
20
+ end
16
21
 
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)
22
+ it "should attach it as a binding for C's function" do
23
+ network.should_receive(:attach_function).with("virNetworkRef", "virNetworkRef", [], :int).and_return(true)
24
+ end
25
+
26
+ it "should call the new attached method" do
27
+ network.should_receive(:send).with("virNetworkRef", [])
28
+ end
19
29
  end
20
30
 
21
- it "should call the new attached method" do
22
- network.should_receive(:send).with("virNetworkRef", [])
31
+ context "and an invalid libvirt function" do
32
+ before :each do
33
+ network.stub(:attach_function).with("virNetworkAbc", "virNetworkAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
34
+ end
35
+
36
+ it "should raise an exception" do
37
+ lambda { network.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
38
+ end
23
39
  end
24
40
  end
25
41
 
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)
42
+ context "without libvirt installed" do
43
+ it "should raise an exception" do
44
+ lambda { network.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
29
45
  end
30
46
  end
31
47
  end
@@ -4,28 +4,44 @@ describe Libvirt::Ruby::StoragePool do
4
4
  let(:storage_pool) { Libvirt::Ruby::StoragePool }
5
5
 
6
6
  context "when calling method #dispatcher" do
7
- context "with a valid libvirt function" do
7
+ context "with libvirt installed" do
8
8
  before :each do
9
- storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
10
- storage_pool.stub(:send).with("virStoragePoolRefresh", [])
9
+ storage_pool.stub(:ffi_lib).with("libvirt")
11
10
  end
12
11
 
13
- after :each do
14
- storage_pool.dispatcher('Refresh', [:int])
15
- end
12
+ context "and a valid libvirt function" do
13
+ before :each do
14
+ storage_pool.stub(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
15
+ storage_pool.stub(:send).with("virStoragePoolRefresh", [])
16
+ end
17
+
18
+ after :each do
19
+ storage_pool.dispatcher('Refresh', [], :int)
20
+ end
16
21
 
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)
22
+ it "should attach it as a binding for C's function" do
23
+ storage_pool.should_receive(:attach_function).with("virStoragePoolRefresh", "virStoragePoolRefresh", [], :int).and_return(true)
24
+ end
25
+
26
+ it "should call the new attached method" do
27
+ storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
28
+ end
19
29
  end
20
30
 
21
- it "should call the new attached method" do
22
- storage_pool.should_receive(:send).with("virStoragePoolRefresh", [])
31
+ context "and an invalid libvirt function" do
32
+ before :each do
33
+ storage_pool.stub(:attach_function).with("virStoragePoolAbc", "virStoragePoolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
34
+ end
35
+
36
+ it "should raise an exception" do
37
+ lambda { storage_pool.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
38
+ end
23
39
  end
24
40
  end
25
41
 
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)
42
+ context "without libvirt installed" do
43
+ it "should raise an exception" do
44
+ lambda { storage_pool.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
29
45
  end
30
46
  end
31
47
  end
@@ -4,28 +4,44 @@ describe Libvirt::Ruby::StorageVol do
4
4
  let(:storage_vol) { Libvirt::Ruby::StorageVol }
5
5
 
6
6
  context "when calling method #dispatcher" do
7
- context "with a valid libvirt function" do
7
+ context "with libvirt installed" do
8
8
  before :each do
9
- storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
10
- storage_vol.stub(:send).with("virStorageVolResize", [])
9
+ storage_vol.stub(:ffi_lib).with("libvirt")
11
10
  end
12
11
 
13
- after :each do
14
- storage_vol.dispatcher('Resize', [:int])
15
- end
12
+ context "and a valid libvirt function" do
13
+ before :each do
14
+ storage_vol.stub(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
15
+ storage_vol.stub(:send).with("virStorageVolResize", [])
16
+ end
17
+
18
+ after :each do
19
+ storage_vol.dispatcher('Resize', [], :int)
20
+ end
16
21
 
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)
22
+ it "should attach it as a binding for C's function" do
23
+ storage_vol.should_receive(:attach_function).with("virStorageVolResize", "virStorageVolResize", [], :int).and_return(true)
24
+ end
25
+
26
+ it "should call the new attached method" do
27
+ storage_vol.should_receive(:send).with("virStorageVolResize", [])
28
+ end
19
29
  end
20
30
 
21
- it "should call the new attached method" do
22
- storage_vol.should_receive(:send).with("virStorageVolResize", [])
31
+ context "and an invalid libvirt function" do
32
+ before :each do
33
+ storage_vol.stub(:attach_function).with("virStorageVolAbc", "virStorageVolAbc", [], :int).and_raise(FFI::NotFoundError.new('Abc', 'libvirt'))
34
+ end
35
+
36
+ it "should raise an exception" do
37
+ lambda { storage_vol.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::InvalidFunction)
38
+ end
23
39
  end
24
40
  end
25
41
 
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)
42
+ context "without libvirt installed" do
43
+ it "should raise an exception" do
44
+ lambda { storage_vol.dispatcher('Abc', [], :int) }.should raise_error(Libvirt::Ruby::Exceptions::MissingLib)
29
45
  end
30
46
  end
31
47
  end
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.2
4
+ version: 0.0.3
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-24 00:00:00.000000000 Z
12
+ date: 2012-02-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
16
- requirement: &12651960 !ruby/object:Gem::Requirement
16
+ requirement: &13546920 !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: *12651960
24
+ version_requirements: *13546920
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &12651440 !ruby/object:Gem::Requirement
27
+ requirement: &13546320 !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: *12651440
35
+ version_requirements: *13546320
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &12650440 !ruby/object:Gem::Requirement
38
+ requirement: &13545340 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *12650440
46
+ version_requirements: *13545340
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: fakefs
49
- requirement: &12649920 !ruby/object:Gem::Requirement
49
+ requirement: &13544880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *12649920
57
+ version_requirements: *13544880
58
58
  description: Access Libvirt's C Library through ruby classes and methods
59
59
  email: plribeiro3000@gmail.com
60
60
  executables: []