libvirt-ruby-mapping 0.0.1 → 0.1.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/lib/libvirt-ruby-mapping.rb +6 -6
- data/lib/libvirt-ruby-mapping/connect.rb +17 -0
- data/lib/libvirt-ruby-mapping/version.rb +1 -1
- data/spec/libvirt-ruby-mapping/connect/open_read_only_spec.rb +41 -0
- data/spec/libvirt-ruby-mapping/connect/open_spec.rb +41 -0
- data/spec/libvirt-ruby-mapping_spec.rb +68 -0
- data/spec/spec_helper.rb +5 -0
- metadata +14 -9
data/lib/libvirt-ruby-mapping.rb
CHANGED
@@ -2,19 +2,19 @@ require "libvirt-ruby-mapping/version"
|
|
2
2
|
|
3
3
|
module Libvirt
|
4
4
|
module Ruby
|
5
|
-
|
6
|
-
|
5
|
+
autoload :Connect, 'libvirt-ruby-mapping/connect'
|
6
|
+
|
7
|
+
def self.initialize
|
8
|
+
virInitialize(:int) unless respond_to_missing?(:virInitialize, false)
|
7
9
|
virInitialize
|
8
10
|
end
|
9
11
|
|
10
12
|
def self.version
|
11
|
-
virGetVersion(:pointer, :string, :pointer, :int) unless
|
13
|
+
virGetVersion(:pointer, :string, :pointer, :int) unless respond_to_missing?(:virGetVersion, false)
|
12
14
|
p = FFI::MemoryPointer.new(:ulong)
|
13
15
|
virGetVersion(p, nil, nil)
|
14
16
|
version = p.get_ulong(0)
|
15
17
|
"#{version / 1_000_000}.#{(version % 1_000_000) / 1_000}.#{(version % 1_000_000) %1000}"
|
16
18
|
end
|
17
19
|
end
|
18
|
-
end
|
19
|
-
|
20
|
-
Libvirt::ruby.initialize
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Ruby
|
3
|
+
module Connect
|
4
|
+
extend Libvirt::Ruby
|
5
|
+
|
6
|
+
def self.open(uri)
|
7
|
+
virConnectOpen(:string, :pointer) unless respond_to_missing?(:virConnectOpen, false)
|
8
|
+
virConnectOpen(uri)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.open_read_only(uri)
|
12
|
+
virConnectOpenReadOnly(:string, :pointer) unless respond_to_missing?(:virConnectOpenReadOnly, false)
|
13
|
+
virConnectOpenReadOnly(uri)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Libvirt::Ruby::Connect do
|
4
|
+
let(:connect) { Libvirt::Ruby::Connect }
|
5
|
+
let(:p) { Object }
|
6
|
+
|
7
|
+
context "#open_read_only" do
|
8
|
+
before :each do
|
9
|
+
connect.stub(:virConnectOpenReadOnly).with(:string, :pointer).and_return(true)
|
10
|
+
connect.stub(:virConnectOpenReadOnly).with("uri").and_return(p)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
connect.open_read_only("uri")
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when virConnectOpenReadOnly is not attached yet" do
|
18
|
+
it "should attach it" do
|
19
|
+
connect.should_receive(:virConnectOpenReadOnly).with(:string, :pointer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when virConnectOpenReadOnly is already attached" do
|
24
|
+
before :each do
|
25
|
+
connect.stub(:respond_to_missing?).with(:virConnectOpenReadOnly, false).and_return(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not try to attach it again" do
|
29
|
+
connect.should_not_receive(:virConnectOpenReadOnly).with(:string, :pointer)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should call virConnectOpenReadOnly" do
|
34
|
+
connect.should_receive(:virConnectOpenReadOnly)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return the pointer to the new read only connection" do
|
38
|
+
connect.open_read_only("uri").should == p
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Libvirt::Ruby::Connect do
|
4
|
+
let(:connect) { Libvirt::Ruby::Connect }
|
5
|
+
let(:p) { Object }
|
6
|
+
|
7
|
+
context "#open" do
|
8
|
+
before :each do
|
9
|
+
connect.stub(:virConnectOpen).with(:string, :pointer).and_return(true)
|
10
|
+
connect.stub(:virConnectOpen).with("uri").and_return(p)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
connect.open("uri")
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when virConnectOpen is not attached yet" do
|
18
|
+
it "should attach it" do
|
19
|
+
connect.should_receive(:virConnectOpen).with(:string, :pointer)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when virConnectOpen is already attached" do
|
24
|
+
before :each do
|
25
|
+
connect.stub(:respond_to_missing?).with(:virConnectOpen, false).and_return(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not try to attach it again" do
|
29
|
+
connect.should_not_receive(:virConnectOpen).with(:string, :pointer)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should call virConnectOpen" do
|
34
|
+
connect.should_receive(:virConnectOpen)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should return the pointer to the new connection" do
|
38
|
+
connect.open("uri").should == p
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Libvirt::Ruby do
|
4
|
+
let(:libvirt) { Libvirt::Ruby }
|
5
|
+
let(:p) { Object }
|
6
|
+
|
7
|
+
context "#initialize" do
|
8
|
+
before :each do
|
9
|
+
libvirt.stub(:virInitialize).with(:int).and_return(true)
|
10
|
+
libvirt.stub(:virInitialize).and_return(true)
|
11
|
+
end
|
12
|
+
|
13
|
+
after :each do
|
14
|
+
libvirt.initialize
|
15
|
+
end
|
16
|
+
|
17
|
+
context "when virInitialize is not attached yet" do
|
18
|
+
it "should attach it" do
|
19
|
+
libvirt.should_receive(:virInitialize).with(:int)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when virInitialize is already attached" do
|
24
|
+
before :each do
|
25
|
+
libvirt.stub(:respond_to_missing?).with(:virInitialize, false).and_return(true)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not try to attach it again" do
|
29
|
+
libvirt.should_not_receive(:virInitialize).with(:int)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should call virInitialize" do
|
34
|
+
libvirt.should_receive(:virInitialize)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "#version" do
|
39
|
+
before :each do
|
40
|
+
libvirt.stub(:virGetVersion).with(:pointer, :string, :pointer, :int).and_return(true)
|
41
|
+
FFI::MemoryPointer.stub(:new).with(:ulong).and_return(p)
|
42
|
+
libvirt.stub(:virGetVersion).with(p, nil, nil).and_return(true)
|
43
|
+
p.stub(:get_ulong).with(0).and_return(8003)
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when virGetVersion is not attached yet" do
|
47
|
+
it "should attach it" do
|
48
|
+
libvirt.should_receive(:virGetVersion).with(:pointer, :string, :pointer, :int)
|
49
|
+
libvirt.version
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when virGetVersion is already attached" do
|
54
|
+
before :each do
|
55
|
+
libvirt.stub(:respond_to_missing?).with(:virGetVersion, false).and_return(true)
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should not try to attach it again" do
|
59
|
+
libvirt.should_not_receive(:virGetVersion).with(:pointer, :string, :pointer, :int)
|
60
|
+
libvirt.version
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should return the version" do
|
65
|
+
libvirt.version.should == "0.8.3"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libvirt-ruby-mapping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.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: 2012-
|
12
|
+
date: 2012-03-13 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: libvirt-ruby
|
16
|
-
requirement: &
|
16
|
+
requirement: &6951800 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>'
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *6951800
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &6951100 !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: *6951100
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &6950040 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - =
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: 2.5.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *6950040
|
47
47
|
description: Libvirt Mapping of C function to Ruby Class and methods
|
48
48
|
email: plribeiro3000@gmail.com
|
49
49
|
executables: []
|
@@ -59,8 +59,13 @@ files:
|
|
59
59
|
- README.rdoc
|
60
60
|
- Rakefile
|
61
61
|
- lib/libvirt-ruby-mapping.rb
|
62
|
+
- lib/libvirt-ruby-mapping/connect.rb
|
62
63
|
- lib/libvirt-ruby-mapping/version.rb
|
63
64
|
- libvirt-ruby-mapping.gemspec
|
65
|
+
- spec/libvirt-ruby-mapping/connect/open_read_only_spec.rb
|
66
|
+
- spec/libvirt-ruby-mapping/connect/open_spec.rb
|
67
|
+
- spec/libvirt-ruby-mapping_spec.rb
|
68
|
+
- spec/spec_helper.rb
|
64
69
|
homepage: ''
|
65
70
|
licenses: []
|
66
71
|
post_install_message:
|
@@ -81,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
86
|
version: '0'
|
82
87
|
requirements: []
|
83
88
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.8.
|
89
|
+
rubygems_version: 1.8.17
|
85
90
|
signing_key:
|
86
91
|
specification_version: 3
|
87
92
|
summary: Ruby mapping of the libvirt's functions using libvirt-ruby
|