本地存储相关接口
添加本地存储为主存储(AddLocalPrimaryStorage)
API请求
URLs
POST zstack/v1/primary-storage/local-storageHeaders
Authorization: OAuth the-session-uuidBody
{
"params": {
"url": "/Cloud_ps",
"name": "PS1",
"zoneUuid": "a71cbd7404e9474c81ed45d167b7eab8"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"url":"/Cloud_ps","name":"PS1","zoneUuid":"3b9a66322185343e9068b2bfd185b690"}}' \
http://localhost:8080/zstack/v1/primary-storage/local-storage参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| url | String | body(包含在params结构中) |
本地存储的路径 | 0.6 | |
| name | String | body(包含在params结构中) |
本地存储主存储名称 | 0.6 | |
| description (可选) | String | body(包含在params结构中) |
本地存储主存储的详细描述 | 0.6 | |
| type (可选) | String | body(包含在params结构中) |
类型为 LocalStorage | 0.6 | |
| zoneUuid | String | body(包含在params结构中) |
区域UUID | 0.6 | |
| resourceUuid (可选) | String | body(包含在params结构中) |
资源UUID。若指定,本地存储主存储会使用该字段值作为UUID。 | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"name": "PS1",
"url": "/Cloud_ps",
"type": "LocalStorage",
"state": "Enabled",
"status": "Connected",
"attachedClusterUuids": [
"562116d368c8467c95c53321757538dc"
]
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| uuid | String | 资源的UUID,唯一标示该资源 | 0.6 |
| zoneUuid | String | 区域UUID | 0.6 |
| name | String | 资源名称 | 0.6 |
| url | String | 0.6 | |
| description | String | 资源的详细描述 | 0.6 |
| totalCapacity | Long | 0.6 | |
| availableCapacity | Long | 0.6 | |
| totalPhysicalCapacity | Long | 0.6 | |
| availablePhysicalCapacity | Long | 0.6 | |
| systemUsedCapacity | Long | 0.6 | |
| type | String | 0.6 | |
| state | String | 0.6 | |
| status | String | 0.6 | |
| mountPath | String | 0.6 | |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
| attachedClusterUuids | List | 0.6 |
SDK示例
Java
SDK
AddLocalPrimaryStorageAction action = new AddLocalPrimaryStorageAction();
action.url = "/Cloud_ps";
action.name = "PS1";
action.zoneUuid = "e9762e3b848e4d0a8f36f1b2fe888b14";
action.sessionId = "01b750dce9e94191abd9216fe8c5e77b";
AddLocalPrimaryStorageAction.Result res = action.call();Python
SDK
AddLocalPrimaryStorageAction action = AddLocalPrimaryStorageAction()
action.url = "/Cloud_ps"
action.name = "PS1"
action.zoneUuid = "bd54c662683b4144b33a72a357064387"
action.sessionId = "b6dd1fd80b7144adbf23d4b1089d978d"
AddLocalPrimaryStorageAction.Result res = action.call()查询本地存储资源引用(QueryLocalStorageResourceRef)
API请求
URLs
GET zstack/v1/primary-storage/local-storage/resource-refsHeaders
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 7642f366a18e41d6b9144fa25b4e32fe" \
-X GET http://localhost:8080/zstack/v1/primary-storage/local-storage/resource-refs?q=uuid=18b4bc6daf0542b09b6756ddce3f87cd可查询字段
运行CLI命令行工具,输入QueryLocalStorageResourceRef并按Tab键查看所有可查询字段以及可跨表查询的资源名。
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
QueryLocalStorageResourceRefAction action = new QueryLocalStorageResourceRefAction();
action.conditions = asList("uuid=46e9ff5cd91a404382107d52a1947614");
action.sessionId = "aaaf8ed4fe224287afff3c38083279a9";
QueryLocalStorageResourceRefAction.Result res = action.call();
Python
SDK
QueryLocalStorageResourceRefAction action = QueryLocalStorageResourceRefAction()
action.conditions = ["uuid=8249a62afd0e440981775795244ab276"]
action.sessionId = "62b361c83e6a4685b13f629f3d402ed7"
QueryLocalStorageResourceRefAction.Result res = action.call()迁移本地存储上存放的云盘(LocalStorageMigrateVolume)
API请求
URLs
PUT zstack/v1/primary-storage/local-storage/volumes/{volumeUuid}/actionsHeaders
Authorization: OAuth the-session-uuidBody
{
"localStorageMigrateVolume": {
"destHostUuid": "511e02b9b8c9427c9fbbac55b8c7ec62"
},
"systemTags": [],
"userTags": []
}Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。
Curl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X PUT -d '{"localStorageMigrateVolume":{"destHostUuid":"58118467f70733cdb19f39bd07868384"}}' \
http://localhost:8080/zstack/v1/primary-storage/local-storage/volumes/f15736d2850536f3a6ea1d68f7c89b7f/actions参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| volumeUuid | String | url | 云盘UUID | 0.6 | |
| destHostUuid | String | body(包含在localStorageMigrateVolume结构中) | 目标主机UUID | 0.6 | |
| systemTags (可选) | List | body | 系统标签 | 0.6 | |
| userTags (可选) | List | body | 用户标签 | 0.6 |
API返回
返回示例
{
"inventory": {
"resourceUuid": "bad5e950cf014275bf9ba6e4cfe78a97",
"primaryStorageUuid": "81d893539a6b4ce7b9957c7a5d6c5df8",
"hostUuid": "9d250b88ae90449db567cfa18a75fecc",
"size": 2.4035328E7
}
}#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventory
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| resourceUuid | String | 0.6 | |
| primaryStorageUuid | String | 主存储UUID | 0.6 |
| hostUuid | String | 物理机UUID | 0.6 |
| size | Long | 0.6 | |
| resourceType | String | 0.6 | |
| createDate | Timestamp | 创建时间 | 0.6 |
| lastOpDate | Timestamp | 最后一次修改时间 | 0.6 |
SDK示例
Java
SDK
LocalStorageMigrateVolumeAction action = new LocalStorageMigrateVolumeAction();
action.volumeUuid = "1d4825d4845c4bba81033de367f0a03c";
action.destHostUuid = "e82e6f37aa3b472ab36b32962b2ba44c";
action.sessionId = "74b8b0a565c542e8bc146d7d9c06c764";
LocalStorageMigrateVolumeAction.Result res = action.call();Python
SDK
LocalStorageMigrateVolumeAction action = LocalStorageMigrateVolumeAction()
action.volumeUuid = "85f9e2cb4d2640b3a5fe4ec74ebccd22"
action.destHostUuid = "f841732d6c604d12bf2cbbb458f09bee"
action.sessionId = "535bc181a3aa41a0989ac795f58ba664"
LocalStorageMigrateVolumeAction.Result res = action.call()获取主机本地存储容量(GetLocalStorageHostDiskCapacity)
API请求
URLs
GET zstack/v1/primary-storage/local-storage/{primaryStorageUuid}/capacitiesHeaders
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth c5115e16f4a44fb6a66bba611f888eb3" \
-X GET http://localhost:8080/zstack/v1/primary-storage/local-storage/b839f809d5954d47aecf0b0d56fb98fa/capacities?hostUuid=b3a59363895143cf847518a0badd3ea3
参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| hostUuid (可选) | String | query | 物理机UUID | 0.6 | |
| primaryStorageUuid | String | url | 主存储UUID | 0.6 | |
| systemTags (可选) | List | query | 系统标签 | 0.6 | |
| userTags (可选) | List | query | 用户标签 | 0.6 |
API返回
返回示例
{
"inventories": [
{
"hostUuid": "02b36a53204d496290c4f2f8b31a7575",
"totalCapacity": 1.073741824E9,
"availableCapacity": 9.73078528E8,
"totalPhysicalCapacity": 1.073741824E9,
"availablePhysicalCapacity": 9.73078528E8
}
]
}| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| error | ErrorCode | 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error | 0.6 |
| inventories | List | 详情参考inventories | 0.6 |
#error
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| code | String | 错误码号,错误的全局唯一标识,例如SYS.1000, HOST.1001 | 0.6 |
| description | String | 错误的概要描述 | 0.6 |
| details | String | 错误的详细信息 | 0.6 |
| elaboration | String | 保留字段,默认为null | 0.6 |
| opaque | LinkedHashMap | 保留字段,默认为null | 0.6 |
| cause | ErrorCode | 根错误,引发当前错误的源错误,若无原错误,该字段为null | 0.6 |
#inventories
| 名字 | 类型 | 描述 | 起始版本 |
|---|---|---|---|
| hostUuid | String | 物理机UUID | 0.6 |
| totalCapacity | long | 0.6 | |
| availableCapacity | long | 0.6 | |
| totalPhysicalCapacity | long | 0.6 | |
| availablePhysicalCapacity | long | 0.6 |
SDK示例
Java
SDK
GetLocalStorageHostDiskCapacityAction action = new GetLocalStorageHostDiskCapacityAction();
action.hostUuid = "e63ea47c5aa14106a6abd89ddc8f43de";
action.primaryStorageUuid = "a193ec73e0824726bc30fa88f7f906cc";
action.sessionId = "0d48347e758c4089a85b586f6d2c0953";
GetLocalStorageHostDiskCapacityAction.Result res = action.call();Python
SDK
GetLocalStorageHostDiskCapacityAction action = GetLocalStorageHostDiskCapacityAction()
action.hostUuid = "fbaace8b570a4be6998dc376b95dcdf1"
action.primaryStorageUuid = "71d63b28517243538d83c326bc21423a"
action.sessionId = "cc34ee291d8a4d7bad091c4a66d97094"
GetLocalStorageHostDiskCapacityAction.Result res = action.call()获取迁移本地存储物理机(LocalStorageGetVolumeMigratableHosts)
检查哪些物理机可以迁移本地存储上存放的云盘。
API请求
URLs
GET zstack/v1/volumes/{volumeUuid}/migration-target-hostsHeaders
Authorization: OAuth the-session-uuidCurl示例
curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 47c467d5c9944985bfbfead8d44cfec2" \
-X GET http://localhost:8080/zstack/v1/volumes/ef7fe562459146d6bb13078821d451a8/migration-target-hosts?
参数列表
| 名字 | 类型 | 位置 | 描述 | 可选值 | 起始版本 |
|---|---|---|---|---|---|
| volumeUuid | String | url | 云盘UUID | 0.6 | |
| systemTags (可选) | List | query | 0.6 | ||
| userTags (可选) | List | query | 0.6 |
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
LocalStorageGetVolumeMigratableHostsAction action = new LocalStorageGetVolumeMigratableHostsAction();
action.volumeUuid = "dd15184d915c422686da18415b194ce9";
action.sessionId = "1ce8dcd82213420ba5aea5c488834eba";
LocalStorageGetVolumeMigratableHostsAction.Result res = action.call();Python
SDK
LocalStorageGetVolumeMigratableHostsAction action = LocalStorageGetVolumeMigratableHostsAction()
action.volumeUuid = "19a3d12dc45540f997ac0c6ad0cfb8d7"
action.sessionId = "e6d54fe5d8424c45b723f65a1136d23e"
LocalStorageGetVolumeMigratableHostsAction.Result res = action.call()