Updated on 2024-08-06 GMT+08:00

Copying an SSH Key Pair (V2)

Function

A tenant may contain multiple users. This API is used to copy the key pair from the target user to the current user under the same tenant account.

URI

  • URI format

    POST /v2/{project_id}/os-keypairs/copy

  • Parameter description
    Table 1 Parameter description

    Parameter

    Mandatory

    Type

    Description

    project_id

    Yes

    String

    Project ID

Requests

Table 2 Request parameters

Parameter

Mandatory

Type

Description

user_name

Yes

String

Name of the target user under the same tenant account

force

No

Boolean

Indicates whether to forcibly overwrite an existing key pair.

Responses

Table 3 Response parameters

Parameter

Mandatory

Type

Description

changed

Yes

Integer

Number of copied key pairs.

success

Yes

Array of objects

List of key pairs that were successfully copied. For details, see Table 4.

failed

Yes

Array of objects

List of key pairs that failed to be copied. For details, see Table 4.

Table 4 success/failed field description

Parameter

Mandatory

Type

Description

keypair

Yes

String

Key pair name

message

Yes

String

Task information

Examples

  • Example request
    {
     "user_name": "kpsuser"
    }
  • Example response
    {
        "changed": 2,
        "success": [
            {
                "keypair": "KeyPair-test1",
                "message": "imported"
            },
            {
                "keypair": "KeyPair-test2",
                "message": "imported"
            }
        ],
        "failed": [
            {
                "keypair": "KeyPair-test3",
                "message": "exist"
            }
        ]
    }

    or

    {
        "error_code": "KPS.XXXX",
        "error_msg": "XXXX"
    }

Status Codes

For details, see Status Codes.