libvirt-ruby 1.0.2 → 2.0.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/.gitignore +16 -1
- data/.rspec +1 -1
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +63 -0
- data/Rakefile +1 -10
- data/lib/libvirt-ruby.rb +9 -9
- data/lib/libvirt-ruby/exceptions.rb +5 -7
- data/lib/libvirt-ruby/exceptions/invalid_function.rb +4 -6
- data/lib/libvirt-ruby/exceptions/missing_lib.rb +4 -6
- data/lib/libvirt-ruby/exceptions/no_return_parameter.rb +4 -6
- data/lib/libvirt-ruby/exceptions/wrong_call.rb +4 -6
- data/lib/libvirt-ruby/version.rb +2 -2
- data/libvirt-ruby.gemspec +15 -15
- data/spec/libvirt-ruby_spec.rb +11 -6
- data/spec/spec_helper.rb +6 -4
- metadata +51 -13
- data/.rvmrc +0 -1
- data/README.rdoc +0 -35
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--colour --format documentation
|
1
|
+
--colour --format documentation --profile
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
libvirt-ruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Libvirt::Ruby
|
2
|
+
|
3
|
+
[](http://badge.fury.io/rb/libvirt-ruby) [](http://travis-ci.org/plribeiro3000/libvirt-ruby) [](https://gemnasium.com/plribeiro3000/libvirt-ruby) [](https://coveralls.io/r/plribeiro3000/libvirt-ruby) [](https://codeclimate.com/github/plribeiro3000/libvirt-ruby)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'libvirt-ruby'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install libvirt-ruby
|
18
|
+
|
19
|
+
## Dependencies
|
20
|
+
|
21
|
+
This gem has as a dependency the libvirt package. Google it and u will find how to install it on your distro.
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
You may define pointers, callbacks and enums using the FFI gem. Since the main module of this gem extend it,
|
26
|
+
you can call directly on it, just like:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Libvirt::Base.new.typedef :pointer, :pointer
|
30
|
+
Libvirt::Base.new.callback :virFreeCallback, [:pointer], :void
|
31
|
+
Libvirt::Base.new.enum :virStorageVolType, [:file, :block]
|
32
|
+
```
|
33
|
+
|
34
|
+
You should call the c function directly with the same name to attach it to the module:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
Libvirt::Base.new.virConnectClose([:int])
|
38
|
+
```
|
39
|
+
|
40
|
+
The only parameter of the function should be an array passing as arguments all the variables that the c function needs
|
41
|
+
and the return of the C function. After call the first time to attach, you can call the method on Libvirt::Ruby,
|
42
|
+
passing this time the real values if needed.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Libvirt::Base.new.virConnectClose
|
46
|
+
```
|
47
|
+
|
48
|
+
## Migrating to 2.0
|
49
|
+
|
50
|
+
To make easy developing on libvirt-ruby-mapping, the module ruby was changed to a class. And a class can't be named ruby,
|
51
|
+
so it is necessary to replace all your calls from Libvirt::Ruby to Libvirt::Base.new.
|
52
|
+
|
53
|
+
## Mantainers
|
54
|
+
[@plribeiro3000](https://github.com/plribeiro3000)
|
55
|
+
|
56
|
+
|
57
|
+
## Contributing
|
58
|
+
|
59
|
+
1. Fork it
|
60
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
61
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
62
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
63
|
+
5. Create new Pull Request
|
data/Rakefile
CHANGED
@@ -4,13 +4,4 @@ require "rspec/core/rake_task"
|
|
4
4
|
RSpec::Core::RakeTask.new
|
5
5
|
|
6
6
|
desc "Default Task"
|
7
|
-
task :default => [ :spec ]
|
8
|
-
|
9
|
-
rubies = %w(1.8.7@libvirt-ruby 1.9.2@libvirt-ruby 1.9.3@libvirt-ruby)
|
10
|
-
rubies.each do |ruby|
|
11
|
-
desc "Run the test suite against: #{ruby.split('@')[0]}"
|
12
|
-
task "spec-#{ruby.split('@')[0]}" do
|
13
|
-
puts "Running test suite against: #{ruby.split('@')[0]}"
|
14
|
-
exec("rvm #{ruby} do rspec spec")
|
15
|
-
end
|
16
|
-
end
|
7
|
+
task :default => [ :spec ]
|
data/lib/libvirt-ruby.rb
CHANGED
@@ -2,33 +2,33 @@ require "libvirt-ruby/version"
|
|
2
2
|
require "ffi"
|
3
3
|
|
4
4
|
module Libvirt
|
5
|
-
|
6
|
-
autoload :Exceptions, 'libvirt-ruby/exceptions'
|
5
|
+
autoload :Exceptions, 'libvirt-ruby/exceptions'
|
7
6
|
|
7
|
+
class Base
|
8
8
|
extend FFI::Library
|
9
9
|
|
10
|
-
def
|
10
|
+
def method_missing(method, *args)
|
11
11
|
args.flatten!
|
12
12
|
return_type = args.delete(args.last)
|
13
|
-
raise Libvirt::
|
13
|
+
raise Libvirt::Exceptions::NoReturnParameter unless return_type
|
14
14
|
dispatcher(method, args, return_type)
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def
|
20
|
-
raise Libvirt::
|
19
|
+
def dispatcher(method, args = [], return_type = nil)
|
20
|
+
raise Libvirt::Exceptions::WrongCall unless not_direct_call?
|
21
21
|
begin
|
22
22
|
ffi_lib "libvirt"
|
23
23
|
attach_function method.to_s, method.to_s, args, return_type
|
24
24
|
rescue FFI::NotFoundError
|
25
|
-
raise Libvirt::
|
25
|
+
raise Libvirt::Exceptions::InvalidFunction.new(method.to_s)
|
26
26
|
rescue LoadError
|
27
|
-
raise Libvirt::
|
27
|
+
raise Libvirt::Exceptions::MissingLib
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
31
|
+
def not_direct_call?
|
32
32
|
caller[1][/`.*'/] and caller[1][/`.*'/][1..-2] == 'method_missing'
|
33
33
|
end
|
34
34
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Libvirt
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
autoload :WrongCall, 'libvirt-ruby/exceptions/wrong_call'
|
8
|
-
end
|
2
|
+
module Exceptions
|
3
|
+
autoload :MissingLib, 'libvirt-ruby/exceptions/missing_lib'
|
4
|
+
autoload :InvalidFunction, 'libvirt-ruby/exceptions/invalid_function'
|
5
|
+
autoload :NoReturnParameter, 'libvirt-ruby/exceptions/no_return_parameter'
|
6
|
+
autoload :WrongCall, 'libvirt-ruby/exceptions/wrong_call'
|
9
7
|
end
|
10
8
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Libvirt
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
super("The function '#{function}' could not be found. Is it correct?")
|
7
|
-
end
|
2
|
+
module Exceptions
|
3
|
+
class InvalidFunction < StandardError
|
4
|
+
def initialize(function)
|
5
|
+
super("The function '#{function}' could not be found. Is it correct?")
|
8
6
|
end
|
9
7
|
end
|
10
8
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Libvirt
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
super("The libvirt C library could not be loaded. Is it properly installed?")
|
7
|
-
end
|
2
|
+
module Exceptions
|
3
|
+
class MissingLib < StandardError
|
4
|
+
def initialize
|
5
|
+
super("The libvirt C library could not be loaded. Is it properly installed?")
|
8
6
|
end
|
9
7
|
end
|
10
8
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Libvirt
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
super("No Return Parameter was Specified. It was by purpose?")
|
7
|
-
end
|
2
|
+
module Exceptions
|
3
|
+
class NoReturnParameter < StandardError
|
4
|
+
def initialize
|
5
|
+
super("No Return Parameter was Specified. It was by purpose?")
|
8
6
|
end
|
9
7
|
end
|
10
8
|
end
|
@@ -1,10 +1,8 @@
|
|
1
1
|
module Libvirt
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
super("This method cannot be called directly. It was by purpose?")
|
7
|
-
end
|
2
|
+
module Exceptions
|
3
|
+
class WrongCall < StandardError
|
4
|
+
def initialize
|
5
|
+
super("This method cannot be called directly. It was by purpose?")
|
8
6
|
end
|
9
7
|
end
|
10
8
|
end
|
data/lib/libvirt-ruby/version.rb
CHANGED
data/libvirt-ruby.gemspec
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require "libvirt-ruby/version"
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
s.description = %q{Access Libvirt's C Library through ruby bindings defined on the fly!}
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "libvirt-ruby"
|
7
|
+
gem.version = Libvirt::Ruby::VERSION
|
8
|
+
gem.authors = %q{Paulo Henrique Lopes Ribeiro}
|
9
|
+
gem.email = %q{plribeiro3000@gmail.com}
|
10
|
+
gem.summary = %q{Ruby bindings for the Libvirt C Library on the fly!}
|
11
|
+
gem.description = %q{Access Libvirt's C Library through ruby bindings defined on the fly!}
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
gem.files = `git ls-files`.split("\n")
|
14
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
gem.require_paths = %w(lib)
|
18
17
|
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
gem.add_runtime_dependency "ffi", "> 1.0.0"
|
19
|
+
gem.add_development_dependency "rake"
|
20
|
+
gem.add_development_dependency "rspec", "> 2.5.0"
|
21
|
+
gem.add_development_dependency 'coveralls'
|
22
22
|
end
|
data/spec/libvirt-ruby_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe Libvirt::
|
4
|
-
let(:libvirt) { Libvirt::
|
3
|
+
describe Libvirt::Base do
|
4
|
+
let(:libvirt) { Libvirt::Base.new }
|
5
5
|
|
6
6
|
context "when calling any libvirt function directly" do
|
7
7
|
context "without a return type specified" do
|
8
8
|
it "should raise an error" do
|
9
|
-
lambda { libvirt.virConnectClose }.should raise_error(Libvirt::
|
9
|
+
lambda { libvirt.virConnectClose }.should raise_error(Libvirt::Exceptions::NoReturnParameter)
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -36,21 +36,26 @@ describe Libvirt::Ruby do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should raise an exception" do
|
39
|
-
lambda { libvirt.virConnectAbc([:int]) }.should raise_error(Libvirt::
|
39
|
+
lambda { libvirt.virConnectAbc([:int]) }.should raise_error(Libvirt::Exceptions::InvalidFunction)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
44
|
context "without libvirt installed" do
|
45
|
+
before :each do
|
46
|
+
libvirt.stub(:attach_function).with("virConnectAbc", "virConnectAbc", [], :int)
|
47
|
+
libvirt.stub(:ffi_lib).and_raise(LoadError)
|
48
|
+
end
|
49
|
+
|
45
50
|
it "should raise an exception" do
|
46
|
-
lambda { libvirt.virConnectAbc([:int])
|
51
|
+
lambda { libvirt.virConnectAbc([:int]) }.should raise_error(Libvirt::Exceptions::MissingLib)
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
50
55
|
|
51
56
|
context "when calling method #dispatcher directly" do
|
52
57
|
it "should raise an exception" do
|
53
|
-
lambda { libvirt.
|
58
|
+
lambda { libvirt.send('dispatcher', 'virConnectClose', [], :int) }.should raise_error(Libvirt::Exceptions::WrongCall)
|
54
59
|
end
|
55
60
|
end
|
56
61
|
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:
|
4
|
+
version: 2.0.0
|
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:
|
12
|
+
date: 2013-08-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,15 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>'
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.0.0
|
25
30
|
- !ruby/object:Gem::Dependency
|
26
31
|
name: rake
|
27
|
-
requirement:
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
28
33
|
none: false
|
29
34
|
requirements:
|
30
35
|
- - ! '>='
|
@@ -32,18 +37,44 @@ dependencies:
|
|
32
37
|
version: '0'
|
33
38
|
type: :development
|
34
39
|
prerelease: false
|
35
|
-
version_requirements:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
36
46
|
- !ruby/object:Gem::Dependency
|
37
47
|
name: rspec
|
38
|
-
requirement:
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
39
49
|
none: false
|
40
50
|
requirements:
|
41
|
-
- -
|
51
|
+
- - ! '>'
|
42
52
|
- !ruby/object:Gem::Version
|
43
53
|
version: 2.5.0
|
44
54
|
type: :development
|
45
55
|
prerelease: false
|
46
|
-
version_requirements:
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>'
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.5.0
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: coveralls
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
47
78
|
description: Access Libvirt's C Library through ruby bindings defined on the fly!
|
48
79
|
email: plribeiro3000@gmail.com
|
49
80
|
executables: []
|
@@ -52,11 +83,12 @@ extra_rdoc_files: []
|
|
52
83
|
files:
|
53
84
|
- .gitignore
|
54
85
|
- .rspec
|
55
|
-
- .
|
86
|
+
- .ruby-gemset
|
87
|
+
- .ruby-version
|
56
88
|
- .travis.yml
|
57
89
|
- Gemfile
|
58
90
|
- LICENSE
|
59
|
-
- README.
|
91
|
+
- README.md
|
60
92
|
- Rakefile
|
61
93
|
- lib/libvirt-ruby.rb
|
62
94
|
- lib/libvirt-ruby/exceptions.rb
|
@@ -68,7 +100,7 @@ files:
|
|
68
100
|
- libvirt-ruby.gemspec
|
69
101
|
- spec/libvirt-ruby_spec.rb
|
70
102
|
- spec/spec_helper.rb
|
71
|
-
homepage:
|
103
|
+
homepage:
|
72
104
|
licenses: []
|
73
105
|
post_install_message:
|
74
106
|
rdoc_options: []
|
@@ -80,15 +112,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
112
|
- - ! '>='
|
81
113
|
- !ruby/object:Gem::Version
|
82
114
|
version: '0'
|
115
|
+
segments:
|
116
|
+
- 0
|
117
|
+
hash: 2094704675340228834
|
83
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
119
|
none: false
|
85
120
|
requirements:
|
86
121
|
- - ! '>='
|
87
122
|
- !ruby/object:Gem::Version
|
88
123
|
version: '0'
|
124
|
+
segments:
|
125
|
+
- 0
|
126
|
+
hash: 2094704675340228834
|
89
127
|
requirements: []
|
90
128
|
rubyforge_project:
|
91
|
-
rubygems_version: 1.8.
|
129
|
+
rubygems_version: 1.8.25
|
92
130
|
signing_key:
|
93
131
|
specification_version: 3
|
94
132
|
summary: Ruby bindings for the Libvirt C Library on the fly!
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm use 1.9.3@libvirt-ruby
|
data/README.rdoc
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
= Libvirt-Ruby {<img src="https://secure.travis-ci.org/plribeiro3000/libvirt-ruby.png" />}[http://travis-ci.org/plribeiro3000/libvirt-ruby]
|
2
|
-
|
3
|
-
Rails gem to map functions from libvirt's library to ruby on the fly.
|
4
|
-
|
5
|
-
== Install
|
6
|
-
|
7
|
-
gem install libvirt-ruby
|
8
|
-
|
9
|
-
== Dependencies
|
10
|
-
|
11
|
-
This gem has as a dependency the libvirt package. Google it and u will find how to install it on your distro.
|
12
|
-
|
13
|
-
== Usage
|
14
|
-
|
15
|
-
You may define pointers, callbacks and enums using the FFI gem. Since the main module of this gem extend it,
|
16
|
-
you can call directly on it, just like:
|
17
|
-
Libvirt::Ruby.typedef :pointer, :pointer
|
18
|
-
Libvirt::Ruby.callback :virFreeCallback, [:pointer], :void
|
19
|
-
Libvirt::Ruby.enum :virStorageVolType, [:file, :block]
|
20
|
-
|
21
|
-
You should call the c function directly with the same name to attach it to the module:
|
22
|
-
Libvirt::Ruby.virConnectClose([:int])
|
23
|
-
|
24
|
-
The only parameter of the function should be an array passing as arguments all the variables that the c function needs
|
25
|
-
and the return of the C function. After call the first time to attach, you can call the method on Libvirt::Ruby,
|
26
|
-
passing this time the real values if needed.
|
27
|
-
Libvirt::Ruby.virConnectClose
|
28
|
-
|
29
|
-
== Bugs
|
30
|
-
|
31
|
-
This Gem still in development, so if you have some problem, feel free to create a new issue.
|
32
|
-
|
33
|
-
== Contribute
|
34
|
-
|
35
|
-
Fork the project, make your changes and send me a Pull Request.
|