vagrant-ovirt4 1.2.3 → 2.1.3
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 +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.gitignore +1 -2
- data/CHANGELOG +50 -0
- data/Gemfile +6 -11
- data/Gemfile.lock +99 -163
- data/README.md +39 -24
- data/Rakefile +3 -16
- data/SECURITY.md +23 -0
- data/lib/vagrant-ovirt4/action/connect_ovirt.rb +29 -7
- data/lib/vagrant-ovirt4/action/create_vm.rb +14 -11
- data/lib/vagrant-ovirt4/action/disconnect_ovirt.rb +4 -1
- data/lib/vagrant-ovirt4/action/halt_vm.rb +11 -0
- data/lib/vagrant-ovirt4/action/read_ssh_info.rb +20 -6
- data/lib/vagrant-ovirt4/action/read_state.rb +7 -1
- data/lib/vagrant-ovirt4/action/snapshot_list.rb +15 -19
- data/lib/vagrant-ovirt4/action/start_vm.rb +13 -4
- data/lib/vagrant-ovirt4/action/wait_till_up.rb +7 -1
- data/lib/vagrant-ovirt4/action.rb +17 -8
- data/lib/vagrant-ovirt4/config.rb +31 -1
- data/lib/vagrant-ovirt4/errors.rb +4 -0
- data/lib/vagrant-ovirt4/util/connection.rb +40 -0
- data/lib/vagrant-ovirt4/util/machine_names.rb +21 -0
- data/lib/vagrant-ovirt4/version.rb +1 -1
- data/lib/vagrant-ovirt4.rb +4 -0
- data/locales/en.yml +6 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_context.rb +39 -0
- data/spec/vagrant-ovirt4/action/create_vm_spec.rb +47 -0
- data/spec/vagrant-ovirt4/action/read_ssh_info_spec.rb +31 -17
- data/spec/vagrant-ovirt4/action/start_vm_spec.rb +54 -0
- data/spec/vagrant-ovirt4/config_spec.rb +90 -17
- data/spec/vagrant-ovirt4/util/connection_spec.rb +80 -0
- data/vagrant-ovirt4.gemspec +2 -1
- metadata +35 -19
- data/.kitchen.yml +0 -83
- data/Jenkinsfile +0 -70
- data/lib/vagrant-ovirt4/action/sync_folders.rb +0 -69
- data/test/integration/bios_serial/bios_serial_spec.rb +0 -6
- data/test/integration/dynamic_network/network_spec.rb +0 -6
- data/test/integration/optimized_for.sh +0 -4
- data/test/integration/singleton-static_network/network_spec.rb +0 -11
@@ -1,10 +1,14 @@
|
|
1
1
|
require 'log4r'
|
2
|
+
require 'vagrant-ovirt4/util/connection'
|
3
|
+
require 'vagrant-ovirt4/util/machine_names'
|
2
4
|
require 'vagrant/util/retryable'
|
3
5
|
|
4
6
|
module VagrantPlugins
|
5
7
|
module OVirtProvider
|
6
8
|
module Action
|
7
9
|
class CreateVM
|
10
|
+
include Util::Connection
|
11
|
+
include Util::MachineNames
|
8
12
|
include Vagrant::Util::Retryable
|
9
13
|
|
10
14
|
def initialize(app, env)
|
@@ -16,12 +20,11 @@ module VagrantPlugins
|
|
16
20
|
# Get config.
|
17
21
|
config = env[:machine].provider_config
|
18
22
|
|
19
|
-
|
20
|
-
hostname = 'vagrant' if hostname.nil?
|
23
|
+
vmname = machine_vmname(env[:machine])
|
21
24
|
|
22
25
|
# Output the settings we're going to use to the user
|
23
26
|
env[:ui].info(I18n.t("vagrant_ovirt4.creating_vm"))
|
24
|
-
env[:ui].info(" -- Name: #{
|
27
|
+
env[:ui].info(" -- Name: #{vmname}")
|
25
28
|
env[:ui].info(" -- Cluster: #{config.cluster}")
|
26
29
|
env[:ui].info(" -- Template: #{config.template}")
|
27
30
|
env[:ui].info(" -- Console Type: #{config.console}")
|
@@ -29,15 +32,15 @@ module VagrantPlugins
|
|
29
32
|
env[:ui].info(" -- Optimized For: #{config.optimized_for}")
|
30
33
|
env[:ui].info(" -- Description: #{config.description}")
|
31
34
|
env[:ui].info(" -- Comment: #{config.comment}")
|
32
|
-
env[:ui].info(" -- Disk: #{Filesize.from("#{config.disk_size} B").to_f('
|
35
|
+
env[:ui].info(" -- Disk: #{Filesize.from("#{config.disk_size} B").to_f('GiB').to_i} GiB") unless config.disk_size.nil?
|
33
36
|
env[:ui].info(" -- Additional Disks:") unless config.disks.empty?
|
34
37
|
config.disks.each do |disk|
|
35
|
-
env[:ui].info(" ---- name=#{disk[:name]} size=#{Filesize.from("#{disk[:size]} B").to_f('
|
38
|
+
env[:ui].info(" ---- name=#{disk[:name]} size=#{Filesize.from("#{disk[:size]} B").to_f('GiB').to_i} GiB")
|
36
39
|
end
|
37
40
|
env[:ui].info(" -- Memory: ")
|
38
|
-
env[:ui].info(" ---- Memory: #{Filesize.from("#{config.memory_size} B").to_f('
|
39
|
-
env[:ui].info(" ---- Maximum: #{Filesize.from("#{config.memory_maximum} B").to_f('
|
40
|
-
env[:ui].info(" ---- Guaranteed: #{Filesize.from("#{config.memory_guaranteed} B").to_f('
|
41
|
+
env[:ui].info(" ---- Memory: #{Filesize.from("#{config.memory_size} B").to_f('MiB').to_i} MiB")
|
42
|
+
env[:ui].info(" ---- Maximum: #{Filesize.from("#{config.memory_maximum} B").to_f('MiB').to_i} MiB")
|
43
|
+
env[:ui].info(" ---- Guaranteed: #{Filesize.from("#{config.memory_guaranteed} B").to_f('MiB').to_i} MiB")
|
41
44
|
env[:ui].info(" -- Cpu: ")
|
42
45
|
env[:ui].info(" ---- Cores: #{config.cpu_cores}")
|
43
46
|
env[:ui].info(" ---- Sockets: #{config.cpu_sockets}")
|
@@ -46,7 +49,7 @@ module VagrantPlugins
|
|
46
49
|
|
47
50
|
# Create oVirt VM.
|
48
51
|
attr = {
|
49
|
-
:name =>
|
52
|
+
:name => vmname,
|
50
53
|
:description => config.description,
|
51
54
|
:comment => config.comment,
|
52
55
|
:cpu => {
|
@@ -127,7 +130,7 @@ module VagrantPlugins
|
|
127
130
|
OvirtSDK4::DiskAttachment.new(
|
128
131
|
disk: {
|
129
132
|
name: disk[:name],
|
130
|
-
description:
|
133
|
+
description: "#{vmname} storage disk",
|
131
134
|
format: disk[:type] == 'qcow2' ? OvirtSDK4::DiskFormat::COW : OvirtSDK4::DiskFormat::RAW,
|
132
135
|
provisioned_size: disk[:size],
|
133
136
|
storage_domains: [{
|
@@ -192,7 +195,7 @@ module VagrantPlugins
|
|
192
195
|
destroy_env[:config_validate] = false
|
193
196
|
destroy_env[:force_confirm_destroy] = true
|
194
197
|
env[:action_runner].run(Action.action_destroy, destroy_env)
|
195
|
-
env
|
198
|
+
safe_close_connection_standard!(env)
|
196
199
|
end
|
197
200
|
end
|
198
201
|
end
|
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'log4r'
|
2
2
|
require 'ovirtsdk4'
|
3
|
+
require 'vagrant-ovirt4/util/connection'
|
3
4
|
|
4
5
|
module VagrantPlugins
|
5
6
|
module OVirtProvider
|
6
7
|
module Action
|
7
8
|
class DisconnectOVirt
|
9
|
+
include Util::Connection
|
10
|
+
|
8
11
|
def initialize(app, env)
|
9
12
|
@logger = Log4r::Logger.new("vagrant_ovirt4::action::disconnect_ovirt")
|
10
13
|
@app = app
|
@@ -14,7 +17,7 @@ module VagrantPlugins
|
|
14
17
|
|
15
18
|
# Get config options for ovirt provider.
|
16
19
|
@logger.info("Disconnecting oVirt connection")
|
17
|
-
env
|
20
|
+
safe_close_connection_standard!(env)
|
18
21
|
|
19
22
|
@app.call(env)
|
20
23
|
end
|
@@ -12,6 +12,17 @@ module VagrantPlugins
|
|
12
12
|
def call(env)
|
13
13
|
env[:ui].info(I18n.t("vagrant_ovirt4.halt_vm"))
|
14
14
|
|
15
|
+
# Halt via OS capability
|
16
|
+
begin
|
17
|
+
if env[:machine].guest.capability?(:halt)
|
18
|
+
env[:machine].guest.capability(:halt)
|
19
|
+
# Give the VM a chance to shutdown gracefully..."
|
20
|
+
sleep 10
|
21
|
+
end
|
22
|
+
rescue
|
23
|
+
env[:ui].info("Failed to shutdown guest gracefully.")
|
24
|
+
end
|
25
|
+
|
15
26
|
machine = env[:vms_service].vm_service(env[:machine].id)
|
16
27
|
machine.stop rescue nil #todo dont rescue
|
17
28
|
|
@@ -17,26 +17,31 @@ module VagrantPlugins
|
|
17
17
|
@app.call(env)
|
18
18
|
end
|
19
19
|
|
20
|
+
# This method powers OVirtProvider::Provider#ssh_info. It returns a
|
21
|
+
# hash of SSH connection information if and only if at least one IPv4
|
22
|
+
# address associated with the machine in question could be retrieved
|
23
|
+
# from the oVirt API. Otherwise, it returns nil.
|
20
24
|
def read_ssh_info(env)
|
21
25
|
vms_service, machine = env[:vms_service], env[:machine]
|
22
|
-
return
|
26
|
+
return nil if machine.id.nil?
|
23
27
|
|
24
28
|
# Find the machine
|
25
29
|
server = vms_service.vm_service(machine.id)
|
26
30
|
begin
|
27
31
|
if server.get.nil?
|
28
32
|
machine.id = nil
|
29
|
-
return
|
33
|
+
return nil
|
30
34
|
end
|
31
35
|
rescue Exception => e
|
32
36
|
machine.id = nil
|
33
|
-
return
|
34
|
-
raise e
|
37
|
+
return nil
|
35
38
|
end
|
36
39
|
|
37
40
|
nics_service = server.nics_service
|
38
41
|
nics = nics_service.list
|
39
|
-
ip_addr = nics
|
42
|
+
ip_addr = first_active_ipv4_address(env, nics)
|
43
|
+
|
44
|
+
return nil if ip_addr.nil?
|
40
45
|
|
41
46
|
# Return the info
|
42
47
|
# TODO: Some info should be configurable in Vagrantfile
|
@@ -49,7 +54,16 @@ module VagrantPlugins
|
|
49
54
|
:forward_x11 => machine.config.ssh.forward_x11,
|
50
55
|
}
|
51
56
|
|
52
|
-
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def first_active_ipv4_address(env, nics)
|
62
|
+
nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
|
63
|
+
rescue
|
64
|
+
# for backwards compatibility with ovirt 4.3
|
65
|
+
nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
|
66
|
+
end
|
53
67
|
end
|
54
68
|
end
|
55
69
|
end
|
@@ -33,7 +33,13 @@ module VagrantPlugins
|
|
33
33
|
end
|
34
34
|
nics_service = server.nics_service
|
35
35
|
nics = nics_service.list
|
36
|
-
|
36
|
+
begin
|
37
|
+
ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
|
38
|
+
rescue
|
39
|
+
# for backwards compatibility with ovirt 4.3
|
40
|
+
ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
|
41
|
+
end
|
42
|
+
|
37
43
|
unless ip_addr.nil?
|
38
44
|
env[:ip_address] = ip_addr
|
39
45
|
@logger.debug("Got output #{env[:ip_address]}")
|
@@ -14,34 +14,30 @@ module VagrantPlugins
|
|
14
14
|
|
15
15
|
system_service = env[:connection].system_service
|
16
16
|
|
17
|
-
#
|
17
|
+
#Find all storage domains and store the id and name in a
|
18
18
|
# hash, so that looking them up later will be faster:
|
19
|
-
vms_map = Hash[env[:vms_service].list.map { |vm| [vm.id, vm.name] }]
|
20
|
-
|
21
|
-
# Same for storage domains:
|
22
19
|
sds_service = system_service.storage_domains_service
|
23
20
|
sds_map = Hash[sds_service.list.map { |sd| [sd.id, sd.name] }]
|
24
21
|
|
25
22
|
# For each virtual machine find its snapshots, then for each snapshot
|
26
23
|
# find its disks:
|
27
24
|
xs = [['id', 'description', 'date']]
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
xs.push([snap_id, snap_description, snap_date.to_s])
|
42
|
-
end
|
25
|
+
vm_service = env[:vms_service].vm_service(env[:machine].id)
|
26
|
+
snaps_service = vm_service.snapshots_service
|
27
|
+
snaps_map = Hash[snaps_service.list.map { |snap| [snap.id, { description: snap.description, date: snap.date }] }]
|
28
|
+
snaps_map.each do |snap_id, metadata|
|
29
|
+
snap_description = metadata[:description]
|
30
|
+
snap_date = metadata[:date]
|
31
|
+
snap_service = snaps_service.snapshot_service(snap_id)
|
32
|
+
disks_service = snap_service.disks_service
|
33
|
+
disks_service.list.each do |disk|
|
34
|
+
next unless disk.storage_domains.any?
|
35
|
+
sd_id = disk.storage_domains.first.id
|
36
|
+
sd_name = sds_map[sd_id]
|
37
|
+
xs.push([snap_id, snap_description, snap_date.to_s])
|
43
38
|
end
|
44
39
|
end
|
40
|
+
|
45
41
|
widths = xs.transpose.map { |column_arr| column_arr.map(&:size).max }
|
46
42
|
env[:machine_snapshot_list] =
|
47
43
|
xs.map { |row_arr|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'log4r'
|
2
|
+
require 'vagrant-ovirt4/errors'
|
3
|
+
require 'vagrant-ovirt4/util/machine_names'
|
2
4
|
require 'vagrant/util/scoped_hash_override'
|
3
5
|
|
4
6
|
module VagrantPlugins
|
@@ -7,6 +9,7 @@ module VagrantPlugins
|
|
7
9
|
|
8
10
|
# Just start the VM.
|
9
11
|
class StartVM
|
12
|
+
include Util::MachineNames
|
10
13
|
include Vagrant::Util::ScopedHashOverride
|
11
14
|
|
12
15
|
def initialize(app, env)
|
@@ -26,8 +29,7 @@ module VagrantPlugins
|
|
26
29
|
end
|
27
30
|
|
28
31
|
# FIX MULTIPLE NETWORK INTERFACES
|
29
|
-
hostname = env[:machine]
|
30
|
-
hostname = 'vagrant' if hostname.nil?
|
32
|
+
hostname = machine_hostname(env[:machine])
|
31
33
|
|
32
34
|
initialization = {
|
33
35
|
host_name: hostname,
|
@@ -46,9 +48,15 @@ module VagrantPlugins
|
|
46
48
|
(0...configured_ifaces_options.length()).each do |iface_index|
|
47
49
|
iface_options = configured_ifaces_options[iface_index]
|
48
50
|
|
51
|
+
if iface_options[:interface_name] != nil then
|
52
|
+
iface_name = iface_options[:interface_name]
|
53
|
+
else
|
54
|
+
iface_name = "eth#{iface_index}"
|
55
|
+
end
|
56
|
+
|
49
57
|
if iface_options[:ip] then
|
50
58
|
nic_configuration = {
|
51
|
-
name:
|
59
|
+
name: iface_name,
|
52
60
|
on_boot: true,
|
53
61
|
boot_protocol: OvirtSDK4::BootProtocol::STATIC,
|
54
62
|
ip: {
|
@@ -60,7 +68,7 @@ module VagrantPlugins
|
|
60
68
|
}
|
61
69
|
else
|
62
70
|
nic_configuration = {
|
63
|
-
name:
|
71
|
+
name: iface_name,
|
64
72
|
on_boot: true,
|
65
73
|
boot_protocol: OvirtSDK4::BootProtocol::DHCP,
|
66
74
|
}
|
@@ -75,6 +83,7 @@ module VagrantPlugins
|
|
75
83
|
vm_configuration = {
|
76
84
|
initialization: initialization,
|
77
85
|
placement_policy: {},
|
86
|
+
run_once: config.run_once
|
78
87
|
}
|
79
88
|
|
80
89
|
vm_configuration[:placement_policy][:hosts] = [{ :name => config.placement_host }] unless config.placement_host.nil?
|
@@ -57,7 +57,13 @@ module VagrantPlugins
|
|
57
57
|
|
58
58
|
nics_service = server.nics_service
|
59
59
|
nics = nics_service.list
|
60
|
-
|
60
|
+
begin
|
61
|
+
ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment.reported_devices).collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first
|
62
|
+
rescue
|
63
|
+
# for backwards compatibility with ovirt 4.3
|
64
|
+
ip_addr = nics.collect { |nic_attachment| env[:connection].follow_link(nic_attachment).reported_devices.collect { |dev| dev.ips.collect { |ip| ip.address if ip.version == 'v4' } unless dev.ips.nil? } }.flatten.reject { |ip| ip.nil? }.first rescue nil
|
65
|
+
end
|
66
|
+
|
61
67
|
unless ip_addr.nil?
|
62
68
|
env[:ui].info("Got IP: #{ip_addr}")
|
63
69
|
# Check if SSH-Server is up
|
@@ -13,8 +13,11 @@ module VagrantPlugins
|
|
13
13
|
b.use ConfigValidate
|
14
14
|
b.use ConnectOVirt
|
15
15
|
b.use Call, ReadState do |env, b2|
|
16
|
+
# synced_folders defaults to NFS on linux. Make it default to rsync as before.
|
17
|
+
env[:machine].config.nfs.functional = false
|
16
18
|
if env[:machine_state_id] == :up
|
17
|
-
b2.use
|
19
|
+
b2.use SyncedFolderCleanup
|
20
|
+
b2.use SyncedFolders
|
18
21
|
b2.use MessageAlreadyUp
|
19
22
|
next
|
20
23
|
end
|
@@ -37,7 +40,8 @@ module VagrantPlugins
|
|
37
40
|
|
38
41
|
b2.use StartVM
|
39
42
|
b2.use WaitTillUp
|
40
|
-
b2.use
|
43
|
+
b2.use SyncedFolderCleanup
|
44
|
+
b2.use SyncedFolders
|
41
45
|
end
|
42
46
|
b.use DisconnectOVirt
|
43
47
|
end
|
@@ -54,8 +58,8 @@ module VagrantPlugins
|
|
54
58
|
|
55
59
|
b2.use ConnectOVirt
|
56
60
|
b2.use ProvisionerCleanup, :before if defined?(ProvisionerCleanup)
|
57
|
-
b2.use HaltVM
|
58
|
-
b2.use WaitTillDown
|
61
|
+
b2.use HaltVM unless env[:machine].state.id == :down
|
62
|
+
b2.use WaitTillDown unless env[:machine].state.id == :down
|
59
63
|
b2.use DestroyVM
|
60
64
|
b2.use DisconnectOVirt
|
61
65
|
end
|
@@ -66,12 +70,15 @@ module VagrantPlugins
|
|
66
70
|
Vagrant::Action::Builder.new.tap do |b|
|
67
71
|
b.use ConfigValidate
|
68
72
|
b.use Call, IsCreated do |env, b2|
|
73
|
+
# synced_folders defaults to NFS on linux. Make it default to rsync as before.
|
74
|
+
env[:machine].config.nfs.functional = false
|
69
75
|
if !env[:result]
|
70
76
|
b2.use MessageNotCreated
|
71
77
|
next
|
72
78
|
end
|
73
79
|
b2.use Provision
|
74
|
-
b2.use
|
80
|
+
b2.use SyncedFolderCleanup
|
81
|
+
b2.use SyncedFolders
|
75
82
|
end
|
76
83
|
end
|
77
84
|
end
|
@@ -161,7 +168,7 @@ module VagrantPlugins
|
|
161
168
|
end
|
162
169
|
|
163
170
|
def self.action_reload
|
164
|
-
|
171
|
+
Vagrant::Action::Builder.new.tap do |b|
|
165
172
|
b.use action_halt
|
166
173
|
b.use action_up
|
167
174
|
end
|
@@ -194,7 +201,8 @@ module VagrantPlugins
|
|
194
201
|
b.use MessageNotSuspended
|
195
202
|
next
|
196
203
|
end
|
197
|
-
b.use
|
204
|
+
b.use StartVM
|
205
|
+
b.use WaitTillUp
|
198
206
|
end
|
199
207
|
end
|
200
208
|
|
@@ -234,7 +242,8 @@ module VagrantPlugins
|
|
234
242
|
autoload :SnapshotSave, action_root.join("snapshot_save")
|
235
243
|
autoload :StartVM, action_root.join("start_vm")
|
236
244
|
autoload :SuspendVM, action_root.join("suspend_vm")
|
237
|
-
autoload :
|
245
|
+
autoload :SyncedFolders, 'vagrant/action/builtin/synced_folders'
|
246
|
+
autoload :SyncedFolderCleanup, 'vagrant/action/builtin/synced_folder_cleanup'
|
238
247
|
autoload :WaitTillDown, action_root.join("wait_till_down")
|
239
248
|
autoload :WaitTillUp, action_root.join("wait_till_up")
|
240
249
|
autoload :WaitTilSuspended, action_root.join("wait_til_suspended")
|
@@ -29,7 +29,11 @@ module VagrantPlugins
|
|
29
29
|
attr_accessor :optimized_for
|
30
30
|
attr_accessor :description
|
31
31
|
attr_accessor :comment
|
32
|
+
attr_accessor :vmname
|
32
33
|
attr_accessor :disks
|
34
|
+
attr_accessor :timeout
|
35
|
+
attr_accessor :connect_timeout
|
36
|
+
attr_accessor :run_once
|
33
37
|
|
34
38
|
def initialize
|
35
39
|
@url = UNSET_VALUE
|
@@ -55,6 +59,10 @@ module VagrantPlugins
|
|
55
59
|
@optimized_for = UNSET_VALUE
|
56
60
|
@description = UNSET_VALUE
|
57
61
|
@comment = UNSET_VALUE
|
62
|
+
@vmname = UNSET_VALUE
|
63
|
+
@timeout = UNSET_VALUE
|
64
|
+
@connect_timeout = UNSET_VALUE
|
65
|
+
@run_once = UNSET_VALUE
|
58
66
|
@disks = []
|
59
67
|
|
60
68
|
end
|
@@ -98,7 +106,7 @@ module VagrantPlugins
|
|
98
106
|
@cpu_threads = 1 if @cpu_threads == UNSET_VALUE
|
99
107
|
@cluster = nil if @cluster == UNSET_VALUE
|
100
108
|
@console = nil if @console == UNSET_VALUE
|
101
|
-
@memory_size = '256
|
109
|
+
@memory_size = '256 MiB' if @memory_size == UNSET_VALUE
|
102
110
|
@memory_maximum = @memory_size if @memory_maximum == UNSET_VALUE
|
103
111
|
@memory_guaranteed = @memory_size if @memory_guaranteed == UNSET_VALUE
|
104
112
|
@template = nil if @template == UNSET_VALUE
|
@@ -109,6 +117,10 @@ module VagrantPlugins
|
|
109
117
|
@optimized_for = nil if @optimized_for == UNSET_VALUE
|
110
118
|
@description = '' if @description == UNSET_VALUE
|
111
119
|
@comment = '' if @comment == UNSET_VALUE
|
120
|
+
@vmname = nil if @vmname == UNSET_VALUE
|
121
|
+
@timeout = nil if @timeout == UNSET_VALUE
|
122
|
+
@connect_timeout = nil if @connect_timeout == UNSET_VALUE
|
123
|
+
@run_once = @run_once == UNSET_VALUE ? false : !!@run_once
|
112
124
|
|
113
125
|
unless optimized_for.nil?
|
114
126
|
raise "Invalid 'optimized_for'. Must be one of #{OvirtSDK4::VmType.constants.map { |s| "'#{s.downcase}'" }.join(' ')}" unless OvirtSDK4::VmType.constants.include? optimized_for.upcase.to_sym
|
@@ -133,6 +145,24 @@ module VagrantPlugins
|
|
133
145
|
rescue ArgumentError
|
134
146
|
raise "Not able to parse either `memory_size` or `memory_guaranteed`. Please verify and check again."
|
135
147
|
end
|
148
|
+
|
149
|
+
unless timeout.nil?
|
150
|
+
begin
|
151
|
+
@timeout = Integer(@timeout)
|
152
|
+
raise ArgumentError if @timeout < 0
|
153
|
+
rescue ArgumentError, TypeError
|
154
|
+
raise "`timeout` argument #{@timeout.inspect} is not a valid nonnegative integer"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
unless connect_timeout.nil?
|
159
|
+
begin
|
160
|
+
@connect_timeout = Integer(@connect_timeout)
|
161
|
+
raise ArgumentError if @connect_timeout < 0
|
162
|
+
rescue ArgumentError, TypeError
|
163
|
+
raise "`connect_timeout` argument #{@connect_timeout.inspect} is not a valid nonnegative integer"
|
164
|
+
end
|
165
|
+
end
|
136
166
|
end
|
137
167
|
|
138
168
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'ovirtsdk4'
|
2
|
+
require 'ovirtsdk4/connection'
|
3
|
+
|
4
|
+
module VagrantPlugins
|
5
|
+
module OVirtProvider
|
6
|
+
module Util
|
7
|
+
module Connection
|
8
|
+
# Use OVirtSDK4::ConnectionError if available; SDK versions older than
|
9
|
+
# 4.2.0 used the generic OVirtSDK4::Error.
|
10
|
+
ERROR_CLASSES = (OvirtSDK4.const_defined?(:ConnectionError) ? [OvirtSDK4::ConnectionError, OvirtSDK4::Error] : [OvirtSDK4::Error]).freeze
|
11
|
+
|
12
|
+
module_function
|
13
|
+
|
14
|
+
# Close a connection, suppressing errors generated by the SDK. Yield
|
15
|
+
# the error to the caller to re-raise if appropriate (or log, or do
|
16
|
+
# whatever).
|
17
|
+
def safe_close_connection!(conn)
|
18
|
+
conn.close
|
19
|
+
rescue *ERROR_CLASSES => e
|
20
|
+
yield e if block_given?
|
21
|
+
rescue StandardError => e
|
22
|
+
yield e if block_given?
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
|
26
|
+
# Wrapper for "#safe_close_connection" that issues a warning message
|
27
|
+
# with diagnostic information about the exception raised.
|
28
|
+
def safe_close_connection_with_warning!(conn, ui)
|
29
|
+
safe_close_connection!(conn) { |e| ui.warn("Encountered exception of class #{e.class}: #{e.message}") }
|
30
|
+
end
|
31
|
+
|
32
|
+
# Wrapper for "#safe_close_connection_with_warning" that extracts the
|
33
|
+
# connection and UI from a Vagrant environment.
|
34
|
+
def safe_close_connection_standard!(env)
|
35
|
+
safe_close_connection_with_warning!(env[:connection], env[:ui])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VagrantPlugins
|
2
|
+
module OVirtProvider
|
3
|
+
module Util
|
4
|
+
module MachineNames
|
5
|
+
DEFAULT_NAME = 'vagrant'.freeze
|
6
|
+
|
7
|
+
module_function
|
8
|
+
|
9
|
+
def machine_hostname(machine)
|
10
|
+
machine.config.vm.hostname || DEFAULT_NAME
|
11
|
+
end
|
12
|
+
|
13
|
+
def machine_vmname(machine)
|
14
|
+
machine.provider_config.vmname || machine_hostname(machine)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
|
data/lib/vagrant-ovirt4.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'log4r'
|
1
2
|
require 'pathname'
|
2
3
|
require 'vagrant-ovirt4/plugin'
|
3
4
|
|
@@ -8,9 +9,11 @@ module VagrantPlugins
|
|
8
9
|
autoload :Errors, lib_path.join("errors")
|
9
10
|
autoload :Util, lib_path.join("util")
|
10
11
|
|
12
|
+
@@logger = Log4r::Logger.new("vagrant_ovirt4::provider")
|
11
13
|
@@ovirt_connection = nil
|
12
14
|
@@vms_service = nil
|
13
15
|
def self.ovirt_connection
|
16
|
+
@@logger.warn('Use of deprecated OVirtProvider.ovirt_connection detected.')
|
14
17
|
@@ovirt_connection
|
15
18
|
end
|
16
19
|
|
@@ -19,6 +22,7 @@ module VagrantPlugins
|
|
19
22
|
end
|
20
23
|
|
21
24
|
def self.vms_service
|
25
|
+
@@logger.warn('Use of deprecated OVirtProvider.vms_service detected.')
|
22
26
|
@@vms_service
|
23
27
|
end
|
24
28
|
|
data/locales/en.yml
CHANGED
@@ -55,7 +55,13 @@ en:
|
|
55
55
|
The instance is not running. Use `vagrant up` to start it.
|
56
56
|
short_down: |-
|
57
57
|
down
|
58
|
+
long_not_created: |-
|
59
|
+
The instance is not created. Use `vagrant up` to create it.
|
60
|
+
short_not_created: |-
|
61
|
+
not created
|
58
62
|
errors:
|
63
|
+
service_connection_error: |-
|
64
|
+
Error connecting to the oVirt cluster endpoint: "%{error_message}"
|
59
65
|
remove_vm_error: |-
|
60
66
|
Error removing VM '%{vm_name}'. oVirt error message was '%{error_message}'
|
61
67
|
no_vm_error: |-
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'vagrant-ovirt4/config'
|
2
|
+
|
3
|
+
shared_context 'provider:action' do
|
4
|
+
let(:app) { double('app') }
|
5
|
+
|
6
|
+
let(:env) {
|
7
|
+
{
|
8
|
+
connection: double('connection',
|
9
|
+
system_service: double('system_service', disks_service: double('disks_service'))
|
10
|
+
),
|
11
|
+
machine: double('machine',
|
12
|
+
provider: double('provider'),
|
13
|
+
provider_config: VagrantPlugins::OVirtProvider::Config.new,
|
14
|
+
name: 'machname',
|
15
|
+
id: 'ID',
|
16
|
+
config: double('config',
|
17
|
+
vm: double('vm_config',
|
18
|
+
networks: [],
|
19
|
+
),
|
20
|
+
),
|
21
|
+
),
|
22
|
+
ui: double('ui'),
|
23
|
+
vms_service: double('vms_service'),
|
24
|
+
}
|
25
|
+
}
|
26
|
+
|
27
|
+
let(:vm_service) {
|
28
|
+
double('vm_service',
|
29
|
+
disk_attachments_service: double('disk_attachments_service', list: []),
|
30
|
+
get: double('get'),
|
31
|
+
)
|
32
|
+
}
|
33
|
+
|
34
|
+
before do
|
35
|
+
allow(app).to receive(:call)
|
36
|
+
allow(env[:vms_service]).to receive(:vm_service).with(env[:machine].id).and_return(vm_service)
|
37
|
+
env[:machine].provider_config.finalize!
|
38
|
+
end
|
39
|
+
end
|