Update user info using Ruby OpenNebula Cloud API

Hi,

I need to update/add user information (eg. department) using ruby command. I follow the guide in http://docs.opennebula.org/4.12/integration/system_interfaces/ruby.html and host hook script (host_error.rb)

In my script, i already done up to the initiate new client / authentication. After this, what is the API to update the user? The update will be for 1 user only as the script will be executed by providing the userid.

The manual way i do this is using oneuser command
oneuser update <user_id> <file> -a

the file content:
DEPARTMENT=IT

Hi,

The ‘oneuser update’ command uses this method internally:
http://docs.opennebula.org/doc/5.0/oca/ruby/OpenNebula/User.html#update-instance_method

Hi Carlos,

Thank you for the info. Is the following codes is correct?

template = <<-EOT
DEPARTMENT    = "IT Dept"
FULL_NAME     = "My name is "
EOT

xml = OpenNebula::User.build_xml
user  = OpenNebula::User.new(xml, client)

rc = user.update(template, append = true)
if OpenNebula.is_error?(rc)
    STDERR.puts rc.message
    exit(-1)
else
    puts "Success"
end

EDIT:
How do i pass the userid parameter?

Use the new_with_id method:
http://docs.opennebula.org/doc/5.0/oca/ruby/OpenNebula/PoolElement.html#new_with_id-class_method