Ask Your Question

The keypair injected using api doesn't match the keypair created?

asked 2016-04-26 13:21:00 -0500

soumitrakarmakar gravatar image

I created a keypair using nova api, but the keypair generated doesn't seem to work.

edit retag flag offensive close merge delete


I suggest u install rest api client in your browser and do the following: X-Auth-Token: Your Token Content-type: apllication/json Pay load: {"keypair": {"name": "testkey"}} , look at the difference.

soumitrakarmakar gravatar imagesoumitrakarmakar ( 2016-04-27 13:12:29 -0500 )edit

To download the keypair created, login with your creds to the project and type the following url:

soumitrakarmakar gravatar imagesoumitrakarmakar ( 2016-04-27 13:14:19 -0500 )edit

Then match the contents generated, u'll get it.

soumitrakarmakar gravatar imagesoumitrakarmakar ( 2016-04-27 13:15:00 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2016-04-27 05:50:20 -0500

dbaxps gravatar image

updated 2016-05-02 11:03:40 -0500

UPDATE 05/02/2016
Code bellow is addressing your question

#!/bin/bash -x
curl -g -i -X POST -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: 2ae281359a8f4b249d5e8cf36c4233c0" -d '{"keypair": {"name": "oskey1"}}' |  tail -1 >output.json
echo "Genegating rsa privare key for server access as file";
echo "-----BEGIN RSA PRIVATE KEY-----" >  oskey1.pem ;
sed 's/\\n/\
/g' <  output.json | grep -v "keypair" | grep -v "user_id" >>oskey1.pem ;
chmod 600 oskey1.pem


UPDATE 04/27/16 MSK 21:56
First thing is remind LarsKS lessons and run :-

nova --debug  keypair-add --pub-key ~/.ssh/ testkey07

Because I intend to inject public key via REST API . Finally script looks like :-
[root@ip-192-169-142-127 test(keystone_demo)]# cat

#!/bin/bash -x
# Injection public key to Server
curl -g -i -X POST -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: efb750c13fa94ff4bd3317c8dadcba4e" -d '{"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDYD2R7bGU0pWmcXk+8qARg7n9qn9YG5xiT/SP3oiorkkb1PUYvVD3vwl3z2C6j+IkTs0VSQfbVnrk4k3wZMjEayKN3VLNr7pV/EX2w5vC1vATbHi1HUrxiLKlNq9HM05JKl8gC45m3RyIjkETI3slaVThCmAXMPZPskgA2JMZmPx03b0gmCHXvtzXWMweU0CfVbgLeg5WTEyI4CovihfzC30V/AQCZytK66KYrACTlFTCfGMr8L0CilfOGFyp/Bw4i2fwKHToPAaucf5kiwjB27sXdauQpZhBnEBefpgj7wo+mefGIxbBx6bl9fi+lZUEn88lqH8olvtxaZEjqnYW1\n", "user_id": "ba77bbbe75b0408a997fa8b30ce49632", "name": "testkey07", "fingerprint": "8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d"}}'

# Creating Server
curl -g -i -X POST -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: efb750c13fa94ff4bd3317c8dadcba4e" -d '{"server": {"name": "CirrOSDevs09", "key_name" : "testkey07", "imageRef": "807c3d57-b8c3-4f59-90c3-10902ee93296", "flavorRef": "1", "max_count": 1, "min_count": 1, "networks": [{"uuid": "7c0279c7-7aa6-48a1-9799-71558e6e5979"}], "security_groups": [{"name": "default"}]}}'

Then check dashboard

image description

No problems with login via ssh

[root@ip-192-169-142-127 test(keystone_demo)]# nova list
| ID                                   | Name         | Status | Task State | Power State | Networks                                |
| d711efb5-5811-4587-966c-3459514a2175 | CirrOSDevs09 | ACTIVE | -          | Running     | demo_network=, |
[root@ip-192-169-142-127 test(keystone_demo)]# ssh cirros@
$ ifconfig
eth0      Link encap:Ethernet  HWaddr FA:16:3E:53:3B:D6  
          inet addr:  Bcast:  Mask:
          inet6 addr: fe80::f816:3eff:fe53:3bd6/64 Scope:Link
          RX packets:392 errors:0 dropped:0 overruns:0 frame:0
          TX packets:393 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:149587 (146.0 KiB)  TX bytes:147711 (144.2 KiB)

lo        Link encap:Local Loopback  
          inet addr:  Mask:
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

If you need password protection rerun ssh-keygen
Looking at code here
I guess I understand what's wrong with REST API ( in which I am very far from expert and might be wrong )

edit flag offensive delete link more


I want to use calling api, this above works but of no use to my project.

soumitrakarmakar gravatar imagesoumitrakarmakar ( 2016-04-27 06:17:16 -0500 )edit

Which one API you need Python SDK or REST API ?

dbaxps gravatar imagedbaxps ( 2016-04-27 10:07:44 -0500 )edit


soumitrakarmakar gravatar imagesoumitrakarmakar ( 2016-04-27 11:02:06 -0500 )edit
dbaxps gravatar imagedbaxps ( 2016-04-27 11:26:10 -0500 )edit

It doesn't work, I mean if I create a keypair using cli i.e nova it's ok, but when I create using the REST API it doesn't return the valid key.

soumitrakarmakar gravatar imagesoumitrakarmakar ( 2016-04-27 11:46:51 -0500 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2016-04-26 13:21:00 -0500

Seen: 639 times

Last updated: May 02 '16