Skip to content

Commit

Permalink
Add v4 vm start method with use_initialization
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gekorob committed Jul 10, 2020
1 parent e698ede commit 664913d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fog/ovirt/compute/v4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class V4 < Fog::Service

request :vm_action
request :vm_start_with_cloudinit
request :vm_start_with_initialization
request :destroy_vm
request :create_vm
request :update_vm
Expand Down
12 changes: 12 additions & 0 deletions lib/fog/ovirt/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ def start_with_cloudinit(options = {})
action_status
end

def start_with_initialization(options = {})
wait_for { !locked? } if options[:blocking]
user_data = if options[:use_custom_script]
{ :custom_script => options[:user_data] }
else
Hash[YAML.safe_load(options[:user_data]).map { |a| [a.first.to_sym, a.last] }]
end
action_status = service.vm_start_with_initialization(:id => id, :user_data => user_data)
reload
action_status
end

def stop(_options = {})
vm_power_action(:stop)
end
Expand Down
23 changes: 23 additions & 0 deletions lib/fog/ovirt/requests/compute/v4/vm_start_with_initialization.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module Fog
module Ovirt
class Compute
class V4
class Real
def vm_start_with_initialization(options = {})
raise ArgumentError, "instance id is a required parameter" unless options.key? :id

vm_service = client.system_service.vms_service.vm_service(options[:id])
vm_service.start(:use_initialization => true, :vm => { :initialization => options[:user_data] })
end
end

class Mock
def vm_start_with_initialization(options = {})
raise ArgumentError, "instance id is a required parameter" unless options.key? :id
true
end
end
end
end
end
end
6 changes: 6 additions & 0 deletions tests/ovirt/compute_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
end
end


tests("Compute requests") do
%w[ add_interface create_vm datacenters destroy_interface destroy_vm get_cluster get_template
get_virtual_machine list_clusters list_networks list_template_interfaces list_templates
Expand All @@ -21,4 +22,9 @@
test("it should respond to #{collection}") { compute.respond_to? collection }
end
end

tests("compute v4 with_initialization request") do
compute = Fog::Ovirt::Compute.new(:api_version => "v4")
test("it should respond to vm_start_with_initialization") { compute.respond_to? "vm_start_with_initialization" }
end
end

0 comments on commit 664913d

Please sign in to comment.