文档目录

SSH密钥相关接口

生成SSH密钥(GenerateSshKeyPair)

API请求

URLs
POST zstack/v1/ssh-key-pair/generate
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "ssh-key-pair",
    "description": "description"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X POST -d '{"params":{"name":"ssh-key-pair","description":"description"}}'
http://localhost:8080/zstack/v1/ssh-key-pair/generate
参数列表
名字 类型 位置 描述 可选值 起始版本
name String body(包含在params结构中) 资源名称 4.7.21
description (可选) String body(包含在params结构中) 资源的详细描述 4.7.21
systemTags (可选) List body 系统标签 4.7.21
userTags (可选) List body 用户标签 4.7.21

API返回

返回示例
{
  "inventory": {
    "uuid": "25d8c1517825305f9dbcfd5413197faf",
    "name": "ssh-key-pair",
    "publicKey": "ssh-public-key",
    "privateKey": "ssh-private-key"
  }
}
名字 类型 描述 起始版本
success boolean 4.7.21
inventory SshPrivateKeyPairInventory 详情参考inventory 4.7.21
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 4.7.21
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 4.7.21
description String 错误的概要描述 4.7.21
details String 错误的详细信息 4.7.21
elaboration String 保留字段,默认为null 4.7.21
opaque LinkedHashMap 保留字段,默认为null 4.7.21
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 4.7.21
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 4.7.21
name String 资源名称 4.7.21
description String 资源的详细描述 4.7.21
publicKey String 4.7.21
createDate Timestamp 创建时间 4.7.21
lastOpDate Timestamp 最后一次修改时间 4.7.21
privateKey String 4.7.21

SDK示例

Java SDK
GenerateSshKeyPairAction action = new GenerateSshKeyPairAction();
action.name = "ssh-key-pair";
action.description = "description";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
GenerateSshKeyPairAction.Result res = action.call();
Python SDK
GenerateSshKeyPairAction action = GenerateSshKeyPairAction()
action.name = "ssh-key-pair"
action.description = "description"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
GenerateSshKeyPairAction.Result res = action.call()

上传SSH密钥(CreateSshKeyPair)

API请求

URLs
POST zstack/v1/ssh-key-pair
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "name": "ssh-key-pair",
    "description": "description",
    "publicKey": ""
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X POST -d '{"params":{"name":"ssh-key-pair","description":"description","publicKey":""}}'
http://localhost:8080/zstack/v1/ssh-key-pair
参数列表
名字 类型 位置 描述 可选值 起始版本
name String body(包含在params结构中) 资源名称 4.7.21
description (可选) String body(包含在params结构中) 资源的详细描述 4.7.21
publicKey String body(包含在params结构中) 4.7.21
resourceUuid (可选) String body(包含在params结构中) 资源UUID 4.7.21
tagUuids (可选) List body(包含在params结构中) 标签UUID列表 4.7.21
systemTags (可选) List body 系统标签 4.7.21
userTags (可选) List body 用户标签 4.7.21

API返回

返回示例
{
  "inventory": {
    "uuid": "87460bc213b534ecaceda5a510a13771",
    "name": "ssh-key-pair",
    "publicKey": ""
  }
}
名字 类型 描述 起始版本
success boolean 4.7.21
inventory SshKeyPairInventory 详情参考inventory 4.7.21
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 4.7.21
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 4.7.21
description String 错误的概要描述 4.7.21
details String 错误的详细信息 4.7.21
elaboration String 保留字段,默认为null 4.7.21
opaque LinkedHashMap 保留字段,默认为null 4.7.21
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 4.7.21
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 4.7.21
name String 资源名称 4.7.21
description String 资源的详细描述 4.7.21
publicKey String 4.7.21
createDate Timestamp 创建时间 4.7.21
lastOpDate Timestamp 最后一次修改时间 4.7.21

SDK示例

Java SDK
CreateSshKeyPairAction action = new CreateSshKeyPairAction();
action.name = "ssh-key-pair";
action.description = "description";
action.publicKey = "";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
CreateSshKeyPairAction.Result res = action.call();
Python SDK
CreateSshKeyPairAction action = CreateSshKeyPairAction()
action.name = "ssh-key-pair"
action.description = "description"
action.publicKey = ""
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
CreateSshKeyPairAction.Result res = action.call()

删除SSH密钥(DeleteSshKeyPair)

API请求

URLs
DELETE zstack/v1/ssh-key-pair/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X DELETE http://localhost:8080/zstack/v1/ssh-key-pair/67560ca0fb1d35b7bd520d43e2cbacee?
http://localhost:8080/zstack/v1/ssh-key-pair/67560ca0fb1d35b7bd520d43e2cbacee?
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 4.7.21
systemTags (可选) List body 系统标签 4.7.21
userTags (可选) List body 用户标签 4.7.21

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:
{
	"error": {
		"code": "SYS.1001",
		"description": "A message or a operation timeout",
		"details": "Create VM on KVM timeout after 300s"
	}
}

SDK示例

Java SDK
DeleteSshKeyPairAction action = new DeleteSshKeyPairAction();
action.uuid = "67560ca0fb1d35b7bd520d43e2cbacee";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
DeleteSshKeyPairAction.Result res = action.call();
Python SDK
DeleteSshKeyPairAction action = DeleteSshKeyPairAction()
action.uuid = "67560ca0fb1d35b7bd520d43e2cbacee"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
DeleteSshKeyPairAction.Result res = action.call()

查询SSH密钥(QuerySshKeyPair)

API请求

URLs
GET zstack/v1/ssh-key-pair
GET zstack/v1/ssh-key-pair/{uuid}
Headers
Authorization: OAuth the-session-uuid
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X GET http://localhost:8080/zstack/v1/ssh-key-pair?q=uuid=1d1c2b759ab23353946035b266bd2ac1
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X GET http://localhost:8080/zstack/v1/ssh-key-pair/085e223844b03474a590f5877b53e0c8

可查询字段

运行CLI命令行工具,输入QuerySshKeyPair并按Tab键查看所有可查询字段以及可跨表查询的资源名。

API返回

返回示例
{
  "inventories": [
    {
      "uuid": "f289105c96f230e9a8add069c3a1bd69",
      "name": "ssh-key-pair",
      "publicKey": ""
    }
  ]
}
名字 类型 描述 起始版本
success boolean 4.7.21
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 4.7.21
inventories List 详情参考inventory 4.7.21
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 4.7.21
description String 错误的概要描述 4.7.21
details String 错误的详细信息 4.7.21
elaboration String 保留字段,默认为null 4.7.21
opaque LinkedHashMap 保留字段,默认为null 4.7.21
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 4.7.21
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 4.7.21
name String 资源名称 4.7.21
description String 资源的详细描述 4.7.21
publicKey String 4.7.21
createDate Timestamp 创建时间 4.7.21
lastOpDate Timestamp 最后一次修改时间 4.7.21

SDK示例

Java SDK
QuerySshKeyPairAction action = new QuerySshKeyPairAction();
action.conditions = asList("uuid=a37de2994dcb3f21bc084b67f3608849");
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
QuerySshKeyPairAction.Result res = action.call();
Python SDK
QuerySshKeyPairAction action = QuerySshKeyPairAction()
action.conditions = ["uuid=de52ff419e82330f8c0d7415ed53469a"]
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
QuerySshKeyPairAction.Result res = action.call()

更新SSH密钥(UpdateSshKeyPair)

API请求

URLs
PUT zstack/v1/ssh-key-pair/{uuid}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
  "updateSshKeyPair": {
    "name": "ssh-key-pair",
    "description": "description"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X PUT -d '{"updateSshKeyPair":{"name":"ssh-key-pair","description":"description"}}'
http://localhost:8080/zstack/v1/ssh-key-pair/ec2724093b1a3da8bf040dff4c9c1adb/actions
参数列表
名字 类型 位置 描述 可选值 起始版本
uuid String url 资源的UUID,唯一标示该资源 4.7.21
name (可选) String body(包含在updateSshKeyPair结构中) 资源名称 4.7.21
description (可选) String body(包含在updateSshKeyPair结构中) 资源的详细描述 4.7.21
systemTags (可选) List body 系统标签 4.7.21
userTags (可选) List body 用户标签 4.7.21

API返回

返回示例
{
  "inventory": {
    "uuid": "15565277de143faea29e6fcc571c4d1d",
    "name": "ssh-key-pair",
    "publicKey": ""
  }
}
名字 类型 描述 起始版本
success boolean 4.7.21
inventory SshKeyPairInventory 详情参考inventory 4.7.21
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 4.7.21
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 4.7.21
description String 错误的概要描述 4.7.21
details String 错误的详细信息 4.7.21
elaboration String 保留字段,默认为null 4.7.21
opaque LinkedHashMap 保留字段,默认为null 4.7.21
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 4.7.21
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 4.7.21
name String 资源名称 4.7.21
description String 资源的详细描述 4.7.21
publicKey String 4.7.21
createDate Timestamp 创建时间 4.7.21
lastOpDate Timestamp 最后一次修改时间 4.7.21

SDK示例

Java SDK
UpdateSshKeyPairAction action = new UpdateSshKeyPairAction();
action.uuid = "ec2724093b1a3da8bf040dff4c9c1adb";
action.name = "ssh-key-pair";
action.description = "description";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
UpdateSshKeyPairAction.Result res = action.call();
Python SDK
UpdateSshKeyPairAction action = UpdateSshKeyPairAction()
action.uuid = "ec2724093b1a3da8bf040dff4c9c1adb"
action.name = "ssh-key-pair"
action.description = "description"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
UpdateSshKeyPairAction.Result res = action.call()

云主机挂载密钥对(AttachSshKeyPairToVmInstance)

API请求

URLs
POST zstack/ssh-key-pair/{sshKeyPairUuid}/vm-instance/{vmInstanceUuid}
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {},
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X POST -d '{"params":{}}'
http://localhost:8080/zstack/v1/ssh-key-pair/9d4fe97b6e0a3d65bca85b093e74d6c9/vm-instance/e76f9792afac3bca8aec7a5d4e768197
参数列表
名字 类型 位置 描述 可选值 起始版本
vmInstanceUuid String url 云主机UUID 4.7.21
sshKeyPairUuid String url 4.7.21
systemTags (可选) List body 系统标签 4.7.21
userTags (可选) List body 用户标签 4.7.21

API返回

返回示例
{
  "inventory": {
    "uuid": "03da892de78c34d8b13e210d068caa8a",
    "name": "ssh-key-pair",
    "publicKey": ""
  }
}
名字 类型 描述 起始版本
success boolean 4.7.21
inventory SshKeyPairInventory 详情参考inventory 4.7.21
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 4.7.21
#error
名字 类型 描述 起始版本
code String 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 4.7.21
description String 错误的概要描述 4.7.21
details String 错误的详细信息 4.7.21
elaboration String 保留字段,默认为null 4.7.21
opaque LinkedHashMap 保留字段,默认为null 4.7.21
cause ErrorCode 根错误,引发当前错误的源错误,若无原错误,该字段为null 4.7.21
#inventory
名字 类型 描述 起始版本
uuid String 资源的UUID,唯一标示该资源 4.7.21
name String 资源名称 4.7.21
description String 资源的详细描述 4.7.21
publicKey String 4.7.21
createDate Timestamp 创建时间 4.7.21
lastOpDate Timestamp 最后一次修改时间 4.7.21

SDK示例

Java SDK
AttachSshKeyPairToVmInstanceAction action = new AttachSshKeyPairToVmInstanceAction();
action.vmInstanceUuid = "e76f9792afac3bca8aec7a5d4e768197";
action.sshKeyPairUuid = "9d4fe97b6e0a3d65bca85b093e74d6c9";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
AttachSshKeyPairToVmInstanceAction.Result res = action.call();
Python SDK
AttachSshKeyPairToVmInstanceAction action = AttachSshKeyPairToVmInstanceAction()
action.vmInstanceUuid = "e76f9792afac3bca8aec7a5d4e768197"
action.sshKeyPairUuid = "9d4fe97b6e0a3d65bca85b093e74d6c9"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
AttachSshKeyPairToVmInstanceAction.Result res = action.call()

云主机卸载密钥对(DetachSshKeyPairFromVmInstance)

API请求

URLs
DELETE zstack/v1/ssh-key-pair/{sshKeyPairUuid}/vm-instance/{vmInstanceUuid}
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {},
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTagsuserTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8"
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c"
-X DELETE
http://localhost:8080/zstack/v1/ssh-key-pair/9be9cb6b56b13746a99660a0d07a0770/vm-instance/dd734d0cd5c53bcca48cec9d2b4aa6d6?
参数列表
名字 类型 位置 描述 可选值 起始版本
vmInstanceUuid String url 云主机UUID 4.7.21
sshKeyPairUuid String url 4.7.21
systemTags (可选) List body 系统标签 4.7.21
userTags (可选) List body 用户标签 4.7.21

API返回

该API成功时返回一个空的JSON结构{},出错时返回的JSON结构包含一个error字段,例如:
{
	"error": {
		"code": "SYS.1001",
		"description": "A message or a operation timeout",
		"details": "Create VM on KVM timeout after 300s"
	}
}

SDK示例

Java SDK
DetachSshKeyPairFromVmInstanceAction action = new DetachSshKeyPairFromVmInstanceAction();
action.vmInstanceUuid = "dd734d0cd5c53bcca48cec9d2b4aa6d6";
action.sshKeyPairUuid = "9be9cb6b56b13746a99660a0d07a0770";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
DetachSshKeyPairFromVmInstanceAction.Result res = action.call();
Python SDK
DetachSshKeyPairFromVmInstanceAction action = DetachSshKeyPairFromVmInstanceAction()
action.vmInstanceUuid = "dd734d0cd5c53bcca48cec9d2b4aa6d6"
action.sshKeyPairUuid = "9be9cb6b56b13746a99660a0d07a0770"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
DetachSshKeyPairFromVmInstanceAction.Result res = action.call()
开发手册 | 5.5.30 | ZStack Cloud · ZCF | ZStack 资源中心