virt 0.1.0 → 0.2.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/README.rdoc CHANGED
@@ -50,7 +50,8 @@ for full API please visit http://rdoc.info/github/ohadlevy/virt
50
50
 
51
51
  puts guest.mac
52
52
 
53
- guest.stop
53
+ guest.shutdown # initiate a shutdown
54
+ guest.poweroff # forces a shutdown
54
55
  Many more options exists, make sure checkout the api/tests
55
56
 
56
57
  ==== list of host bridges
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/lib/virt/guest.rb CHANGED
@@ -1,21 +1,22 @@
1
1
  module Virt
2
2
  class Guest
3
3
  include Virt::Util
4
- attr_reader :name, :xml_desc
5
- attr_accessor :memory, :vcpu, :arch, :volume, :interface, :template_path
4
+ attr_reader :name, :xml_desc, :arch, :current_memory, :type, :boot_device, :machine
5
+ attr_accessor :memory, :vcpu, :volume, :interface, :template_path
6
6
 
7
7
  def initialize options = {}
8
- @connection = Virt.connection
9
- @name = options[:name] || raise("Must provide a name")
10
- # If our domain exists, we ignore the provided options and defaults
11
- fetch_guest
12
- @memory ||= options[:memory] || default_memory_size
13
- @vcpu ||= options[:vcpu] || default_vcpu_count
14
- @arch ||= options[:arch] || default_arch
15
-
16
- @template_path = options[:template_path] || default_template_path
17
- @volume = Volume.new options
18
- @interface = Interface.new options.merge({:mac => @mac})
8
+ @connection = Virt.connection
9
+ @name = options[:name] || raise("Must provide a name")
10
+
11
+ # If our domain exists, we ignore the provided options and defaults
12
+ fetch_guest
13
+ @memory ||= options[:memory] || default_memory_size
14
+ @vcpu ||= options[:vcpu] || default_vcpu_count
15
+ @arch ||= options[:arch] || default_arch
16
+
17
+ @template_path = options[:template_path] || default_template_path
18
+ @volume = Volume.new options
19
+ @interface ||= Interface.new options
19
20
  end
20
21
 
21
22
  def new?
@@ -37,7 +38,7 @@ module Virt
37
38
  def running?
38
39
  return false if new?
39
40
  @domain.active?
40
- rescue
41
+ rescue
41
42
  # some versions of libvirt do not support checking for active state
42
43
  @connection.connection.list_domains.each do |did|
43
44
  return true if @connection.connection.lookup_domain_by_id(did).name == name
@@ -45,26 +46,51 @@ module Virt
45
46
  false
46
47
  end
47
48
 
48
- def stop
49
+ def stop(force=false)
49
50
  raise "Guest not created, can't stop" if new?
50
- @domain.destroy
51
+ force ? @domain.destroy : @domain.shutdown
51
52
  !running?
52
53
  rescue Libvirt::Error
53
54
  # domain is not running
54
55
  true
55
56
  end
56
57
 
58
+ def shutdown
59
+ stop
60
+ end
61
+
62
+ def poweroff
63
+ stop(true)
64
+ end
65
+
57
66
  def destroy
58
67
  return true if new?
59
- stop if running?
68
+ stop(true) if running?
60
69
  @domain = @domain.undefine
61
70
  new?
62
71
  end
63
72
 
73
+ def reboot
74
+ raise "Guest not running, can't reboot" if new? or !running?
75
+ @domain.reboot
76
+ end
77
+
64
78
  def uuid
65
79
  @domain.uuid unless new?
66
80
  end
67
81
 
82
+ def arch= value
83
+ @arch = value == "i386" ? "i686" : value
84
+ end
85
+
86
+ def to_s
87
+ name.to_s
88
+ end
89
+
90
+ def <=> other
91
+ self.name <=> other.name
92
+ end
93
+
68
94
  private
69
95
 
70
96
  def fetch_guest
@@ -75,12 +101,25 @@ module Virt
75
101
 
76
102
  def fetch_info
77
103
  return if @domain.nil?
78
- @xml_desc = @domain.xml_desc
79
- @memory = @domain.max_memory
80
- @vcpu = document("domain/vcpu")
81
- @arch = document("domain/os/type", "arch")
82
- @mac = document("domain/devices/interface/mac", "address")
83
- @interface.mac = @mac if @interface
104
+ @xml_desc = @domain.xml_desc
105
+ @memory = @domain.max_memory
106
+ @current_memory = document("domain/currentMemory") if running?
107
+ @type = document("domain", "type")
108
+ @vcpu = document("domain/vcpu")
109
+ @arch = document("domain/os/type", "arch")
110
+ @machine = document("domain/os/type", "machine")
111
+ @boot_device = document("domain/os/boot", "dev")
112
+
113
+ # do we have a NIC?
114
+ network_type = document("domain/devices/interface", "type") rescue nil
115
+
116
+ unless network_type.nil?
117
+ @interface ||= Interface.new
118
+ @interface.type = network_type
119
+ @interface.mac = document("domain/devices/interface/mac", "address")
120
+ @interface.device = document("domain/devices/interface/source", "bridge") if @interface.type == "bridge"
121
+ @interface.network = document("domain/devices/interface/source", "network") if @interface.type == "network"
122
+ end
84
123
  end
85
124
 
86
125
  def default_memory_size
@@ -1,6 +1,6 @@
1
1
  module Virt
2
2
  class Interface
3
- attr_accessor :mac, :model, :type, :device
3
+ attr_accessor :mac, :model, :type, :device, :network
4
4
 
5
5
  def initialize options = {}
6
6
  @connection = Virt.connection
@@ -8,6 +8,7 @@ module Virt
8
8
  @type = options[:type] || default_type
9
9
  @model = options[:model] || default_model
10
10
  @mac = options[:mac]
11
+ @network = options[:network]
11
12
  end
12
13
 
13
14
  def new?
data/lib/virt/volume.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Virt
2
2
  class Volume
3
3
  include Virt::Util
4
- attr_reader :name, :pool, :path, :type, :allocated_size, :size, :template_path, :key
4
+ attr_reader :name, :pool, :type, :allocated_size, :size, :template_path, :key
5
5
 
6
6
  def initialize options = {}
7
7
  @connection = Virt.connection
@@ -10,7 +10,7 @@ module Virt
10
10
  @allocated_size = options[:allocated_size] || default_allocated_size
11
11
  @template_path = options[:template_path] || default_template_path
12
12
  @size = options[:size] || default_size
13
- @pool = @connection.host.storage_pool(options[:pool] || "default")
13
+ @pool = options[:pool].nil? ? @connection.host.storage_pools.first : @connection.host.storage_pool(options[:pool])
14
14
  fetch_volume
15
15
  end
16
16
 
@@ -46,7 +46,7 @@
46
46
  <target port='0'/>
47
47
  </console>
48
48
  <input type='mouse' bus='ps2'/>
49
- <graphics type='vnc' port='-1' autoport='yes' keymap='en-us'/>
49
+ <graphics type='vnc' port='-1' autoport='yes'/>
50
50
  <video>
51
51
  <model type='cirrus' vram='9216' heads='1'/>
52
52
  </video>
data/test/guest_test.rb CHANGED
@@ -9,6 +9,11 @@ class Virt::GuestTest < Test::Unit::TestCase
9
9
  @guest = Virt::Guest.new({:name => "test-host-#{Time.now.to_i}"})
10
10
  end
11
11
 
12
+ def teardown
13
+ @guest.destroy
14
+ Virt.connection.disconnect unless Virt.connection.closed?
15
+ end
16
+
12
17
  def test_should_be_new
13
18
  assert @guest.new?
14
19
  assert @guest.interface.new?
@@ -19,7 +24,14 @@ class Virt::GuestTest < Test::Unit::TestCase
19
24
  assert @guest.save
20
25
  assert !@guest.interface.new?
21
26
  assert_not_nil @guest.interface.mac
22
- @guest.destroy
27
+ end
28
+
29
+ def test_should_be_able_to_save_32bit_guest
30
+ @guest.arch = "i386"
31
+ assert_equal @guest.arch, "i686"
32
+ assert @guest.save
33
+ assert !@guest.interface.new?
34
+ assert_not_nil @guest.interface.mac
23
35
  end
24
36
 
25
37
  def test_should_be_able_to_destroy
data/virt.gemspec CHANGED
@@ -4,14 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{virt}
8
- s.version = "0.1.0"
7
+ s.name = "virt"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ohad Levy"]
12
- s.date = %q{2011-01-31}
13
- s.description = %q{Simplied interface to use ruby the libvirt ruby library}
14
- s.email = %q{ohadlevy@gmail.com}
12
+ s.date = "2011-11-15"
13
+ s.description = "Simplied interface to use ruby the libvirt ruby library"
14
+ s.email = "ohadlevy@gmail.com"
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE.txt",
17
17
  "README.rdoc"
@@ -43,11 +43,11 @@ Gem::Specification.new do |s|
43
43
  "test/volume_test.rb",
44
44
  "virt.gemspec"
45
45
  ]
46
- s.homepage = %q{https://github.com/ohadlevy/virt}
46
+ s.homepage = "https://github.com/ohadlevy/virt"
47
47
  s.licenses = ["GPLv3"]
48
48
  s.require_paths = ["lib"]
49
- s.rubygems_version = %q{1.3.7}
50
- s.summary = %q{Simple to use ruby interface to libvirt}
49
+ s.rubygems_version = "1.7.2"
50
+ s.summary = "Simple to use ruby interface to libvirt"
51
51
  s.test_files = [
52
52
  "test/connection_test.rb",
53
53
  "test/guest_test.rb",
@@ -59,7 +59,6 @@ Gem::Specification.new do |s|
59
59
  ]
60
60
 
61
61
  if s.respond_to? :specification_version then
62
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
63
62
  s.specification_version = 3
64
63
 
65
64
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virt
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
5
- prerelease: false
4
+ hash: 23
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ohad Levy
@@ -15,12 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-31 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-11-15 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
22
- prerelease: false
23
21
  name: shoulda
22
+ type: :development
24
23
  version_requirements: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
@@ -32,11 +31,11 @@ dependencies:
32
31
  - 11
33
32
  - 3
34
33
  version: 2.11.3
34
+ prerelease: false
35
35
  requirement: *id001
36
- type: :development
37
36
  - !ruby/object:Gem::Dependency
38
- prerelease: false
39
37
  name: bundler
38
+ type: :development
40
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
41
40
  none: false
42
41
  requirements:
@@ -48,11 +47,11 @@ dependencies:
48
47
  - 0
49
48
  - 0
50
49
  version: 1.0.0
50
+ prerelease: false
51
51
  requirement: *id002
52
- type: :development
53
52
  - !ruby/object:Gem::Dependency
54
- prerelease: false
55
53
  name: jeweler
54
+ type: :development
56
55
  version_requirements: &id003 !ruby/object:Gem::Requirement
57
56
  none: false
58
57
  requirements:
@@ -64,11 +63,11 @@ dependencies:
64
63
  - 5
65
64
  - 2
66
65
  version: 1.5.2
66
+ prerelease: false
67
67
  requirement: *id003
68
- type: :development
69
68
  - !ruby/object:Gem::Dependency
70
- prerelease: false
71
69
  name: rcov
70
+ type: :development
72
71
  version_requirements: &id004 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
@@ -80,8 +79,8 @@ dependencies:
80
79
  - 9
81
80
  - 8
82
81
  version: 0.9.8
82
+ prerelease: false
83
83
  requirement: *id004
84
- type: :development
85
84
  description: Simplied interface to use ruby the libvirt ruby library
86
85
  email: ohadlevy@gmail.com
87
86
  executables: []
@@ -117,7 +116,6 @@ files:
117
116
  - test/test_helper.rb
118
117
  - test/volume_test.rb
119
118
  - virt.gemspec
120
- has_rdoc: true
121
119
  homepage: https://github.com/ohadlevy/virt
122
120
  licenses:
123
121
  - GPLv3
@@ -147,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
145
  requirements: []
148
146
 
149
147
  rubyforge_project:
150
- rubygems_version: 1.3.7
148
+ rubygems_version: 1.7.2
151
149
  signing_key:
152
150
  specification_version: 3
153
151
  summary: Simple to use ruby interface to libvirt