Wednesday, April 27, 2016

Injection public ssh key via REST API Creating Server on RDO Mitaka

Get REST API POST request body run :-

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

***********************************************************
Afterwards REST API Code looks like
***********************************************************

[root@ip-192-169-142-127 test(keystone_demo)]# cat RestAPI.sh

#!/bin/bash -x
################################
# Injection public key to Server
################################

# Uploading public key to serve as ssh keypair
curl -g -i -X POST http://192.169.142.127:8774/v2/af755632772a42c28539091819740943/os-keypairs -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 root@ip-192-169-142-127.ip.secureserver.net\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 http://192.169.142.127:8774/v2/af755632772a42c28539091819740943/servers -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"}]}}'



Go to dashboard (login demo ):-




 
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=50.0.0.29, 192.169.142.186 |
    +--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+

[root@ip-192-169-142-127 test(keystone_demo)]# ssh cirros@192.169.142.186
    $ ifconfig
    eth0      Link encap:Ethernet  HWaddr FA:16:3E:53:3B:D6 
              inet addr:50.0.0.29  Bcast:50.0.0.255  Mask:255.255.255.0
              inet6 addr: fe80::f816:3eff:fe53:3bd6/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1
              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:127.0.0.1  Mask:255.0.0.0
              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