How to power On/Off host with Rest api?

Check out this Stack Overflow post:

Doesn't look like you can grab the authenticity_token ahead of time.

Check out Ohad's post on creating a VM:

Looks like he has a part that powers on the host…

HTH's,
Romeo

··· On Fri, Mar 8, 2013 at 9:26 AM, Viet Nguyen wrote:

From my Java Rest client I’m able to connect to a secure (basic http auth)
Foreman instance and create new hosts but can’t figure out a way to power
On/Off a host.

No luck with mimicking the browser request [2] either from java or curl.
It seems like I need to first login and somehow obtain authenticity_token
for subsequent requests.

Foreman logs

*1. Brower request (working): *

Started POST “/hosts/vnguyentest102/power?power_action=start” for
10.3.234.230 at Fri Mar 08 11:01:44 -0500 2013
Processing by HostsController#power as HTML
Parameters:
{“authenticity_token”=>“6pm5VCrOFd1AKbJTzSHOEEKh3HlSJjlK3VJ8ntFx2I=”,
“power_action”=>“start”, “id”=>“vnguyentest102”}
Redirected to https://******/hosts/vnguyentest102
Completed 302 Found in 810ms

2. Rest api - PUT (not working)

Started PUT “/hosts/vnguyentest102/power?power_action=start” for
10.3.234.230 at Fri Mar 08 12:20:00 -0500 2013
Processing by HostsController#power as HTML
Parameters: {“power_action”=>“start”, “id”=>“vnguyentest102”}
Redirected to https://******/users/login
Completed 302 Found in 35ms

3. Rest api - POST (not working)

Started POST “/hosts/vnguyentest102/power?power_action=start” for
10.3.234.230 at Fri Mar 08 12:45:36 -0500 2013
ActionController::RoutingError (No route matches
“/hosts/vnguyentest102/power”):


You received this message because you are subscribed to the Google Groups
“Foreman users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at http://groups.google.com/group/foreman-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Romeo

Unfortunately powerup didn't work

unknown attribute: powerup (ActiveRecord::UnknownAttributeError)

One clarification I'm aware that during host creation you can pass in
{compute_attributes {start=1}} to start VM. What I want to do via Rest is
like clicking on Power On/Off button.

··· On Friday, March 8, 2013 4:51:10 PM UTC-5, Romeo Theriault wrote: > > Check out this Stack Overflow post: > > > http://stackoverflow.com/questions/941594/understand-rails-authenticity-token > > Doesn't look like you can grab the authenticity_token ahead of time. > > Check out Ohad's post on creating a VM: > > http://blog.theforeman.org/2012/01/creating-new-host-using-foreman-api.html > > Looks like he has a part that powers on the host... > > HTH's, > Romeo >

Hi Viet,

did you manage to start a vm during build with {compute_attributes
{start=1}} because it' s not working in our example.

  "compute_attributes": {
    "cpus": 1,
    "cluster": "DevOps",
    "start": 1,
    "path": "/Datencenter/xxxx/vm/DevOps",
    "interfaces_attributes": {
      "new_interfaces": {
        "_delete": "",
        "network": "VM Network"
      },
      "0": {
        "_delete": "",
        "network": "VMNetwork69"
      }
    },

greetings

daniel

··· Am Samstag, 9. März 2013 00:54:13 UTC+1 schrieb Viet Nguyen: > > > > Unfortunately powerup didn't work > > *unknown attribute: powerup (ActiveRecord::UnknownAttributeError)* > > One clarification I'm aware that during host creation you can pass in > {compute_attributes {start=1}} to start VM. What I want to do via Rest is > like clicking on Power On/Off button. > > > > > On Friday, March 8, 2013 4:51:10 PM UTC-5, Romeo Theriault wrote: >> >> Check out this Stack Overflow post: >> >> >> http://stackoverflow.com/questions/941594/understand-rails-authenticity-token >> >> Doesn't look like you can grab the authenticity_token ahead of time. >> >> Check out Ohad's post on creating a VM: >> >> >> http://blog.theforeman.org/2012/01/creating-new-host-using-foreman-api.html >> >> Looks like he has a part that powers on the host... >> >> HTH's, >> Romeo >> > > >