Create or Import KeyPair

Overview

Generate or import SSH keys. After generating a KeyPair, please specify the key_name parameter in the request body in Create Server request to associate the new server with SSH keys.

Classification

  • Create

API Operation Object

Synchronous / Asynchronous

  • Synchronous

Request

HTTP Request Method

  • POST

HTTP Request Path

{api_endpoint}/v2/{tenant_id}/os-keypairs

HTTP Request Header

Accept: application/json
Content-Type: application/json
X-Auth-Token: <token>

HTTP Request Body

Format

Generate KeyPair (with private key)
{
  "keypair": {
    "name": "<name>",
    "public_key": "<public_key>"
  }
}
Import KeyPair (without private key)
{
    "keypair": {
        "name": "<name>"
    }
}

Request Parameter

Input Parameters
name style format description required/optional default value action for invalid parameter response code for invalid parameter
tenant_id URL UUID ID for the tenant. required - Terminate 403, 404
token Header Authentication token string Keystone authentication token. required - Terminate 401
name Request String The name to associate with the KeyPair. It is a unique name in the tenant. Available character is 1-255 character of alphabet(a-zA-Z), number(0-9) and slash(-). required - Terminate 400, 409, 413
public_key Request String The public RSA or DSA SSH key to import. If not provided, a key is generated 2048bit RSA key. optional - Terminate 400, 500

Response

HTTP Response Header

Format

HTTP/1.1 200 OK
  • <response_code>: see “HTTP Responses” section
  • <message>: message based on the response code

Response Code

Response Codes
response code condition
200 normal end
400 specified parameter is invalid
401 unauthorized
403 tenant is not available
404 not found a specified item
405 request URL or method is invalid
409 conflict server action requests. request will be accepted only when the task_state is None
413 KeyPair is over the maximum number
415 bad media type
500 compute fault. If an error other than above has occurred, the response code is always 500.

HTTP Response Body

Format

Generate KeyPair (with private key)
{
  "keypair": {
    "name": "<name>",
    "public_key": "<public_key>",
    "private_key": "<private_key>",
    "fingerprint": "<fingerprint>",
    "user_id": "<user_id>"
  }
}
Import KeyPair (without private key)
{
  "keypair": {
    "name": "<name>",
    "public_key": "<public_key>",
    "fingerprint": "<fingerprint>",
    "user_id": "<user_id>"
  }
}

Response Parameter

Response Parameters
item format   description
keypair KeyPair Array   List KeyPairs that are associated with the tenant.

Sample Request and Response

Sample API Request

Request URI

https://baremetal-server-jp1-ecl.api.ntt.com/v2/b322a85578de48beba0f92acce57869b/os-keypairs

Request Header

POST /v2/b322a85578de48beba0f92acce57869b/os-keypairs HTTP/1.1
User-Agent: curl/7.35.0
Host: 192.168.150.51:8774
Accept: application/json
Content-Type: application/json
X-Auth-Token: 62d528dc0cca4827b0ed465efe1c2588

Request Body

Generate KeyPair (with private key)
{
  "keypair": {
    "name": "public-key",
    "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQCtzdf5vKNNSoeMfTUUj65eJLMjXfIbtc2GQn6+EEISHX6vjBzsTMdToQJEhgg+5rYlb5tc2mvPYNbPDIJV8OyV"
  }
}
Import KeyPair (without private key)
{
    "keypair": {
        "name": "generate-key"
    }
}

Sample API Response

Response Header

HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: <content-length>
Date: Thu, 17 Jul 2014 04:21:06 GMT

Response Body

Generate KeyPair (with private key)
{
  "keypair": {
    "name": "generated-key",
    "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQC9A6d3dY2K/QeCBsO+DFE1zfCn2skqZE+umJaUNy99BG25W7EnvHmwzJIzwobsc834lUCWhxQ01EUYRZUp+GLH",
    "private_key": "-----BEGIN RSA PRIVATE KEY-----\\nMIIBPAIBAAJBAL0Dp3d1jYr9B4IGw74MUTXN8KfaySpkT66YlpQ3L30EbblbsSe8\\nebDMkjPChuxzzfiVQJaHFDTURRhFlSn4YscCAwEAAQJBALvBvoAnEKRpNyUNrTHD\\nMISe/xjud3gZzyFjx+iRbSXkJCzEpJzFVxeGqhjKVl0LRVRamXbyxzzpl1izUc/m\\nAVkCIQDg8Un/I9ahOYOQHgUm3GAK7lRo9u3a0nzeejLapqKEfQIhANccdkeMkyMQ\\nLQvzC/1+NEHiKcqi+7uV5CqMtpBki7uTAiEA2IluIh3tzuX+sA02CGK8Ucl7mE+c\\nSLm3WrNnoPQoHkECIDzet/WdKNGmNSkJeJ4dxUnTZsIJhrRZQPxtXwfS+9tzAiEA\\ntGJDUKq7Z0P/pKUqVadogrJ3vkhXqy4k664PTPOEwhY=\\n-----END RSA PRIVATE KEY-----\\n",
    "fingerprint": "ce:66:48:df:f8:23:49:9c:d6:00:e3:74:d1:0c:0a:26",
    "user_id": "270dd02f-2abf-48bd-813a-f8a4470da7f7"
  }
}
Import KeyPair (without private key)
{
  "keypair": {
    "name": "public-key",
    "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQCtzdf5vKNNSoeMfTUUj65eJLMjXfIbtc2GQn6+EEISHX6vjBzsTMdToQJEhgg+5rYlb5tc2mvPYNbPDIJV8OyV",
    "fingerprint": "2c:42:86:f4:a0:2f:b9:96:a6:e5:d9:31:c8:a3:73:1d",
    "user_id": "270dd02f-2abf-48bd-813a-f8a4470da7f7"
  }
}