fog-libvirt 0.4.1 → 0.8.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.
- checksums.yaml +5 -5
- data/fog-libvirt.gemspec +7 -16
- data/lib/fog/bin/libvirt.rb +2 -2
- data/lib/fog/libvirt.rb +1 -3
- data/lib/fog/libvirt/compute.rb +6 -4
- data/lib/fog/libvirt/models/compute/README.md +16 -0
- data/lib/fog/libvirt/models/compute/interface.rb +2 -2
- data/lib/fog/libvirt/models/compute/interfaces.rb +3 -3
- data/lib/fog/libvirt/models/compute/network.rb +3 -3
- data/lib/fog/libvirt/models/compute/networks.rb +3 -3
- data/lib/fog/libvirt/models/compute/nic.rb +2 -2
- data/lib/fog/libvirt/models/compute/nics.rb +3 -3
- data/lib/fog/libvirt/models/compute/node.rb +2 -2
- data/lib/fog/libvirt/models/compute/nodes.rb +3 -3
- data/lib/fog/libvirt/models/compute/pool.rb +2 -2
- data/lib/fog/libvirt/models/compute/pools.rb +3 -3
- data/lib/fog/libvirt/models/compute/server.rb +149 -9
- data/lib/fog/libvirt/models/compute/servers.rb +3 -3
- data/lib/fog/libvirt/models/compute/templates/server.xml.erb +55 -0
- data/lib/fog/libvirt/models/compute/templates/volume.xml.erb +4 -4
- data/lib/fog/libvirt/models/compute/util/uri.rb +2 -2
- data/lib/fog/libvirt/models/compute/util/util.rb +2 -2
- data/lib/fog/libvirt/models/compute/volume.rb +11 -9
- data/lib/fog/libvirt/models/compute/volumes.rb +3 -3
- data/lib/fog/libvirt/requests/compute/clone_volume.rb +3 -3
- data/lib/fog/libvirt/requests/compute/create_domain.rb +2 -2
- data/lib/fog/libvirt/requests/compute/create_volume.rb +2 -2
- data/lib/fog/libvirt/requests/compute/define_domain.rb +2 -2
- data/lib/fog/libvirt/requests/compute/define_pool.rb +2 -2
- data/lib/fog/libvirt/requests/compute/destroy_interface.rb +2 -2
- data/lib/fog/libvirt/requests/compute/destroy_network.rb +2 -2
- data/lib/fog/libvirt/requests/compute/dhcp_leases.rb +2 -2
- data/lib/fog/libvirt/requests/compute/get_node_info.rb +2 -2
- data/lib/fog/libvirt/requests/compute/libversion.rb +18 -0
- data/lib/fog/libvirt/requests/compute/list_domains.rb +9 -3
- data/lib/fog/libvirt/requests/compute/list_interfaces.rb +2 -2
- data/lib/fog/libvirt/requests/compute/list_networks.rb +11 -3
- data/lib/fog/libvirt/requests/compute/list_pool_volumes.rb +2 -2
- data/lib/fog/libvirt/requests/compute/list_pools.rb +2 -2
- data/lib/fog/libvirt/requests/compute/list_volumes.rb +16 -8
- data/lib/fog/libvirt/requests/compute/pool_action.rb +2 -2
- data/lib/fog/libvirt/requests/compute/update_autostart.rb +18 -0
- data/lib/fog/libvirt/requests/compute/update_display.rb +2 -2
- data/lib/fog/libvirt/requests/compute/upload_volume.rb +2 -2
- data/lib/fog/libvirt/requests/compute/vm_action.rb +2 -2
- data/lib/fog/libvirt/requests/compute/volume_action.rb +2 -2
- data/lib/fog/libvirt/version.rb +1 -1
- data/minitests/server/server_test.rb +64 -0
- data/minitests/server/user_data_iso_test.rb +8 -8
- data/tests/libvirt/compute_tests.rb +2 -1
- data/tests/libvirt/models/compute/interface_tests.rb +1 -1
- data/tests/libvirt/models/compute/interfaces_tests.rb +1 -1
- data/tests/libvirt/models/compute/network_tests.rb +1 -1
- data/tests/libvirt/models/compute/networks_tests.rb +1 -1
- data/tests/libvirt/models/compute/nic_tests.rb +1 -1
- data/tests/libvirt/models/compute/pool_tests.rb +1 -1
- data/tests/libvirt/models/compute/pools_tests.rb +1 -1
- data/tests/libvirt/models/compute/server_tests.rb +4 -1
- data/tests/libvirt/models/compute/servers_tests.rb +1 -1
- data/tests/libvirt/models/compute/volume_tests.rb +1 -1
- data/tests/libvirt/models/compute/volumes_tests.rb +2 -1
- data/tests/libvirt/requests/compute/update_autostart_tests.rb +12 -0
- metadata +27 -15
@@ -2,10 +2,10 @@ require 'fog/core/collection'
|
|
2
2
|
require 'fog/libvirt/models/compute/server'
|
3
3
|
|
4
4
|
module Fog
|
5
|
-
module
|
6
|
-
class
|
5
|
+
module Libvirt
|
6
|
+
class Compute
|
7
7
|
class Servers < Fog::Collection
|
8
|
-
model Fog::Compute::
|
8
|
+
model Fog::Libvirt::Compute::Server
|
9
9
|
|
10
10
|
def all(filter={})
|
11
11
|
load(service.list_domains(filter))
|
@@ -1,6 +1,11 @@
|
|
1
1
|
<domain type='<%= domain_type %>'>
|
2
2
|
<name><%= name %></name>
|
3
3
|
<memory><%= memory_size %></memory>
|
4
|
+
<% if hugepages -%>
|
5
|
+
<memoryBacking>
|
6
|
+
<hugepages/>
|
7
|
+
</memoryBacking>
|
8
|
+
<% end -%>
|
4
9
|
<vcpu><%= cpus %></vcpu>
|
5
10
|
<os>
|
6
11
|
<type arch='<%= arch %>'><%= os_type %></type>
|
@@ -32,13 +37,48 @@
|
|
32
37
|
<% end -%>
|
33
38
|
<clock offset='utc'/>
|
34
39
|
<devices>
|
40
|
+
<% args = {}
|
41
|
+
if File.file?('/etc/foreman/ceph.conf')
|
42
|
+
File.readlines('/etc/foreman/ceph.conf').each do |line|
|
43
|
+
pair = line.strip.split("=")
|
44
|
+
key = pair[0]
|
45
|
+
value = pair[1]
|
46
|
+
args[key] = value
|
47
|
+
end
|
48
|
+
end
|
49
|
+
%>
|
35
50
|
<% volumes.each do |vol| -%>
|
51
|
+
<% if File.file?('/etc/foreman/ceph.conf') && vol.pool_name.include?(args["libvirt_ceph_pool"]) %>
|
52
|
+
<disk type='network' device='disk'>
|
53
|
+
<driver name='qemu' type='<%= vol.format_type %>' cache='writeback' discard='unmap'/>
|
54
|
+
<source protocol='rbd' name='<%= vol.path %>'>
|
55
|
+
<% if args.key?("monitor") -%>
|
56
|
+
<% args["monitor"].split(",").each do |mon| %>
|
57
|
+
<host name='<%= mon %>' port='<%= args["port"] %>'/>
|
58
|
+
<% end %>
|
59
|
+
<% end %>
|
60
|
+
</source>
|
61
|
+
<auth username='<%= args["auth_username"] %>'>
|
62
|
+
<% if args.key?("auth_uuid") -%>
|
63
|
+
<secret type='ceph' uuid='<%= args["auth_uuid"] %>'/>
|
64
|
+
<% else -%>
|
65
|
+
<secret type='ceph' usage='<%= args["auth_usage"] %>'/>
|
66
|
+
<% end -%>
|
67
|
+
</auth>
|
68
|
+
<% if args['bus_type'] == 'virtio' %>
|
69
|
+
<target dev='vd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='virtio'/>
|
70
|
+
<% else %>
|
71
|
+
<target dev='sd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='scsi'/>
|
72
|
+
<% end %>
|
73
|
+
</disk>
|
74
|
+
<% else %>
|
36
75
|
<disk type='file' device='disk'>
|
37
76
|
<driver name='qemu' type='<%= vol.format_type %>'/>
|
38
77
|
<source file='<%= vol.path %>'/>
|
39
78
|
<%# we need to ensure a unique target dev -%>
|
40
79
|
<target dev='vd<%= ('a'..'z').to_a[volumes.index(vol)] %>' bus='virtio'/>
|
41
80
|
</disk>
|
81
|
+
<% end %>
|
42
82
|
<% end -%>
|
43
83
|
<% if iso_file -%>
|
44
84
|
<disk type='file' device='cdrom'>
|
@@ -55,6 +95,21 @@
|
|
55
95
|
<model type='<%= nic.model %>'/>
|
56
96
|
</interface>
|
57
97
|
<% end -%>
|
98
|
+
<% if guest_agent -%>
|
99
|
+
<channel type='unix'>
|
100
|
+
<target type='virtio' name='org.qemu.guest_agent.0'/>
|
101
|
+
</channel>
|
102
|
+
<% end -%>
|
103
|
+
<rng model='virtio'>
|
104
|
+
<%
|
105
|
+
rng_backend_model = virtio_rng[:backend_model] ? virtio_rng[:backend_model] : 'random'
|
106
|
+
-%>
|
107
|
+
<% if virtio_rng[:backend_path] -%>
|
108
|
+
<backend model='<%= rng_backend_model %>'><%= virtio_rng[:backend_path] %></backend>
|
109
|
+
<% else -%>
|
110
|
+
<backend model='<%= rng_backend_model %>'/>
|
111
|
+
<% end -%>
|
112
|
+
</rng>
|
58
113
|
<serial type='pty'>
|
59
114
|
<target port='0'/>
|
60
115
|
</serial>
|
@@ -5,8 +5,8 @@
|
|
5
5
|
<target>
|
6
6
|
<format type="<%= format_type %>"/>
|
7
7
|
<permissions>
|
8
|
-
<owner
|
9
|
-
<group
|
8
|
+
<owner><%= owner %></owner>
|
9
|
+
<group><%= group %></group>
|
10
10
|
<mode>0744</mode>
|
11
11
|
<label>virt_image_t</label>
|
12
12
|
</permissions>
|
@@ -16,8 +16,8 @@
|
|
16
16
|
<path><%= backing_volume.path %></path>
|
17
17
|
<format type="<%= backing_volume.format_type %>"/>
|
18
18
|
<permissions>
|
19
|
-
<owner
|
20
|
-
<group
|
19
|
+
<owner><%= owner %></owner>
|
20
|
+
<group><%= group %></group>
|
21
21
|
<mode>0744</mode>
|
22
22
|
<label>virt_image_t</label>
|
23
23
|
</permissions>
|
@@ -4,8 +4,8 @@ require 'ostruct'
|
|
4
4
|
require 'securerandom'
|
5
5
|
|
6
6
|
module Fog
|
7
|
-
module
|
8
|
-
module
|
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
|
6
|
-
class
|
5
|
+
module Libvirt
|
6
|
+
class Compute
|
7
7
|
class Volume < Fog::Model
|
8
8
|
attr_reader :xml
|
9
|
-
include Fog::
|
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 => "0",
|
112
|
+
:group => "0",
|
109
113
|
}
|
110
114
|
end
|
111
115
|
|
112
116
|
def split_size_unit(text)
|
113
|
-
if text.kind_of?
|
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
|
6
|
-
class
|
5
|
+
module Libvirt
|
6
|
+
class Compute
|
7
7
|
class Volumes < Fog::Collection
|
8
|
-
model Fog::Compute::
|
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
|
3
|
-
class
|
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::
|
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
|
3
|
-
class
|
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
|
3
|
-
class
|
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 =>
|
41
|
+
:bridge_name => bridge_name
|
34
42
|
}
|
35
43
|
end
|
36
44
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Fog
|
2
|
-
module
|
3
|
-
class
|
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
|
-
|
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 =>
|
87
|
-
:id =>
|
88
|
-
: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,
|