Ask Your Question
0

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
1

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:

{"pause":null}

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

Comments

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
0

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 }' \
  http://controller:8774/v2.0/91ca51f6a...
edit flag offensive delete link more

Comments

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 http://10.126.70.102:8774/v2/fb889735... -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} ' http://10.126.70.102:8774/v2.0/fb88973548f04353ac3dfe10ff166a53/servers/ef6d7cd0-7a74-42db-9b22-44f8cb9a7574/actions  -H "X-Auth-Token: e48ccba29d0c4d91bafe9085cc36d03e" |python -m json.tool
KeithJ gravatar imageKeithJ ( 2014-05-28 04:17:16 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

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

Seen: 1,193 times

Last updated: May 29 '14