libvirt 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +6 -6
- data/Rakefile +21 -0
- data/lib/libvirt/connection.rb +1 -1
- data/lib/libvirt/domain.rb +8 -0
- data/lib/libvirt/exception.rb +9 -0
- data/lib/libvirt/spec.rb +1 -0
- data/lib/libvirt/spec/device.rb +27 -0
- data/lib/libvirt/spec/device/disk.rb +25 -5
- data/lib/libvirt/spec/device/graphics.rb +39 -0
- data/lib/libvirt/spec/device/input.rb +40 -0
- data/lib/libvirt/spec/device/interface.rb +47 -0
- data/lib/libvirt/spec/device/sound.rb +32 -0
- data/lib/libvirt/spec/device/video.rb +47 -0
- data/lib/libvirt/spec/device/video_model.rb +53 -0
- data/lib/libvirt/spec/domain.rb +80 -5
- data/lib/libvirt/spec/domain/clock.rb +35 -0
- data/lib/libvirt/spec/domain/memtune.rb +29 -0
- data/lib/libvirt/spec/domain/os_booting.rb +27 -1
- data/lib/libvirt/spec/util.rb +43 -0
- data/lib/libvirt/version.rb +1 -1
- data/libvirt.gemspec +3 -4
- data/test/libvirt/domain_test.rb +6 -0
- data/test/libvirt/spec/device_test.rb +21 -0
- data/test/libvirt/spec/devices/disk_test.rb +21 -87
- data/test/libvirt/spec/devices/graphics_test.rb +25 -0
- data/test/libvirt/spec/devices/input_test.rb +25 -0
- data/test/libvirt/spec/devices/interface_test.rb +35 -0
- data/test/libvirt/spec/devices/sound_test.rb +20 -0
- data/test/libvirt/spec/devices/video_model_test.rb +36 -0
- data/test/libvirt/spec/domain/clock_test.rb +20 -0
- data/test/libvirt/spec/domain/os_booting_test.rb +31 -0
- data/test/libvirt/spec/domain_test.rb +123 -1
- metadata +32 -7
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
libvirt (0.
|
4
|
+
libvirt (0.2.0)
|
5
5
|
ffi (~> 0.6.3)
|
6
6
|
nokogiri (~> 1.4.3)
|
7
7
|
|
@@ -12,15 +12,15 @@ GEM
|
|
12
12
|
ffi (0.6.3)
|
13
13
|
rake (>= 0.8.7)
|
14
14
|
ffi (0.6.3-java)
|
15
|
-
mocha (0.9.
|
15
|
+
mocha (0.9.10)
|
16
16
|
rake
|
17
|
-
nokogiri (1.4.
|
18
|
-
nokogiri (1.4.
|
17
|
+
nokogiri (1.4.4)
|
18
|
+
nokogiri (1.4.4-java)
|
19
19
|
weakling (>= 0.0.3)
|
20
|
-
protest (0.4.
|
20
|
+
protest (0.4.2)
|
21
21
|
rake (0.8.7)
|
22
22
|
weakling (0.0.4-java)
|
23
|
-
yard (0.6.
|
23
|
+
yard (0.6.3)
|
24
24
|
|
25
25
|
PLATFORMS
|
26
26
|
java
|
data/Rakefile
CHANGED
@@ -12,6 +12,27 @@ task :test do
|
|
12
12
|
files.each { |f| load f }
|
13
13
|
end
|
14
14
|
|
15
|
+
# Testing against specific rubies or all of them. This uses RVM
|
16
|
+
# and expects these rubies to be installed already.
|
17
|
+
rubies = ["1.9.2", "1.8.7", "jruby", "rbx"]
|
18
|
+
rubies.each do |ruby|
|
19
|
+
desc "Run the test suite against: #{ruby}"
|
20
|
+
task "test_#{ruby.gsub('.', '_')}" do
|
21
|
+
puts "Running test suite against: #{ruby}"
|
22
|
+
exec("rvm #{ruby} rake")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Run the test suite against all rubies: #{rubies.join(", ")}"
|
27
|
+
task :test_all do
|
28
|
+
rubies.each do |ruby|
|
29
|
+
puts "Running test suite against: #{ruby}"
|
30
|
+
pid = fork
|
31
|
+
exec "rvm #{ruby} rake" if !pid
|
32
|
+
Process.wait(pid) if pid
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
15
36
|
begin
|
16
37
|
# Documentation task
|
17
38
|
require 'yard'
|
data/lib/libvirt/connection.rb
CHANGED
@@ -40,7 +40,7 @@ module Libvirt
|
|
40
40
|
# # Basic Information of a Connection
|
41
41
|
#
|
42
42
|
# Once you have a connection object, you can gather basic information about it
|
43
|
-
# by using methods such as {#
|
43
|
+
# by using methods such as {#hypervisor}, {#capabilities}, etc.:
|
44
44
|
#
|
45
45
|
# puts "Hypervisor type: #{conn.hypervisor}"
|
46
46
|
# puts "Hypervisor version: #{conn.hypervisor_verison}"
|
data/lib/libvirt/domain.rb
CHANGED
@@ -111,6 +111,14 @@ module Libvirt
|
|
111
111
|
FFI::Libvirt.virDomainGetXMLDesc(self, 0)
|
112
112
|
end
|
113
113
|
|
114
|
+
# Returns the {Libvirt::Spec::Domain} object representing this
|
115
|
+
# domain.
|
116
|
+
#
|
117
|
+
# @return [Libvirt::Spec::Domain]
|
118
|
+
def spec
|
119
|
+
Spec::Domain.new(xml)
|
120
|
+
end
|
121
|
+
|
114
122
|
# Returns boolean of whether the domain is active (running) or not.
|
115
123
|
#
|
116
124
|
# @return [Boolean]
|
data/lib/libvirt/exception.rb
CHANGED
@@ -15,5 +15,14 @@ module Libvirt
|
|
15
15
|
super(error.message)
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
# Represents an exception in parsing an XML spec into a Ruby
|
20
|
+
# {Libvirt::Spec} object.
|
21
|
+
class UnparseableSpec < StandardError
|
22
|
+
def initialize(tags)
|
23
|
+
tags = tags.map { |tag| tag.name }
|
24
|
+
super("Unsupported tags found. This is either a bug or the XML string given is invalid. Tags: #{tags}")
|
25
|
+
end
|
26
|
+
end
|
18
27
|
end
|
19
28
|
end
|
data/lib/libvirt/spec.rb
CHANGED
data/lib/libvirt/spec/device.rb
CHANGED
@@ -3,6 +3,33 @@ module Libvirt
|
|
3
3
|
module Device
|
4
4
|
autoload :Disk, 'libvirt/spec/device/disk'
|
5
5
|
autoload :Emulator, 'libvirt/spec/device/emulator'
|
6
|
+
autoload :Graphics, 'libvirt/spec/device/graphics'
|
7
|
+
autoload :Input, 'libvirt/spec/device/input'
|
8
|
+
autoload :Interface, 'libvirt/spec/device/interface'
|
9
|
+
autoload :Sound, 'libvirt/spec/device/sound'
|
10
|
+
autoload :Video, 'libvirt/spec/device/video'
|
11
|
+
autoload :VideoModel, 'libvirt/spec/device/video_model'
|
12
|
+
|
13
|
+
# Loads a device from an XML string. This will automatically find
|
14
|
+
# the proper class to load and return that.
|
15
|
+
#
|
16
|
+
# @return [Device]
|
17
|
+
def self.load!(xml)
|
18
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
19
|
+
get(xml.name).new(xml)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Returns the class of a device based on the name. If
|
23
|
+
# `:disk` were given, for example, then a {Disk} class
|
24
|
+
# would be returned. Note that since the class is returned,
|
25
|
+
# and not an instance, it is up to the caller to instantiate
|
26
|
+
# the returned class.
|
27
|
+
#
|
28
|
+
# @param [Symbol] name
|
29
|
+
# @return [Class]
|
30
|
+
def self.get(name)
|
31
|
+
const_get(name.to_s.capitalize)
|
32
|
+
end
|
6
33
|
end
|
7
34
|
end
|
8
35
|
end
|
@@ -5,7 +5,10 @@ module Libvirt
|
|
5
5
|
# cdrom, or paravirtualized driver is specified via the disk
|
6
6
|
# element.
|
7
7
|
class Disk
|
8
|
+
include Util
|
9
|
+
|
8
10
|
attr_accessor :type
|
11
|
+
attr_accessor :device
|
9
12
|
attr_accessor :source
|
10
13
|
attr_accessor :target_dev
|
11
14
|
attr_accessor :target_bus
|
@@ -15,16 +18,33 @@ module Libvirt
|
|
15
18
|
attr_accessor :shareable
|
16
19
|
attr_accessor :serial
|
17
20
|
|
18
|
-
#
|
19
|
-
#
|
20
|
-
|
21
|
-
|
21
|
+
# Initializes a new disk element. If an XML string is passed
|
22
|
+
# then that will be used to initialize the attributes of the
|
23
|
+
# device.
|
24
|
+
def initialize(xml=nil)
|
22
25
|
@shareable = false
|
26
|
+
|
27
|
+
load!(xml) if xml
|
28
|
+
end
|
29
|
+
|
30
|
+
# Loads data from XML.
|
31
|
+
def load!(xml)
|
32
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
33
|
+
try(xml.xpath("//disk[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym }
|
34
|
+
try(xml.xpath("//disk[@device]"), :preserve => true) { |result| self.device = result["device"].to_sym }
|
35
|
+
try(xml.xpath("//disk/source")) { |result| self.source = result["dev"] || result["file"] }
|
36
|
+
|
37
|
+
try(xml.xpath("//disk/target")) do |result|
|
38
|
+
self.target_dev = result["dev"]
|
39
|
+
self.target_bus = result["bus"]
|
40
|
+
end
|
41
|
+
|
42
|
+
raise_if_unparseables(xml.xpath("//disk/*"))
|
23
43
|
end
|
24
44
|
|
25
45
|
# Returns the XML representation of this device.
|
26
46
|
def to_xml(xml=Nokogiri::XML::Builder.new)
|
27
|
-
xml.disk(:type => type) do |d|
|
47
|
+
xml.disk(:type => type, :device => device) do |d|
|
28
48
|
if source
|
29
49
|
# Source tag, the attribute depends on the type.
|
30
50
|
attribute = type == :block ? :dev : :file
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Spec
|
3
|
+
module Device
|
4
|
+
# Represents a graphics device, which allows for graphical
|
5
|
+
# interaction with the guest OS.
|
6
|
+
class Graphics
|
7
|
+
include Util
|
8
|
+
|
9
|
+
attr_accessor :type
|
10
|
+
attr_accessor :display
|
11
|
+
|
12
|
+
# Initializes a new graphics device. If an XML string is given,
|
13
|
+
# it will be used to attempt to initialize the attributes.
|
14
|
+
def initialize(xml=nil)
|
15
|
+
load!(xml) if xml
|
16
|
+
end
|
17
|
+
|
18
|
+
# Attempts to initialize object attributes based on the XML
|
19
|
+
# string given.
|
20
|
+
def load!(xml)
|
21
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
22
|
+
try(xml.xpath("//graphics[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym }
|
23
|
+
try(xml.xpath("//graphics[@display]"), :preserve => true) { |result| self.display = result["display"] }
|
24
|
+
|
25
|
+
raise_if_unparseables(xml.xpath("//graphics/*"))
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the XML representation of this device.
|
29
|
+
def to_xml(xml=Nokogiri::XML::Builder.new)
|
30
|
+
options = { :type => type }
|
31
|
+
options[:display] = display if display
|
32
|
+
|
33
|
+
xml.graphics(options)
|
34
|
+
xml.to_xml
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Spec
|
3
|
+
module Device
|
4
|
+
# Represents an input device, which is a device that allows
|
5
|
+
# interaction with the graphical framebuffer in the guest
|
6
|
+
# virtual machine.
|
7
|
+
class Input
|
8
|
+
include Util
|
9
|
+
|
10
|
+
attr_accessor :type
|
11
|
+
attr_accessor :bus
|
12
|
+
|
13
|
+
# Initializes a new input device. If an XML string is given,
|
14
|
+
# it will be used to attempt to initialize the attributes.
|
15
|
+
def initialize(xml=nil)
|
16
|
+
load!(xml) if xml
|
17
|
+
end
|
18
|
+
|
19
|
+
# Attempts to initialize object attributes based on the XML
|
20
|
+
# string given.
|
21
|
+
def load!(xml)
|
22
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
23
|
+
try(xml.xpath("//input[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym }
|
24
|
+
try(xml.xpath("//input[@bus]"), :preserve => true) { |result| self.bus = result["bus"].to_sym }
|
25
|
+
|
26
|
+
raise_if_unparseables(xml.xpath("//input/*"))
|
27
|
+
end
|
28
|
+
|
29
|
+
# Returns the XML representation of this device
|
30
|
+
def to_xml(xml=Nokogiri::XML::Builder.new)
|
31
|
+
options = { :type => type }
|
32
|
+
options[:bus] = bus if bus
|
33
|
+
|
34
|
+
xml.input(options)
|
35
|
+
xml.to_xml
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Spec
|
3
|
+
module Device
|
4
|
+
# Represents a network interface device which is attached to
|
5
|
+
# a domain.
|
6
|
+
class Interface
|
7
|
+
include Util
|
8
|
+
|
9
|
+
attr_accessor :type
|
10
|
+
attr_accessor :mac_address
|
11
|
+
attr_accessor :model_type
|
12
|
+
attr_accessor :source_network
|
13
|
+
|
14
|
+
# Initializes a new network interface device. If an XML string
|
15
|
+
# is given, it will be used to attempt to initialize the attributes.
|
16
|
+
def initialize(xml=nil)
|
17
|
+
load!(xml) if xml
|
18
|
+
end
|
19
|
+
|
20
|
+
# Attempts to initialize object attributes based on XML attributes.
|
21
|
+
def load!(xml)
|
22
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
23
|
+
try(xml.xpath("//interface")) do |interface|
|
24
|
+
self.type = interface["type"].to_sym if interface["type"]
|
25
|
+
try(interface.xpath("mac")) { |result| self.mac_address = result["address"] }
|
26
|
+
try(interface.xpath("model")) { |result| self.model_type = result["type"] }
|
27
|
+
try(interface.xpath("source")) do |result|
|
28
|
+
self.source_network = result["network"]
|
29
|
+
end
|
30
|
+
|
31
|
+
raise_if_unparseables(interface.xpath("*"))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the XML representation of this device
|
36
|
+
def to_xml(xml=Nokogiri::XML::Builder.new)
|
37
|
+
xml.interface(:type => type) do |i|
|
38
|
+
i.mac(:address => mac_address) if mac_address
|
39
|
+
i.model(:type => model_type) if model_type
|
40
|
+
end
|
41
|
+
|
42
|
+
xml.to_xml
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Spec
|
3
|
+
module Device
|
4
|
+
# Represents a sound device.
|
5
|
+
class Sound
|
6
|
+
include Util
|
7
|
+
|
8
|
+
attr_accessor :model
|
9
|
+
|
10
|
+
# Initializes a new sound device. If an XML string is given,
|
11
|
+
# it will be used to attempt to initialize the attributes.
|
12
|
+
def initialize(xml=nil)
|
13
|
+
load!(xml) if xml
|
14
|
+
end
|
15
|
+
|
16
|
+
# Attempts to initialize object attributes based on the XML
|
17
|
+
# string given.
|
18
|
+
def load!(xml)
|
19
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
20
|
+
try(xml.xpath("//sound[@model]"), :preserve => true) { |result| self.model = result["model"].to_sym }
|
21
|
+
raise_if_unparseables(xml.xpath("//sound/*"))
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns the XML representation of this device.
|
25
|
+
def to_xml(xml=Nokogiri::XML::Builder.new)
|
26
|
+
xml.sound(:model => model)
|
27
|
+
xml.to_xml
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Spec
|
3
|
+
module Device
|
4
|
+
# Represents a video device.
|
5
|
+
class Video
|
6
|
+
include Util
|
7
|
+
|
8
|
+
attr_accessor :models
|
9
|
+
|
10
|
+
# Initializes a new video device. If an XML string is given,
|
11
|
+
# it will be used to attempt to initialize the attributes.
|
12
|
+
def initialize(xml=nil)
|
13
|
+
@models = []
|
14
|
+
|
15
|
+
load!(xml) if xml
|
16
|
+
end
|
17
|
+
|
18
|
+
# Attempts to initialize object attributes based on the XML
|
19
|
+
# string given.
|
20
|
+
def load!(xml)
|
21
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
22
|
+
|
23
|
+
try(xml.xpath("//video/model"), :multi => true) do |result|
|
24
|
+
self.models = []
|
25
|
+
|
26
|
+
result.each do |model|
|
27
|
+
self.models << VideoModel.new(model)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
raise_if_unparseables(xml.xpath("//video/*"))
|
32
|
+
end
|
33
|
+
|
34
|
+
# Returns the XML representation of this device.
|
35
|
+
def to_xml(xml=Nokogiri::XML::Builder.new)
|
36
|
+
xml.video do |v|
|
37
|
+
models.each do |model|
|
38
|
+
model.to_xml(xml)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
xml.to_xml
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Libvirt
|
2
|
+
module Spec
|
3
|
+
module Device
|
4
|
+
# Represents a model in the specific video device.
|
5
|
+
class VideoModel
|
6
|
+
include Util
|
7
|
+
|
8
|
+
attr_accessor :type
|
9
|
+
attr_accessor :vram
|
10
|
+
attr_accessor :heads
|
11
|
+
attr_accessor :accel3d
|
12
|
+
attr_accessor :accel2d
|
13
|
+
|
14
|
+
# Initializes a new video model device. If an XML string is
|
15
|
+
# given, it will be used to attempt to initialize the attributes.
|
16
|
+
def initialize(xml=nil)
|
17
|
+
load!(xml) if xml
|
18
|
+
end
|
19
|
+
|
20
|
+
# Attempts to initialize object attributes based on the XML
|
21
|
+
# strings given.
|
22
|
+
def load!(xml)
|
23
|
+
xml = Nokogiri::XML(xml).root if !xml.is_a?(Nokogiri::XML::Element)
|
24
|
+
try(xml.xpath("//model[@type]"), :preserve => true) { |result| self.type = result["type"].to_sym }
|
25
|
+
try(xml.xpath("//model[@vram]"), :preserve => true) { |result| self.vram = result["vram"] }
|
26
|
+
try(xml.xpath("//model[@heads]"), :preserve => true) { |result| self.heads = result["heads"] }
|
27
|
+
try(xml.xpath("//model/acceleration")) do |result|
|
28
|
+
self.accel3d = result["accel3d"] == "yes"
|
29
|
+
self.accel2d = result["accel2d"] == "yes"
|
30
|
+
end
|
31
|
+
|
32
|
+
raise_if_unparseables(xml.xpath("//model/*"))
|
33
|
+
end
|
34
|
+
|
35
|
+
# Returns the XML representation of this device.
|
36
|
+
def to_xml(xml=Nokogiri::XML::Builder.new)
|
37
|
+
options = { :type => type }
|
38
|
+
options[:vram] = vram if vram
|
39
|
+
options[:heads] = heads if heads
|
40
|
+
|
41
|
+
xml.model(options) do |m|
|
42
|
+
a3d = accel3d ? "yes" : "no"
|
43
|
+
a2d = accel2d ? "yes" : "no"
|
44
|
+
|
45
|
+
m.acceleration(:accel3d => a3d, :accel2d => a2d)
|
46
|
+
end
|
47
|
+
|
48
|
+
xml.to_xml
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|