Ask Your Question

curl api call to stop vm

asked 2014-05-26 09:53:22 -0500

KeithJ gravatar image

Hi , I am currently trying to facilitate a user so that he can stop /start his vm through an open-api call. I have successfully obtained a token as follows:

curl -i 'http://<ipaddress>:5000/v2.0/tokens' -X POST -H "Content-Type: application/json" -H "Accept: application/json" -d '{"auth": {"tenantName": "", "passwordCredentials": {"username": "myuser", "password": "myuser"}}}'

I am now trying to pass the token and issuse a server command as follows:

curl -i -X POST -H "Content-Type: application/json" -H 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8'
-d '{"os-stop":null} ' 'http://<ipaddress>:8774/v2.0/<tenant_id>/servers/<vm_id>/action'

eg as follows:

curl -i -X POST -H "Content-Type: application/json" 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8' -d '{"os-stop":null }' http://controller:8774/v2.0/91ca51f6a...

91ca51f6aff347089b5439931c770b39 is the tenant-id 8c67ea2e-9477-4714-bddf-092efc03b7ba is the vm-id b13a057539784d6f8a55d9d2d3a115a8 is the token-id

curl: (6) Couldn't resolve host 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8'

I know I am very close to getting this to work. Can someone help with where I am going wrong.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-05-29 10:08:12 -0500

KeithJ gravatar image

I eventually got this to work:

I created a file pause.json which looks like the following:


I then issued the following command:

 curl -i http://<controllernode>:8774/v2/<TENANT_ID>/servers/<VM_ID>/action -X POST -H "Content-Type: application/json" -H "X-Auth-Project-Id:<PROJECTNAME>" -H "X-Auth-Token: <TOKEN_ID>" -H "Accept: application/json" -T pause.json

This ended up pausing my VM. I think the Key here was to include H "Accept: application/json" on the command line

curl -i http://<controllernode>:8774/v2/<tenant_id>/servers/<vm_id>/action -X POST -H "Content-Type: application/json" -H "X-Auth-Project-Id:<projectname>" -H "X-Auth-Token: <token_id>" -H "Accept: application/json" -T pause.json

The -H "X-Auth-Project-Id:<projectname>" is optional in this case.

If you do not wish to call a file, you can replace -T pause.json with -d '{"pause":null}'

Note: use unpause to resume your server

edit flag offensive delete link more


Thanks for following this up, I managed to solve a problem that I've been sitting on for about a week by following this. Super grateful!

zxcviii gravatar imagezxcviii ( 2014-12-14 14:34:40 -0500 )edit

answered 2014-05-26 18:26:01 -0500

larsks gravatar image

Look at the error you're getting:

Couldn't resolve host 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8'

That's because curl is interpreting your X-auth-token argument as a hostname...because you're missing the -H command line argument preceding that argument. Instead of:

curl -i -X POST -H "Content-Type: application/json" 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8' -d '{"os-stop":null }' http://controller:8774/v2.0/91ca51f6a...

You want:

curl -i -X POST -H "Content-Type: application/json" -H 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8' -d '{"os-stop":null }' http://controller:8774/v2.0/91ca51f6a...

Reformatting this for clarity makes errors like that a little easier to spot:

curl -i -X POST \
  -H "Content-Type: application/json" \
  -H 'X-Auth-Token:b13a057539784d6f8a55d9d2d3a115a8' \
  -d '{"os-stop":null }' \
edit flag offensive delete link more


After adding in the -H as suggested, I get the following: "The server could not comply with the request since it is either malformed or otherwise incorrect.", "code": 400

is it possible that you could post a complete working example.

KeithJ gravatar imageKeithJ ( 2014-05-27 08:16:10 -0500 )edit

I have got a bit further in that I can now list information using the following call.

curl -s -H "X-Auth-Token: e48ccba29d0c4d91bafe9085cc36d03e"

If I issue a POST i get choices back

KeithJ gravatar imageKeithJ ( 2014-05-28 04:15:59 -0500 )edit

Thsi is the command which is coming back with choices. What am I missing:

curl -s -d '{"os-stop":null} '  -H "X-Auth-Token: e48ccba29d0c4d91bafe9085cc36d03e" |python -m json.tool
KeithJ gravatar imageKeithJ ( 2014-05-28 04:17:16 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-05-26 09:53:22 -0500

Seen: 1,308 times

Last updated: May 29 '14