I need help~ Use REST API poweroff vm fail~


#1

I want to use REST API to achieve our private cloud some function,e.g:poweroff/poweron vms,create vms.
But when I test REST API at manageiq localhost,PUT and DELETE action also failed.
the error messages just like:
"
[root@localhost ~]# curl --user admin:smartvm -X POST -H “Accept: application/json” -d ‘{“action”: “poweroff”,“resources” : [{“name”:“vm-test41”}]}’ http://localhost:3000/api/vms

{“error”:{“kind”:“bad_request”,“message”:“Unsupported HTTP Method post for the Collection vms specified”,“klass”:“ApiController::BadRequestError”}}
"
"
[root@localhost ~]# curl --user admin:smartvm -i -X DELETE -H “Accept: application/json” http://localhost:3000/api/vms/502

{“error”:{“kind”:“bad_request”,“message”:“Unsupported HTTP Method delete for the Collection vms specified”,“klass”:“ApiController::BadRequestError”}}


[root@localhost ~]#curl --user admin:smartvm -i -X POST -H “Accept: application/json” -d ‘{ “action”: “poweroff” }’ http://localhost:3000/api/vms/511

{“error”:{“kind”:“bad_request”,“message”:“Unsupported HTTP Method post for the Collection vms specified”,“klass”:“ApiController::BadRequestError”}}
"
I want to know,the reason that the commander is wrong or real unsupported the action of post&delete?

I wish the master help me,Thx~


#2

@abellotti , any ideas here?


#3

IIRC the REST API is still under heavy development and if you are trying some of the example actions as they are shown in documentation, it may happen that they are not implemented yet (that confused me too when I was poking it). Here is a list of all actions that are currently implemented. Your best friend is the “actions” key in the response JSON, that contains references of all actions that are possible on the object/collection. If the “actions” key is not there or the action you want is not in the “actions” contents, bad luck, it is still not available.

Milan Falešník
Quality Engineer


#4

Correct, we haven’t enabled POSTS on vms’ yet. Reference Guide is good to peruse as it shows what’s currently implemented.


#5

Okay,I see.Thx for your help:)


#6

Got it~Thx for your help~


#7

A workaround in the mean time would be simply to call an automation_request passing as parameters the objects you wish to deal with, at the receiver method you do what you want to do like power off the vm etc…


#8

poweroff action in design, now implemented and merged as “stop” action.

POST to your VM /api/vms/:id with:
{
“action” : “stop”
}

Then you’ll get an async action result which you’ll get the task_href and query that to see when the job is done.