fog-libvirt 0.5.0 → 0.9.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.
Files changed (70) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +1 -1
  3. data/fog-libvirt.gemspec +3 -3
  4. data/lib/fog/bin/libvirt.rb +1 -1
  5. data/lib/fog/libvirt.rb +1 -3
  6. data/lib/fog/libvirt/compute.rb +12 -11
  7. data/lib/fog/libvirt/models/compute/README.md +16 -0
  8. data/lib/fog/libvirt/models/compute/interface.rb +2 -2
  9. data/lib/fog/libvirt/models/compute/interfaces.rb +3 -3
  10. data/lib/fog/libvirt/models/compute/network.rb +3 -3
  11. data/lib/fog/libvirt/models/compute/networks.rb +3 -3
  12. data/lib/fog/libvirt/models/compute/nic.rb +2 -2
  13. data/lib/fog/libvirt/models/compute/nics.rb +3 -3
  14. data/lib/fog/libvirt/models/compute/node.rb +2 -2
  15. data/lib/fog/libvirt/models/compute/nodes.rb +3 -3
  16. data/lib/fog/libvirt/models/compute/pool.rb +2 -2
  17. data/lib/fog/libvirt/models/compute/pools.rb +3 -3
  18. data/lib/fog/libvirt/models/compute/server.rb +23 -8
  19. data/lib/fog/libvirt/models/compute/servers.rb +3 -3
  20. data/lib/fog/libvirt/models/compute/templates/server.xml.erb +65 -0
  21. data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +8 -4
  22. data/lib/fog/libvirt/models/compute/util/uri.rb +2 -2
  23. data/lib/fog/libvirt/models/compute/util/util.rb +2 -2
  24. data/lib/fog/libvirt/models/compute/volume.rb +11 -9
  25. data/lib/fog/libvirt/models/compute/volumes.rb +3 -3
  26. data/lib/fog/libvirt/requests/compute/clone_volume.rb +3 -3
  27. data/lib/fog/libvirt/requests/compute/create_domain.rb +2 -2
  28. data/lib/fog/libvirt/requests/compute/create_volume.rb +2 -2
  29. data/lib/fog/libvirt/requests/compute/define_domain.rb +2 -2
  30. data/lib/fog/libvirt/requests/compute/define_pool.rb +2 -2
  31. data/lib/fog/libvirt/requests/compute/destroy_interface.rb +2 -2
  32. data/lib/fog/libvirt/requests/compute/destroy_network.rb +2 -2
  33. data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +2 -2
  34. data/lib/fog/libvirt/requests/compute/get_node_info.rb +2 -2
  35. data/lib/fog/libvirt/requests/compute/libversion.rb +2 -2
  36. data/lib/fog/libvirt/requests/compute/list_domains.rb +9 -3
  37. data/lib/fog/libvirt/requests/compute/list_interfaces.rb +2 -2
  38. data/lib/fog/libvirt/requests/compute/list_networks.rb +11 -3
  39. data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +2 -2
  40. data/lib/fog/libvirt/requests/compute/list_pools.rb +2 -2
  41. data/lib/fog/libvirt/requests/compute/list_volumes.rb +16 -8
  42. data/lib/fog/libvirt/requests/compute/pool_action.rb +2 -2
  43. data/lib/fog/libvirt/requests/compute/update_autostart.rb +18 -0
  44. data/lib/fog/libvirt/requests/compute/update_display.rb +2 -2
  45. data/lib/fog/libvirt/requests/compute/upload_volume.rb +2 -2
  46. data/lib/fog/libvirt/requests/compute/vm_action.rb +2 -2
  47. data/lib/fog/libvirt/requests/compute/volume_action.rb +2 -2
  48. data/lib/fog/libvirt/version.rb +1 -1
  49. data/minitests/server/server_test.rb +1 -1
  50. data/minitests/server/user_data_iso_test.rb +8 -11
  51. data/minitests/test_helper.rb +1 -1
  52. data/tests/helper.rb +1 -1
  53. data/tests/helpers/formats_helper.rb +58 -56
  54. data/tests/helpers/formats_helper_tests.rb +22 -25
  55. data/tests/helpers/mock_helper.rb +1 -1
  56. data/tests/helpers/succeeds_helper.rb +2 -2
  57. data/tests/libvirt/compute_tests.rb +2 -1
  58. data/tests/libvirt/models/compute/interface_tests.rb +1 -1
  59. data/tests/libvirt/models/compute/interfaces_tests.rb +1 -1
  60. data/tests/libvirt/models/compute/network_tests.rb +1 -1
  61. data/tests/libvirt/models/compute/networks_tests.rb +1 -1
  62. data/tests/libvirt/models/compute/nic_tests.rb +1 -1
  63. data/tests/libvirt/models/compute/pool_tests.rb +1 -1
  64. data/tests/libvirt/models/compute/pools_tests.rb +1 -1
  65. data/tests/libvirt/models/compute/server_tests.rb +4 -1
  66. data/tests/libvirt/models/compute/servers_tests.rb +1 -1
  67. data/tests/libvirt/models/compute/volume_tests.rb +1 -1
  68. data/tests/libvirt/models/compute/volumes_tests.rb +2 -1
  69. data/tests/libvirt/requests/compute/update_autostart_tests.rb +12 -0
  70. metadata +12 -16
@@ -5,8 +5,12 @@
5
5
  <target>
6
6
  <format type="<%= format_type %>"/>
7
7
  <permissions>
8
- <owner>0</owner>
9
- <group>0</group>
8
+ <% if owner -%>
9
+ <owner><%= owner %></owner>
10
+ <% end -%>
11
+ <% if group -%>
12
+ <group><%= group %></group>
13
+ <% end -%>
10
14
  <mode>0744</mode>
11
15
  <label>virt_image_t</label>
12
16
  </permissions>
@@ -16,8 +20,8 @@
16
20
  <path><%= backing_volume.path %></path>
17
21
  <format type="<%= backing_volume.format_type %>"/>
18
22
  <permissions>
19
- <owner>0</owner>
20
- <group>0</group>
23
+ <owner><%= owner %></owner>
24
+ <group><%= group %></group>
21
25
  <mode>0744</mode>
22
26
  <label>virt_image_t</label>
23
27
  </permissions>
@@ -2,8 +2,8 @@ require 'uri'
2
2
  require 'cgi'
3
3
 
4
4
  module Fog
5
- module Compute
6
- module LibvirtUtil
5
+ module Libvirt
6
+ module Util
7
7
  class URI
8
8
  attr_reader :uri
9
9
 
@@ -4,8 +4,8 @@ require 'ostruct'
4
4
  require 'securerandom'
5
5
 
6
6
  module Fog
7
- module Compute
8
- module LibvirtUtil
7
+ module Libvirt
8
+ module Util
9
9
  def xml_element(xml, path, attribute=nil)
10
10
  xml = Nokogiri::XML(xml)
11
11
  attribute.nil? ? (xml/path).first.text : (xml/path).first[attribute.to_sym]
@@ -2,11 +2,11 @@ require 'fog/core/model'
2
2
  require 'fog/libvirt/models/compute/util/util'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Volume < Fog::Model
8
8
  attr_reader :xml
9
- include Fog::Compute::LibvirtUtil
9
+ include Fog::Libvirt::Util
10
10
 
11
11
  identity :id, :aliases => 'key'
12
12
 
@@ -16,6 +16,8 @@ module Fog
16
16
  attribute :path
17
17
  attribute :capacity
18
18
  attribute :allocation
19
+ attribute :owner
20
+ attribute :group
19
21
  attribute :format_type
20
22
  attribute :backing_volume
21
23
 
@@ -106,18 +108,18 @@ module Fog
106
108
  :name => randomized_name,
107
109
  :capacity => "10G",
108
110
  :allocation => "1G",
111
+ :owner => nil,
112
+ :group => nil,
109
113
  }
110
114
  end
111
115
 
112
116
  def split_size_unit(text)
113
- if text.kind_of? Integer
114
- # if text is an integer, match will fail
115
- size = text
116
- unit = 'G'
117
- else
118
- matcher = text.match(/(\d+)(.+)/)
117
+ if (text.kind_of? String) && (matcher = text.match(/(\d+)(.+)/))
119
118
  size = matcher[1]
120
119
  unit = matcher[2]
120
+ else
121
+ size = text.to_i
122
+ unit = "G"
121
123
  end
122
124
  [size, unit]
123
125
  end
@@ -2,10 +2,10 @@ require 'fog/core/collection'
2
2
  require 'fog/libvirt/models/compute/volume'
3
3
 
4
4
  module Fog
5
- module Compute
6
- class Libvirt
5
+ module Libvirt
6
+ class Compute
7
7
  class Volumes < Fog::Collection
8
- model Fog::Compute::Libvirt::Volume
8
+ model Fog::Libvirt::Compute::Volume
9
9
 
10
10
  def all(filter = {})
11
11
  load(service.list_volumes(filter))
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def clone_volume (pool_name, xml, name)
6
6
  vol = client.lookup_storage_pool_by_name(pool_name).lookup_volume_by_name(name)
@@ -10,7 +10,7 @@ module Fog
10
10
 
11
11
  class Mock
12
12
  def clone_volume(pool_name, xml, name)
13
- Fog::Compute::Libvirt::Volume.new({:pool_name => pool_name, :xml => xml})
13
+ Fog::Libvirt::Compute::Volume.new({:pool_name => pool_name, :xml => xml})
14
14
  end
15
15
  end
16
16
  end
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def create_domain(xml)
6
6
  client.create_domain_xml(xml)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def create_volume(pool_name, xml)
6
6
  client.lookup_storage_pool_by_name(pool_name).create_vol_xml(xml)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def define_domain(xml)
6
6
  client.define_domain_xml(xml)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def define_pool(xml)
6
6
  client.define_storage_pool_xml(xml)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  #shutdown the interface
6
6
  def destroy_interface(uuid)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def destroy_network(uuid)
6
6
  client.lookup_network_by_uuid(uuid).destroy
@@ -1,8 +1,8 @@
1
1
  require 'socket'
2
2
 
3
3
  module Fog
4
- module Compute
5
- class Libvirt
4
+ module Libvirt
5
+ class Compute
6
6
  class Real
7
7
  def dhcp_leases(uuid, mac, flags = 0)
8
8
  client.lookup_network_by_uuid(uuid).dhcp_leases(mac, flags)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def get_node_info
6
6
  node_hash = Hash.new
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Fog
3
- module Compute
4
- class Libvirt
3
+ module Libvirt
4
+ class Compute
5
5
  class Real
6
6
  def libversion()
7
7
  client.libversion
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def list_domains(filter = { })
6
6
  data=[]
@@ -39,7 +39,13 @@ module Fog
39
39
  end
40
40
 
41
41
  def domain_volumes xml
42
- xml_elements(xml, "domain/devices/disk/source", "file")
42
+ vols_by_file = xml_elements(xml, "domain/devices/disk/source", "file")
43
+ vols_by_name = xml_elements(xml, "domain/devices/disk/source", "name")
44
+ vols = []
45
+ vols_by_file.zip(vols_by_name).each do |by_file,by_name|
46
+ vols.push(by_file.nil? ? by_name : by_file)
47
+ end
48
+ vols
43
49
  end
44
50
 
45
51
  def boot_order xml
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def list_interfaces(filter = { })
6
6
  data=[]
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def list_networks(filter = { })
6
6
  data=[]
@@ -25,12 +25,20 @@ module Fog
25
25
  end
26
26
  end
27
27
 
28
+ # bridge name may not be defined in some networks, we should skip that in such case
28
29
  def network_to_attributes(net)
29
30
  return if net.nil?
31
+
32
+ begin
33
+ bridge_name = net.bridge_name
34
+ rescue ::Libvirt::Error
35
+ bridge_name = ''
36
+ end
37
+
30
38
  {
31
39
  :uuid => net.uuid,
32
40
  :name => net.name,
33
- :bridge_name => net.bridge_name
41
+ :bridge_name => bridge_name
34
42
  }
35
43
  end
36
44
  end
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def list_pool_volumes(uuid)
6
6
  pool = client.lookup_storage_pool_by_uuid uuid
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def list_pools(filter = { })
6
6
  data=[]
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def list_volumes(filter = { })
6
6
  data = []
@@ -17,7 +17,7 @@ module Fog
17
17
  end
18
18
  end
19
19
  else
20
- return [get_volume(filter)]
20
+ data << get_volume(filter)
21
21
  end
22
22
  data.compact
23
23
  end
@@ -69,7 +69,8 @@ module Fog
69
69
  return raw ? vol : volume_to_attributes(vol)
70
70
  end
71
71
  end
72
- { }
72
+
73
+ nil
73
74
  end
74
75
  end
75
76
 
@@ -77,15 +78,22 @@ module Fog
77
78
  def list_volumes(filters={ })
78
79
  vol1 = mock_volume 'vol1'
79
80
  vol2 = mock_volume 'vol2'
80
- [vol1, 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] }
81
89
  end
82
90
 
83
91
  def mock_volume name
84
92
  {
85
93
  :pool_name => 'vol.pool.name',
86
- :key => 'vol.key',
87
- :id => 'vol.key',
88
- :path => 'vol.path',
94
+ :key => "vol.#{name}", # needs to match id
95
+ :id => "vol.#{name}",
96
+ :path => "path/to/disk", # used by in mock_files/domain.xml
89
97
  :name => name,
90
98
  :format_type => 'raw',
91
99
  :allocation => 123,
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def pool_action(uuid, action)
6
6
  pool = client.lookup_storage_pool_by_uuid uuid
@@ -0,0 +1,18 @@
1
+ module Fog
2
+ module Libvirt
3
+ class Compute
4
+ class Real
5
+ def update_autostart(uuid, value)
6
+ domain = client.lookup_domain_by_uuid(uuid)
7
+ domain.autostart = value
8
+ end
9
+ end
10
+
11
+ class Mock
12
+ def update_autostart(uuid, value)
13
+ value
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def update_display(options = { })
6
6
  raise ArgumentError, "uuid is a required parameter" unless options.key? :uuid
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
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)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def vm_action(uuid, action)
6
6
  domain = client.lookup_domain_by_uuid(uuid)
@@ -1,6 +1,6 @@
1
1
  module Fog
2
- module Compute
3
- class Libvirt
2
+ module Libvirt
3
+ class Compute
4
4
  class Real
5
5
  def volume_action(key, action, options={})
6
6
  get_volume({:key => key}, true).send(action)
@@ -1,5 +1,5 @@
1
1
  module Fog
2
2
  module Libvirt
3
- VERSION = '0.5.0'
3
+ VERSION = '0.9.0'
4
4
  end
5
5
  end