How to power On/Off host with Rest api?

HI Nguyen,

please post your code to authenticate secure foreman connection & create a
new host. I need such kind of solution urgent.

Thanks,

··· On Friday, 8 March 2013 20:26:55 UTC+1, 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"): > > >