On 02/17/2017 05:53 AM, Marc Young wrote:
Using the ruby sdk I'm unable to start a VM on a specific host.
According to the API docs at api/v4/model#types/vm_placement_policy :
Name Type
----------------
hosts Host[]
No matter what I specify, I run into this same bug:
https://bugzilla.redhat.com/show_bug.cgi?id=1249521
65: require 'pry'
66: binding.pry
67:
=> 68: machine.start(
69: use_cloud_init: true,
70: vm: vm_configuration
71: )
72:
73: @app.call(env)
[1] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)>
vm_configuration[:placement_policy] = { :hosts => [{ :host =>
'server.test.local' }], :affinity => 'pinned' }
[2] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)>
vm_configuration
=> {:initialization=>
{:host_name=>"test",
:nic_configurations=>[{:name=>"eth0", :on_boot=>true,
:boot_protocol=>"static", :ip=>{:version=>"v4",
:address=>"192.168.2.200", :gateway=>"192.168.2.1"}}],
:custom_script=>
"write_files:\n - content: |\n wat\n path:
/tmp/something.txt\n permissions: '0644'\nnetwork-interfaces: |\n
auto eth0\n iface eth0 inet static\n address 192.168.2.201\n
network 192.168.2.0\n netmask 255.255.255.0\n gateway
192.168.2.1\n dns-nameservers 192.168.2.113 192.168.2.1\n"},
:placement_policy=>{:hosts=>[{:host=>"server.test.local"}],
:affinity=>"pinned"}}
==> default: An error occured. Recovering..
==> default: Halting VM...
==> default: Waiting for VM to shutdown...
==> default: Removing VM...
/home/myoung/.rvm/gems/ruby-2.2.3/gems/ovirt-engine-sdk-4.1.2/lib/ovirtsdk4/service.rb:52:in
`raise_error': Fault reason is "Incomplete parameters". Fault detail
is "Host [id|name] required for
validateAndUpdateHostsInPlacementPolicy". HTTP response code is 400.
(OvirtSDK4::Error)
The same goes with giving an object instead of a hash object
=> 68: machine.start(
69: use_cloud_init: true,
70: vm: vm_configuration
71: )
72:
73: @app.call(env)
[1] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)>
hosts_service = env[:connection].system_service.hosts_service
[2] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)> host =
hosts_service.list(search: 'name=server.test.local')[0]
[3] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)> host.status
=> "up"
[4] pry(#<VagrantPlugins::OVirtProvider::Action::StartVM>)>
vm_configuration[:placement_policy] = { :hosts => [{ :host => host }]}
==> default: An error occured. Recovering..
==> default: Halting VM...
==> default: Waiting for VM to shutdown...
==> default: Removing VM...
/home/myoung/.rvm/gems/ruby-2.2.3/gems/ovirt-engine-sdk-4.1.2/lib/ovirtsdk4/service.rb:52:in
`raise_error': Fault reason is "Incomplete parameters". Fault detail
is "Host [id|name] required for
validateAndUpdateHostsInPlacementPolicy". HTTP response code is 400.
(OvirtSDK4::Error)
from
/home/myoung/.rvm/gems/ruby-2.2.3/gems/ovirt-engine-sdk-4.1.2/lib/ovirtsdk4/service.rb:85:in
`check_action'
from
/home/myoung/.rvm/gems/ruby-2.2.3/gems/ovirt-engine-sdk-4.1.2/lib/ovirtsdk4/services.rb:29460:in
`start'
The host is indicated using an object of type 'OvirtSDK4::Host', with
the 'name' attribute set to the host name or the 'id' attribute set to
the host id. So you need to create the 'vm_configuration' like this:
vm_configuration = OvirtSDK4::Vm.new(
placement_policy: {
hosts: [
{
name: 'myhost'
}
]
}
)
Unfortunately the Ruby doesn't provide a good mechanism to check the
types of arguments, so the error message generated isn't very helpful.
We are working on improving that. See this bug:
https://bugzilla.redhat.com/1378113
sdk should raise an exception when unknown parameter is used
When that is fixed you will receive an exception with a message like this:
The type of the 'host' attribute should be 'OvirtSDK4::Host'
but it is 'String'.
Remember that you have the Ruby SDK reference available here:
http://www.rubydoc.info/gems/ovirt-engine-sdk
The expected types of parameters and attributes is documented there. For
example, the definition of the 'VmPlacementPolicy.hosts' attribute is here:
http://www.rubydoc.info/gems/ovirt-engine-sdk/OvirtSDK4/VmPlacementPolicy...
There you can see that the expected type is Array<Host>.