Ask Your Question

Revision history [back]

Make this test

# . keystonerc_demo 
# nova keypair-add oskey1 > oskey1.priv
# chmod 600 oskey1.priv
# nova boot --flavor 1 --key_name oskey1 --image \
    image_id  --nic net-id=private-net_id CirrOSDevs

UPDATE 04/27/16 MSK 19:16

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


  #!/usr/bin/env python
    import sys
    import os
    import time
    from novaclient.v2.client import Client

    def get_nova_creds():
        d = {}
        d['username'] = os.environ['OS_USERNAME']
        d['api_key'] = os.environ['OS_PASSWORD']
        d['auth_url'] = os.environ['OS_AUTH_URL']
        d['project_id'] = os.environ['OS_TENANT_NAME']
        return d


    total = len(sys.argv)
    cmdargs = str(sys.argv)
    print ("The total numbers of args passed to the script: %d " % total)
    print ("Args list: %s " % cmdargs)
    print ("First argument: %s" % str(sys.argv[1]))

    creds = get_nova_creds()
    nova = Client(**creds)
    if not nova.keypairs.findall(name="oskeymitaka1"):
        with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
            nova.keypairs.create(name="oskeymitaka1", public_key=fpubkey.read())


    image = nova.images.find(name=str(sys.argv[1]))
    flavor = nova.flavors.find(name="m1.tiny")


    # Select tenant's network

    nova.networks.list()
    network = nova.networks.find(label="demo_network")
    nics = [{'net-id': network.id}]


    # Starting nova instance

    instance = nova.servers.create(name="CirrOSDevs05", image=image,
                      flavor=flavor,
                      key_name="oskeymitaka1", nics=nics )

    # Poll at 5 second intervals, until the status is no longer 'BUILD'
    status = instance.status
    while status == 'BUILD':
        time.sleep(5)
        # Retrieve the instance again so the status field updates
        instance = nova.servers.get(instance.id)
        status = instance.status
    print "status: %s" % status

[root@ip-192-169-142-127 test(keystone_demo)]# python createServer1.py CirrOS034-Image

The total numbers of args passed to the script: 2 
Args list: ['createServer1.py', 'CirrOS034-Image'] 
First argument: CirrOS034-Image
status: ACTIVE
[root@ip-192-169-142-127 test(keystone_demo)]# nova list

+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+ | ID                                   | Name         | Status | Task State | Power State | Networks                 |
+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+ | b731e14c-0af8-4c7d-bab0-e27b5aea4441 | CirrOSDevs05 | ACTIVE | -          | Running     | demo_network=50.0.0.26,
192.169.142.184 |
+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+ [root@ip-192-169-142-127 test(keystone_demo)]# ssh cirros@192.169.142.184 The authenticity of host '192.169.142.184 (192.169.142.184)' can't be established. RSA key fingerprint is 70:4c:75:b2:2d:96:0a:0e:7b:d1:56:5c:0f:a2:42:03. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.169.142.184' (RSA) to the list of known hosts. $ ifconfig eth0      Link encap:Ethernet HWaddr FA:16:3E:66:12:7E  
          inet addr:50.0.0.26  Bcast:50.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::f816:3eff:fe66:127e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1
          RX packets:114 errors:0 dropped:0 overruns:0 frame:0
          TX packets:133 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:15535 (15.1 KiB)  TX bytes:14494 (14.1 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)

$ uname -a Linux cirrosdevs05
3.2.0-80-virtual #116-Ubuntu SMP Mon Mar 23 17:28:52 UTC 2015 x86_64 GNU/Linux

Make this test

# . keystonerc_demo 
# nova keypair-add oskey1 > oskey1.priv
# chmod 600 oskey1.priv
# nova boot --flavor 1 --key_name oskey1 --image \
    image_id  --nic net-id=private-net_id CirrOSDevs

UPDATE 04/27/16 MSK 19:16
Creating ssh keypair for tenant demo , previously obtained X-Auth-Token via standard request ( keystone api v2 )

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


  #!/usr/bin/env python
    import sys
    import os
    import time
    from novaclient.v2.client import Client

    def get_nova_creds():
        d = {}
        d['username'] = os.environ['OS_USERNAME']
        d['api_key'] = os.environ['OS_PASSWORD']
        d['auth_url'] = os.environ['OS_AUTH_URL']
        d['project_id'] = os.environ['OS_TENANT_NAME']
        return d


    total = len(sys.argv)
    cmdargs = str(sys.argv)
    print ("The total numbers of args passed to the script: %d " % total)
    print ("Args list: %s " % cmdargs)
    print ("First argument: %s" % str(sys.argv[1]))

    creds = get_nova_creds()
    nova = Client(**creds)
    if not nova.keypairs.findall(name="oskeymitaka1"):
        with open(os.path.expanduser('~/.ssh/id_rsa.pub')) as fpubkey:
            nova.keypairs.create(name="oskeymitaka1", public_key=fpubkey.read())


    image = nova.images.find(name=str(sys.argv[1]))
    flavor = nova.flavors.find(name="m1.tiny")


    # Select tenant's network

    nova.networks.list()
    network = nova.networks.find(label="demo_network")
    nics = [{'net-id': network.id}]


    # Starting nova instance

    instance = nova.servers.create(name="CirrOSDevs05", image=image,
                      flavor=flavor,
                      key_name="oskeymitaka1", nics=nics )

    # Poll at 5 second intervals, until the status is no longer 'BUILD'
    status = instance.status
    while status == 'BUILD':
        time.sleep(5)
        # Retrieve the instance again so the status field updates
        instance = nova.servers.get(instance.id)
        status = instance.status
    print "status: %s" % status

[root@ip-192-169-142-127 test(keystone_demo)]# python createServer1.py CirrOS034-Image

The total numbers of args passed to the script: 2 
Args list: ['createServer1.py', 'CirrOS034-Image'] 
First argument: CirrOS034-Image
status: ACTIVE
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: c6726c6191b04c57b9ebb8050ab110e4" -d '{"keypair": {"name": "testkey"}}'
HTTP/1.1 200 OK
Content-Length: 2294
Content-Type: application/json
X-Compute-Request-Id: req-0440816b-ad6c-46f7-a97b-d1bdd57b3389
Date: Wed, 27 Apr 2016 16:49:16 GMT

Output :-

{"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtQ6xzwWalWEF3s+7fr7h4UREqkSlLGBabWnd3NF/oXehFxLbAESMukvHdZMYo6oAwpZ1Hg6Myl5WL5SE1SvYCTZ/7olF36SzfHEMyRwwVn88fijn75OPtnRCV/W0gOTevWVu/gnzcaJPI9OXCPG3JzNKkIs2muRGw8CTXseYaar95Ekf44IK9FBOz7i5pcn8YARtlle0fOAuV+idzIB5rpp8vMkndxfi8IPxKa35/h4Gp3EQnubqaXpE2sIZGHySmcWkTqg/Fng43m2duc1fmOpfdbB8WXdZKz3NGk0NMpsqihH02VPuvpNuLsDFZZ+G2ovjEWlBINb+8u3RpHDIp Generated-by-Nova", "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEqgIBAAKCAQEA7UOsc8FmpVhBd7Pu36+4eFERKpEpSxgWm1p3dzRf6F3oRcS2\nwBEjLpLx3WTGKOqAMKWdR4OjMpeVi+UhNUr2Ak2f+6JRd+ks3xxDMkcMFZ/PH4o5\n++Tj7Z0Qlf1tIDk3r1lbv4J83GiTyPTlwjxtyczSpCLNprkRsPAk17HmGmq/eRJH\n+OCCvRQTs+4uaXJ/GAEbZZXtHzgLlfoncyAea6afLzJJ3cX4vCD8Smt+f4eBqdxE\nJ7m6ml6RNrCGRh8kpnFpE6oPxZ4ON5tnbnNX5jqX3WwfFl3WSs9zRpNDTKbKooR9\nNlT7r6Tbi7AxWWfhtqL4xFpQSDW/vLt0aRwyKQIDAQABAoIBACbg5vpU37AKZTfr\nOSJYVf8JManq/Xw7p0Cvs1HKOEkIUk5UbKnOZRh1pcJkiAAeZQETslEMpgpdQnkZ\nA7cK4IMCG0wNjhH7GIo6xFwRvk4w0KzXZqb7G8pM6XHahC46kgBewSUBidpIHKda\nUefhJRBjSsTwmw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fdDkuSnkO373175SyYlKUNyvRadjdLA==\n-----END RSA PRIVATE KEY-----\n", "user_id": "ba77bbbe75b0408a997fa8b30ce49632", "name": "testkey", "fingerprint":"da:6d:37:d9:9f:ae:6f:8c:0a:d7:d4:2b:6d:66:d3:5b"}}

[root@ip-192-169-142-127 test(keystone_demo)]# nova list +--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+ | ID keypair-list

+-----------------+-------------------------------------------------+
| Name         | Status | Task State | Power State | Networks                 |
+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+ | b731e14c-0af8-4c7d-bab0-e27b5aea4441 | CirrOSDevs05 | ACTIVE | -          | Running     | demo_network=50.0.0.26,
192.169.142.184 |
+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+ [root@ip-192-169-142-127 test(keystone_demo)]# ssh cirros@192.169.142.184 The authenticity of host '192.169.142.184 (192.169.142.184)' can't be established. RSA key fingerprint is 70:4c:75:b2:2d:96:0a:0e:7b:d1:56:5c:0f:a2:42:03. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.169.142.184' (RSA) to the list of known hosts. $ ifconfig eth0      Link encap:Ethernet HWaddr FA:16:3E:66:12:7E  
          inet addr:50.0.0.26  Bcast:50.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::f816:3eff:fe66:127e/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1400  Metric:1
          RX packets:114 errors:0 dropped:0 overruns:0 frame:0
          TX packets:133 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:15535 (15.1 KiB)  TX bytes:14494 (14.1 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)

$ uname -a Linux cirrosdevs05
3.2.0-80-virtual #116-Ubuntu SMP Mon Mar 23 17:28:52 UTC 2015 x86_64 GNU/Linux
   | Fingerprint                                     |
+-----------------+-------------------------------------------------+
| oskeymitaka0412 | c7:5f:50:33:03:22:88:1c:62:46:45:ff:8d:85:ae:78 |
| oskeymitaka     | 8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d |
| oskeymitaka1    | 8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d |
| testkey         | da:6d:37:d9:9f:ae:6f:8c:0a:d7:d4:2b:6d:66:d3:5b |
+-----------------+-------------------------------------------------+

Make this test

# . keystonerc_demo 
# nova keypair-add oskey1 > oskey1.priv
# chmod 600 oskey1.priv
# nova boot --flavor 1 --key_name oskey1 --image \
    image_id  --nic net-id=private-net_id CirrOSDevs

UPDATE 04/27/16 MSK 19:16
Creating ssh keypair for tenant demo , previously obtained X-Auth-Token via standard request ( keystone api v2 )

[root@ip-192-169-142-127 test(keystone_demo)]# 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: c6726c6191b04c57b9ebb8050ab110e4" -d '{"keypair": {"name": "testkey"}}'
HTTP/1.1 200 OK
Content-Length: 2294
Content-Type: application/json
X-Compute-Request-Id: req-0440816b-ad6c-46f7-a97b-d1bdd57b3389
Date: Wed, 27 Apr 2016 16:49:16 GMT

Output :-

{"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtQ6xzwWalWEF3s+7fr7h4UREqkSlLGBabWnd3NF/oXehFxLbAESMukvHdZMYo6oAwpZ1Hg6Myl5WL5SE1SvYCTZ/7olF36SzfHEMyRwwVn88fijn75OPtnRCV/W0gOTevWVu/gnzcaJPI9OXCPG3JzNKkIs2muRGw8CTXseYaar95Ekf44IK9FBOz7i5p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N0kbvP5009XtNuBrJBG6o7i+oF98DLgN0CseKeWeTyKuo41AoIAgQD8\ni+6SXEUN+GgcEjAVV1c27hLTPseTbU2wdqFtCBUFW0nmyq0xxAYD8zOqiG2CEwAm\nUtBCpxedbuyRap982q4fh9ycYPZTQR+R4T419OhhqGX1fTtALp4Aj8VWWPhyJrs4\n0Iq42mwGWEcMpjXpp8GphN9Apt2a9I9dMdLbnX2ipQKCAIEAtei9Lc+umXevnDPm\nTh5DUoiExLWASmJiaSUaoZoxo0JL0KxkA9hE8g0n7SgNeP5WBg4cGFGetXapZYZU\n8MEPsepacxbfGh3aXdwJ8xNKhYzH6x+wYy/Vkt09VZdQbJMe/JfL1OowmAo3nBSX\nWqWg9Ypsv/5IrDkHNTKh1kHTorUCggCBAJN8IOJGkmlbNWmXUY9VB3Djzgih9Clr\nvuAcF5+2BZiwPFNU75pNkPnDkNu5esJo2ECJQmh6bncZbXxq2SMwDloJnNOSaKgs\nMwSdlxgpo4BMuOaJsQ2Fa+6GB8eqg8UeS14do7XakRWPfkar1nZS6u1V1I9MI8S3\np/XUAAETU2ilAoIAgQCVLois+hSqnhJ9HR3VEqkNBpBzXVLujSLg8ctG/sjihmYK\nJ5j1Qu3gBJ1Y74HWR5kXjN1uLDXO9Z2METEkDq7huLbuJJk5rsInlHT8qGnL8mX2\nKBHooLNrnpgqkjdzHFbMWeJ4+n7xVgSfdDkuSnkO373175SyYlKUNyvRadjdLA==\n-----END RSA PRIVATE KEY-----\n", "user_id": "ba77bbbe75b0408a997fa8b30ce49632", "name": "testkey", "fingerprint":"da:6d:37:d9:9f:ae:6f:8c:0a:d7:d4:2b:6d:66:d3:5b"}}

[root@ip-192-169-142-127 test(keystone_demo)]# nova keypair-list

+-----------------+-------------------------------------------------+
| Name            | Fingerprint                                     |
+-----------------+-------------------------------------------------+
| oskeymitaka0412 | c7:5f:50:33:03:22:88:1c:62:46:45:ff:8d:85:ae:78 |
| oskeymitaka     | 8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d |
| oskeymitaka1    | 8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d |
| testkey         | da:6d:37:d9:9f:ae:6f:8c:0a:d7:d4:2b:6d:66:d3:5b |
+-----------------+-------------------------------------------------+

Make this test

# . keystonerc_demo 
# nova keypair-add oskey1 > oskey1.priv
# chmod 600 oskey1.priv
# nova boot --flavor 1 --key_name oskey1 --image \
    image_id  --nic net-id=private-net_id CirrOSDevs
Works for me , see
http://bderzhavets.blogspot.com/2016/04/rest-api-creating-ssh-kypair-and-server.html
END UPDATE

UPDATE 04/27/16 MSK 19:16
Creating ssh keypair for tenant demo , previously obtained X-Auth-Token via standard request ( keystone api v2 )
21:56
First thing remind LarsKS lessons and run :-

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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: c6726c6191b04c57b9ebb8050ab110e4" efb750c13fa94ff4bd3317c8dadcba4e" -d '{"keypair": {"name": "testkey"}}'
HTTP/1.1 200 OK
Content-Length: 2294
Content-Type: application/json
X-Compute-Request-Id: req-0440816b-ad6c-46f7-a97b-d1bdd57b3389
Date: Wed, 27 Apr 2016 16:49:16 GMT

Output :-

{"keypair": {"public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDtQ6xzwWalWEF3s+7fr7h4UREqkSlLGBabWnd3NF/oXehFxLbAESMukvHdZMYo6oAwpZ1Hg6Myl5WL5SE1SvYCTZ/7olF36SzfHEMyRwwVn88fijn75OPtnRCV/W0gOTevWVu/gnzcaJPI9OXCPG3JzNKkIs2muRGw8CTXseYaar95Ekf44IK9FBOz7i5pcn8YARtlle0fOAuV+idz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kiwjB27sXdauQpZhBnEBefpgj7wo+mefGIxbBx6bl9fi+lZUEn88lqH8olvtxaZEjqnYW1 root@ip-192-169-142-127.ip.secureserver.net\n", "user_id": "ba77bbbe75b0408a997fa8b30ce49632", "name": "testkey", "fingerprint":"da:6d:37:d9:9f:ae:6f:8c:0a:d7:d4:2b:6d:66:d3:5b"}}
"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"}]}}'

Then check dashboard

image description

No problems with login via ssh

[root@ip-192-169-142-127 test(keystone_demo)]# nova keypair-list

+-----------------+-------------------------------------------------+
list
+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+
| ID                                   | Name            | Fingerprint      | Status | Task State | Power State | Networks                                |
+-----------------+-------------------------------------------------+
| oskeymitaka0412 | c7:5f:50:33:03:22:88:1c:62:46:45:ff:8d:85:ae:78 +--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+
| d711efb5-5811-4587-966c-3459514a2175 | CirrOSDevs09 | ACTIVE | -          | Running     | demo_network=50.0.0.29, 192.169.142.186 |
| oskeymitaka     | 8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d |
| oskeymitaka1    | 8c:7d:df:0c:8b:ce:e6:27:69:68:35:98:bc:12:25:1d |
| testkey         | da:6d:37:d9:9f:ae:6f:8c:0a:d7:d4:2b:6d:66:d3:5b |
+-----------------+-------------------------------------------------+
+--------------------------------------+--------------+--------+------------+-------------+-----------------------------------------+
[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)

Works for me , see
http://bderzhavets.blogspot.com/2016/04/rest-api-creating-ssh-kypair-and-server.html
END UPDATE

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

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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"}]}}'

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=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)

END UPDATE

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

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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"}]}}'

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=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
END UPDATE

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

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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"}]}}'

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=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
Looking at code here http://docs.openstack.org/user-guide/sdk_configure_access_security_instances.html
I guess I understand what's wrong with REST API ( in which I am very far from expert and might be wrong )
END UPDATE

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

#!/bin/bash -x
curl -g -i -X POST http://192.169.142.127:8774/v2//os-keypairs -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: 2ae281359a8f4b249d5e8cf36c4233c0" -d '{"keypair": {"name": "oskey1"}}' | tee log1 | 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

END UPDATE

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

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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"}]}}'

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=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
Looking at code here http://docs.openstack.org/user-guide/sdk_configure_access_security_instances.html
I guess I understand what's wrong with REST API ( in which I am very far from expert and might be wrong )
END UPDATE

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

#!/bin/bash -x
curl -g -i -X POST http://192.169.142.127:8774/v2//os-keypairs -H "User-Agent: python-novaclient" -H "Content-Type: application/json" -H "Accept: application/json" -H "X-Auth-Token: 2ae281359a8f4b249d5e8cf36c4233c0" -d '{"keypair": {"name": "oskey1"}}' | tee log1 |  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

END UPDATE

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

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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"}]}}'

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=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
Looking at code here http://docs.openstack.org/user-guide/sdk_configure_access_security_instances.html
I guess I understand what's wrong with REST API ( in which I am very far from expert and might be wrong )
END UPDATE

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

#!/bin/bash -x
curl -g -i -X POST http://192.169.142.127:8774/v2//os-keypairs http://192.169.142.127:8774/v2/052b16e56537467d8161266b52a43b54/os-keypairs -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

END UPDATE

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

nova --debug  keypair-add --pub-key ~/.ssh/id_rsa.pub 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 RestAPI.sh

#!/bin/bash -x
# Injection public key to Server
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"}]}}'

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=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
Looking at code here http://docs.openstack.org/user-guide/sdk_configure_access_security_instances.html
I guess I understand what's wrong with REST API ( in which I am very far from expert and might be wrong )
END UPDATE