fog-libvirt 0.12.2 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -3
  3. data/fog-libvirt.gemspec +4 -5
  4. data/lib/fog/libvirt/compute.rb +15 -26
  5. data/lib/fog/libvirt/models/compute/network.rb +11 -0
  6. data/lib/fog/libvirt/models/compute/pool.rb +14 -0
  7. data/lib/fog/libvirt/models/compute/server.rb +41 -150
  8. data/lib/fog/libvirt/models/compute/util/util.rb +2 -10
  9. data/lib/fog/libvirt/models/compute/volume.rb +41 -2
  10. data/lib/fog/libvirt/requests/compute/clone_volume.rb +7 -5
  11. data/lib/fog/libvirt/requests/compute/create_domain.rb +6 -4
  12. data/lib/fog/libvirt/requests/compute/create_volume.rb +6 -3
  13. data/lib/fog/libvirt/requests/compute/define_domain.rb +6 -4
  14. data/lib/fog/libvirt/requests/compute/define_pool.rb +6 -3
  15. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +6 -4
  16. data/lib/fog/libvirt/requests/compute/destroy_network.rb +6 -4
  17. data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +4 -5
  18. data/lib/fog/libvirt/requests/compute/get_node_info.rb +6 -3
  19. data/lib/fog/libvirt/requests/compute/libversion.rb +6 -4
  20. data/lib/fog/libvirt/requests/compute/list_domains.rb +27 -31
  21. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +6 -14
  22. data/lib/fog/libvirt/requests/compute/list_networks.rb +6 -24
  23. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +6 -3
  24. data/lib/fog/libvirt/requests/compute/list_pools.rb +20 -42
  25. data/lib/fog/libvirt/requests/compute/list_volumes.rb +16 -36
  26. data/lib/fog/libvirt/requests/compute/pool_action.rb +6 -4
  27. data/lib/fog/libvirt/requests/compute/update_autostart.rb +6 -4
  28. data/lib/fog/libvirt/requests/compute/update_display.rb +6 -5
  29. data/lib/fog/libvirt/requests/compute/upload_volume.rb +6 -3
  30. data/lib/fog/libvirt/requests/compute/vm_action.rb +6 -4
  31. data/lib/fog/libvirt/requests/compute/volume_action.rb +6 -4
  32. data/lib/fog/libvirt/version.rb +1 -1
  33. data/minitests/test_helper.rb +1 -1
  34. data/tests/helper.rb +1 -1
  35. data/tests/helpers/formats_helper.rb +3 -2
  36. data/tests/helpers/formats_helper_tests.rb +8 -8
  37. data/tests/helpers/mock_helper.rb +1 -1
  38. data/tests/libvirt/models/compute/network_tests.rb +14 -2
  39. data/tests/libvirt/models/compute/nic_tests.rb +2 -1
  40. data/tests/libvirt/models/compute/pools_tests.rb +6 -6
  41. data/tests/libvirt/models/compute/server_tests.rb +53 -3
  42. data/tests/libvirt/models/compute/volume_tests.rb +21 -1
  43. data/tests/libvirt/models/compute/volumes_tests.rb +2 -0
  44. data/tests/libvirt/requests/compute/list_pools_tests.rb +1 -1
  45. metadata +38 -43
  46. data/lib/fog/libvirt/models/compute/templates/network.xml.erb +0 -6
  47. data/lib/fog/libvirt/models/compute/templates/pool.xml.erb +0 -6
  48. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +0 -34
  49. data/lib/fog/libvirt/requests/compute/mock_files/domain.xml +0 -40
  50. data/minitests/server/server_test.rb +0 -64
@@ -1,16 +1,18 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def destroy_network(uuid)
6
6
  client.lookup_network_by_uuid(uuid).destroy
7
7
  end
8
8
  end
9
9
 
10
+ class Real
11
+ include Shared
12
+ end
13
+
10
14
  class Mock
11
- def destroy_network(uuid)
12
- true
13
- end
15
+ include Shared
14
16
  end
15
17
  end
16
18
  end
@@ -10,6 +10,7 @@ module Fog
10
10
  end
11
11
 
12
12
  class Mock
13
+ # Not implemented by the test driver
13
14
  def dhcp_leases(uuid, mac, flags = 0)
14
15
  leases1 = {
15
16
  'aa:bb:cc:dd:ee:ff' => [
@@ -23,13 +24,11 @@ module Fog
23
24
  ]
24
25
  }
25
26
  networks = {
26
- # should match mock net uuid from list_networks.rb
27
- 'a29146ea-39b2-412d-8f53-239eef117a32' => leases1,
27
+ # should match the default network from the test connection
28
+ 'dd8fe884-6c02-601e-7551-cca97df1c5df' => leases1,
28
29
  'fbd4ac68-cbea-4f95-86ed-22953fd92384' => leases2
29
30
  }
30
- if !networks[uuid].nil?
31
- return networks[uuid][mac]
32
- end
31
+ networks.dig(uuid, mac)
33
32
  end
34
33
  end
35
34
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def get_node_info
6
6
  node_hash = Hash.new
7
7
  node_info = client.node_get_info
@@ -28,9 +28,12 @@ module Fog
28
28
  end
29
29
  end
30
30
 
31
+ class Real
32
+ include Shared
33
+ end
34
+
31
35
  class Mock
32
- def get_node_info
33
- end
36
+ include Shared
34
37
  end
35
38
  end
36
39
  end
@@ -2,16 +2,18 @@
2
2
  module Fog
3
3
  module Libvirt
4
4
  class Compute
5
- class Real
5
+ module Shared
6
6
  def libversion()
7
7
  client.libversion
8
8
  end
9
9
  end
10
10
 
11
+ class Real
12
+ include Shared
13
+ end
14
+
11
15
  class Mock
12
- def libversion()
13
- return 1002009
14
- end
16
+ include Shared
15
17
  end
16
18
  end
17
19
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def list_domains(filter = { })
6
6
  data=[]
7
7
 
@@ -25,9 +25,7 @@ module Fog
25
25
  rescue ::Libvirt::RetrieveError, ::Libvirt::Error
26
26
  nil
27
27
  end
28
- end
29
28
 
30
- module Shared
31
29
  private
32
30
 
33
31
  def domain_display xml
@@ -48,6 +46,24 @@ module Fog
48
46
  xml_elements(xml, "domain/os/boot", "dev")
49
47
  end
50
48
 
49
+ def firmware(xml)
50
+ firmware_from_loader = xml_elements(xml, "domain/os/loader", "type").first
51
+
52
+ case firmware_from_loader
53
+ when 'pflash'
54
+ 'efi'
55
+ when 'rom'
56
+ 'bios'
57
+ else
58
+ xml_elements(xml, "domain/os", "firmware").first || 'bios'
59
+ end
60
+ end
61
+
62
+ # we rely on the fact that the secure attribute is only present when secure boot is enabled
63
+ def secure_boot_enabled?(xml)
64
+ xml_elements(xml, "domain/os/loader", "secure").first == 'yes'
65
+ end
66
+
51
67
  def domain_interfaces xml
52
68
  ifs = xml_elements(xml, "domain/devices/interface")
53
69
  ifs.map { |i|
@@ -80,7 +96,9 @@ module Fog
80
96
  :boot_order => boot_order(dom.xml_desc),
81
97
  :nics => domain_interfaces(dom.xml_desc),
82
98
  :volumes_path => domain_volumes(dom.xml_desc),
83
- :state => states[dom.info.state]
99
+ :state => states[dom.info.state],
100
+ :firmware => firmware(dom.xml_desc),
101
+ :secure_boot => secure_boot_enabled?(dom.xml_desc),
84
102
  }
85
103
  rescue ::Libvirt::RetrieveError, ::Libvirt::Error
86
104
  # Catch libvirt exceptions to avoid race conditions involving
@@ -90,34 +108,12 @@ module Fog
90
108
  end
91
109
  end
92
110
 
93
- class Mock
94
- def list_domains(filter = { })
95
- dom1 = mock_domain 'fog-dom1'
96
- dom2 = mock_domain 'fog-dom2'
97
- dom3 = mock_domain 'a-fog-dom3'
98
- [dom1, dom2, dom3]
99
- end
111
+ class Real
112
+ include Shared
113
+ end
100
114
 
101
- def mock_domain name
102
- xml = read_xml 'domain.xml'
103
- {
104
- :id => "dom.uuid",
105
- :uuid => "dom.uuid",
106
- :name => name,
107
- :max_memory_size => 8,
108
- :cputime => 7,
109
- :memory_size => 6,
110
- :cpus => 5,
111
- :autostart => false,
112
- :os_type => "hvm",
113
- :active => false,
114
- :vnc_port => 5910,
115
- :boot_order => boot_order(xml),
116
- :nics => domain_interfaces(xml),
117
- :volumes_path => domain_volumes(xml),
118
- :state => 'shutoff'
119
- }
120
- end
115
+ class Mock
116
+ include Shared
121
117
  end
122
118
  end
123
119
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def list_interfaces(filter = { })
6
6
  data=[]
7
7
  if filter.keys.empty?
@@ -37,20 +37,12 @@ module Fog
37
37
  end
38
38
  end
39
39
 
40
- class Mock
41
- def list_interfaces(filters={ })
42
- if1 = mock_interface 'if1'
43
- if2 = mock_interface 'if2'
44
- [if1, if2]
45
- end
40
+ class Real
41
+ include Shared
42
+ end
46
43
 
47
- def mock_interface name
48
- {
49
- :mac => 'aa:bb:cc:dd:ee:ff',
50
- :name => name,
51
- :active => true
52
- }
53
- end
44
+ class Mock
45
+ include Shared
54
46
  end
55
47
  end
56
48
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def list_networks(filter = { })
6
6
  data=[]
7
7
  if filter.keys.empty?
@@ -43,30 +43,12 @@ module Fog
43
43
  end
44
44
  end
45
45
 
46
- class Mock
47
- def list_networks(filter={ })
48
- networks = [ {
49
- :uuid => 'a29146ea-39b2-412d-8f53-239eef117a32',
50
- :name => 'net1',
51
- :bridge_name => 'virbr0'
52
- },
53
- {
54
- :uuid => 'fbd4ac68-cbea-4f95-86ed-22953fd92384',
55
- :name => 'net2',
56
- :bridge_name => 'virbr1'
57
- }
58
- ]
59
- return networks if filter.empty?
46
+ class Real
47
+ include Shared
48
+ end
60
49
 
61
- case filter.keys.first
62
- when :uuid
63
- [networks.find(:uuid => filter[:uuid]).first]
64
- when :name
65
- [networks.find(:name => filter[:name]).first]
66
- else
67
- networks
68
- end
69
- end
50
+ class Mock
51
+ include Shared
70
52
  end
71
53
  end
72
54
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def list_pool_volumes(uuid)
6
6
  pool = client.lookup_storage_pool_by_uuid uuid
7
7
  pool.list_volumes.map do |volume_name|
@@ -10,9 +10,12 @@ module Fog
10
10
  end
11
11
  end
12
12
 
13
+ class Real
14
+ include Shared
15
+ end
16
+
13
17
  class Mock
14
- def list_pool_volumes(uuid)
15
- end
18
+ include Shared
16
19
  end
17
20
  end
18
21
  end
@@ -2,29 +2,6 @@ module Fog
2
2
  module Libvirt
3
3
  class Compute
4
4
  module Shared
5
- private
6
-
7
- def pool_to_attributes(pool, include_inactive = nil)
8
- return nil unless pool.active? || include_inactive
9
-
10
- states=[:inactive, :building, :running, :degrated, :inaccessible]
11
- {
12
- :uuid => pool.uuid,
13
- :persistent => pool.persistent?,
14
- :autostart => pool.autostart?,
15
- :active => pool.active?,
16
- :name => pool.name,
17
- :allocation => pool.info.allocation,
18
- :capacity => pool.info.capacity,
19
- :num_of_volumes => pool.active? ? pool.num_of_volumes : nil,
20
- :state => states[pool.info.state]
21
- }
22
- end
23
- end
24
-
25
- class Real
26
- include Shared
27
-
28
5
  def list_pools(filter = { })
29
6
  data=[]
30
7
  if filter.key?(:name)
@@ -52,31 +29,32 @@ module Fog
52
29
  rescue ::Libvirt::RetrieveError
53
30
  nil
54
31
  end
55
- end
56
32
 
57
- class Mock
58
- include Shared
59
-
60
- def list_pools(filter = { })
61
- pool1 = mock_pool 'pool1'
62
- pool2 = mock_pool 'pool1'
63
- [pool1, pool2]
64
- end
33
+ def pool_to_attributes(pool, include_inactive = nil)
34
+ return nil unless pool.active? || include_inactive
65
35
 
66
- def mock_pool name
36
+ states=[:inactive, :building, :running, :degrated, :inaccessible]
67
37
  {
68
- :uuid => 'pool.uuid',
69
- :persistent => true,
70
- :autostart => true,
71
- :active => true,
72
- :name => name,
73
- :allocation => 123456789,
74
- :capacity => 123456789,
75
- :num_of_volumes => 3,
76
- :state => :running
38
+ :uuid => pool.uuid,
39
+ :persistent => pool.persistent?,
40
+ :autostart => pool.autostart?,
41
+ :active => pool.active?,
42
+ :name => pool.name,
43
+ :allocation => pool.info.allocation,
44
+ :capacity => pool.info.capacity,
45
+ :num_of_volumes => pool.active? ? pool.num_of_volumes : nil,
46
+ :state => states[pool.info.state]
77
47
  }
78
48
  end
79
49
  end
50
+
51
+ class Real
52
+ include Shared
53
+ end
54
+
55
+ class Mock
56
+ include Shared
57
+ end
80
58
  end
81
59
  end
82
60
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def list_volumes(filter = { })
6
6
  data = []
7
7
  if filter.keys.empty?
@@ -29,16 +29,16 @@ module Fog
29
29
  return nil if format_type == "dir"
30
30
 
31
31
  begin
32
- {
33
- :pool_name => vol.pool.name,
34
- :key => vol.key,
35
- :id => vol.key,
36
- :path => vol.path,
37
- :name => vol.name,
38
- :format_type => format_type,
39
- :allocation => bytes_to_gb(vol.info.allocation),
40
- :capacity => bytes_to_gb(vol.info.capacity),
41
- }
32
+ {
33
+ :pool_name => vol.pool.name,
34
+ :key => vol.key,
35
+ :id => vol.key,
36
+ :path => vol.path,
37
+ :name => vol.name,
38
+ :format_type => format_type,
39
+ :allocation => bytes_to_gb(vol.info.allocation),
40
+ :capacity => bytes_to_gb(vol.info.capacity),
41
+ }
42
42
  rescue ::Libvirt::RetrieveError, ::Libvirt::Error
43
43
  return nil # If there are issues during stat of volume file
44
44
  end
@@ -74,32 +74,12 @@ module Fog
74
74
  end
75
75
  end
76
76
 
77
- class Mock
78
- def list_volumes(filters={ })
79
- vol1 = mock_volume 'vol1'
80
- vol2 = mock_volume 'vol2'
81
- vols = [vol1, vol2]
82
-
83
- if filters.keys.empty?
84
- return vols
85
- end
86
-
87
- key = filters.keys.first
88
- vols.select { |v| v[key] == filters[key] }
89
- end
77
+ class Real
78
+ include Shared
79
+ end
90
80
 
91
- def mock_volume name
92
- {
93
- :pool_name => 'vol.pool.name',
94
- :key => "vol.#{name}", # needs to match id
95
- :id => "vol.#{name}",
96
- :path => "path/to/disk", # used by in mock_files/domain.xml
97
- :name => name,
98
- :format_type => 'raw',
99
- :allocation => 123,
100
- :capacity => 123,
101
- }
102
- end
81
+ class Mock
82
+ include Shared
103
83
  end
104
84
  end
105
85
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def pool_action(uuid, action)
6
6
  pool = client.lookup_storage_pool_by_uuid uuid
7
7
  pool.send(action)
@@ -9,10 +9,12 @@ module Fog
9
9
  end
10
10
  end
11
11
 
12
+ class Real
13
+ include Shared
14
+ end
15
+
12
16
  class Mock
13
- def pool_action(uuid, action)
14
- true
15
- end
17
+ include Shared
16
18
  end
17
19
  end
18
20
  end
@@ -1,17 +1,19 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def update_autostart(uuid, value)
6
6
  domain = client.lookup_domain_by_uuid(uuid)
7
7
  domain.autostart = value
8
8
  end
9
9
  end
10
10
 
11
+ class Real
12
+ include Shared
13
+ end
14
+
11
15
  class Mock
12
- def update_autostart(uuid, value)
13
- value
14
- end
16
+ include Shared
15
17
  end
16
18
  end
17
19
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def update_display(options = { })
6
6
  raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid
7
7
 
@@ -25,11 +25,12 @@ module Fog
25
25
  end
26
26
  end
27
27
 
28
+ class Real
29
+ include Shared
30
+ end
31
+
28
32
  class Mock
29
- def update_display(options = { })
30
- raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid
31
- true
32
- end
33
+ include Shared
33
34
  end
34
35
  end
35
36
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def upload_volume(pool_name, volume_name, file_path)
6
6
  volume = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(volume_name)
7
7
  stream = client.stream
@@ -22,9 +22,12 @@ module Fog
22
22
  end
23
23
  end
24
24
 
25
+ class Real
26
+ include Shared
27
+ end
28
+
25
29
  class Mock
26
- def upload_volume(pool_name, volume_name, file_path)
27
- end
30
+ include Shared
28
31
  end
29
32
  end
30
33
  end
@@ -1,7 +1,7 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def vm_action(uuid, action, *params)
6
6
  domain = client.lookup_domain_by_uuid(uuid)
7
7
  domain.send(action, *params)
@@ -9,10 +9,12 @@ module Fog
9
9
  end
10
10
  end
11
11
 
12
+ class Real
13
+ include Shared
14
+ end
15
+
12
16
  class Mock
13
- def vm_action(uuid, action, *params)
14
- true
15
- end
17
+ include Shared
16
18
  end
17
19
  end
18
20
  end
@@ -1,17 +1,19 @@
1
1
  module Fog
2
2
  module Libvirt
3
3
  class Compute
4
- class Real
4
+ module Shared
5
5
  def volume_action(key, action, options={})
6
6
  get_volume({:key => key}, true).send(action)
7
7
  true
8
8
  end
9
9
  end
10
10
 
11
+ class Real
12
+ include Shared
13
+ end
14
+
11
15
  class Mock
12
- def volume_action(action, options={})
13
- true
14
- end
16
+ include Shared
15
17
  end
16
18
  end
17
19
  end
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Libvirt
3
- VERSION = '0.12.2'
3
+ VERSION = '0.13.1'
4
4
  end
5
5
  end
@@ -14,5 +14,5 @@ require 'fog/libvirt'
14
14
 
15
15
  Fog.mock!
16
16
  Fog.credentials = {
17
- :libvirt_uri => 'qemu://libvirt/system',
17
+ :libvirt_uri => 'test:///default',
18
18
  }.merge(Fog.credentials)
data/tests/helper.rb CHANGED
@@ -3,7 +3,7 @@ ENV['FOG_CREDENTIAL'] = ENV['FOG_CREDENTIAL'] || 'default'
3
3
 
4
4
  require 'fog/libvirt'
5
5
 
6
- Excon.defaults.merge!(debug_request: true, debug_response: true)
6
+ Excon.defaults.merge!(:debug_request => true, :debug_response => true)
7
7
 
8
8
  require File.expand_path(File.join(File.dirname(__FILE__), 'helpers', 'mock_helper'))
9
9
 
@@ -7,6 +7,7 @@ require 'fog/schema/data_validator'
7
7
  # allows both nil.is_a?(Fog::Nullable::String) and ''.is_a?(Fog::Nullable::String)
8
8
  module Fog
9
9
  module Boolean; end
10
+
10
11
  module Nullable
11
12
  module Boolean; end
12
13
  module Integer; end
@@ -86,9 +87,9 @@ module Shindo
86
87
  def formats(format, strict = true)
87
88
  test('has proper format') do
88
89
  if strict
89
- options = { allow_extra_keys: false, allow_optional_rules: true }
90
+ options = { :allow_extra_keys => false, :allow_optional_rules => true }
90
91
  else
91
- options = { allow_extra_keys: true, allow_optional_rules: true }
92
+ options = { :allow_extra_keys => true, :allow_optional_rules => true }
92
93
  end
93
94
  validator = Fog::Schema::DataValidator.new
94
95
  valid = validator.validate(yield, format, options)