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 Oct 13, 2020
1 parent cd6e5b3 commit ea58965
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 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
22 changes: 16 additions & 6 deletions lib/fog/ovirt/models/compute/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ def start(options = {})

def start_with_cloudinit(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_cloudinit(:id => id, :user_data => user_data)
action_status = service.vm_start_with_cloudinit(:id => id, :user_data => fetch_user_data(options))
reload
action_status
end

def start_with_initialization(options = {})
wait_for { !locked? } if options[:blocking]
action_status = service.vm_start_with_initialization(:id => id, :user_data => fetch_user_data(options))
reload
action_status
end
Expand Down Expand Up @@ -182,6 +184,14 @@ def save
def to_s
name
end

private

def fetch_user_data(options)
return { :custom_script => options[:user_data] } if options[:use_custom_script]

Hash[YAML.safe_load(options[:user_data]).map { |a| [a.first.to_sym, a.last] }]
end
end
end
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
5 changes: 5 additions & 0 deletions tests/ovirt/compute_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,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 ea58965

Please sign in to comment.