Skip to content

Commit 664913d

Browse files
committed
Add v4 vm start method with use_initialization
Since the version 4.3.1 of the ovirt-engine-sdk-ruby is possible to start a vm passing the use_initialization param. In this way, according to the VM's OS type it'll be possible to set the correct init section (cloudinit, sysprep, ignition)
1 parent e698ede commit 664913d

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

lib/fog/ovirt/compute/v4.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class V4 < Fog::Service
99

1010
request :vm_action
1111
request :vm_start_with_cloudinit
12+
request :vm_start_with_initialization
1213
request :destroy_vm
1314
request :create_vm
1415
request :update_vm

lib/fog/ovirt/models/compute/server.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ def start_with_cloudinit(options = {})
133133
action_status
134134
end
135135

136+
def start_with_initialization(options = {})
137+
wait_for { !locked? } if options[:blocking]
138+
user_data = if options[:use_custom_script]
139+
{ :custom_script => options[:user_data] }
140+
else
141+
Hash[YAML.safe_load(options[:user_data]).map { |a| [a.first.to_sym, a.last] }]
142+
end
143+
action_status = service.vm_start_with_initialization(:id => id, :user_data => user_data)
144+
reload
145+
action_status
146+
end
147+
136148
def stop(_options = {})
137149
vm_power_action(:stop)
138150
end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module Fog
2+
module Ovirt
3+
class Compute
4+
class V4
5+
class Real
6+
def vm_start_with_initialization(options = {})
7+
raise ArgumentError, "instance id is a required parameter" unless options.key? :id
8+
9+
vm_service = client.system_service.vms_service.vm_service(options[:id])
10+
vm_service.start(:use_initialization => true, :vm => { :initialization => options[:user_data] })
11+
end
12+
end
13+
14+
class Mock
15+
def vm_start_with_initialization(options = {})
16+
raise ArgumentError, "instance id is a required parameter" unless options.key? :id
17+
true
18+
end
19+
end
20+
end
21+
end
22+
end
23+
end

tests/ovirt/compute_tests.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
end
1414
end
1515

16+
1617
tests("Compute requests") do
1718
%w[ add_interface create_vm datacenters destroy_interface destroy_vm get_cluster get_template
1819
get_virtual_machine list_clusters list_networks list_template_interfaces list_templates
@@ -21,4 +22,9 @@
2122
test("it should respond to #{collection}") { compute.respond_to? collection }
2223
end
2324
end
25+
26+
tests("compute v4 with_initialization request") do
27+
compute = Fog::Ovirt::Compute.new(:api_version => "v4")
28+
test("it should respond to vm_start_with_initialization") { compute.respond_to? "vm_start_with_initialization" }
29+
end
2430
end

0 commit comments

Comments
 (0)