文档目录

本地存储相关接口

添加本地存储为数据存储(AddLocalPrimaryStorage)

API请求

URLs
POST zstack/v1/primary-storage/local-storage
Headers
Authorization: OAuth the-session-uuid
Body
{
"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 ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
inventory PrimaryStorageInventory 详情参考inventory 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
#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-refs
Headers
Authorization: OAuth the-session-uuid
Curl示例
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}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
"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 ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 0.6
inventory LocalStorageResourceRefInventory 详情参考inventory 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
#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}/capacities
Headers
Authorization: OAuth the-session-uuid

Curl示例

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-hosts
Headers
Authorization: OAuth the-session-uuid

Curl示例

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

获取主机磁盘信息 (GetPhysicalMachineBlockDevices)

API请求

URLs
GET zstack/v1/host/get-block-devices
Headers
Authorization: OAuth the-session-uuid

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth 47c467d5c9944985bfbfead8d44cfec2" \
-X GET http://localhost:8080/zstack/v1/host/get-block-devices?username=username&password=password&sshPort=22&hostName=192.168.1.1
参数列表
名字 类型 位置 描述 可选值 起始版本
username String query 主机名 4.3.0
password (可选) String query 主机密码 4.3.0
sshPort Integer query 主机端口 4.3.0
hostName String query 主机IP 4.3.0
excludedTypes (可选) List query 指定排除的磁盘类型 4.3.0
systemTags (可选) List query 系统标签 4.3.0
userTags (可选) List query 用户标签 4.3.0

API返回

返回示例
{
  "blockDevices": {
    "unusedBlockDevices": [
      {
        "name": "/dev/vdb",
        "type": "disk",
        "size": 322122547200,
        "used": 0,
        "available": 0,
        "physicalSector": 512,
        "logicalSector": 512,
        "partitionTable": "msdos",
        "usedRatio": 0,
        "multipath": false
      },
      {
        "name": "/dev/vdc",
        "type": "disk",
        "size": 429496729600,
        "used": 0,
        "available": 0,
        "physicalSector": 512,
        "logicalSector": 512,
        "partitionTable": "unknown",
        "usedRatio": 0,
        "multipath": false
      }
    ],
    "usedBlockDevices": [
      {
        "name": "/dev/vda",
        "type": "disk",
        "size": 429496729600,
        "used": 0,
        "available": 0,
        "physicalSector": 512,
        "logicalSector": 512,
        "children": [
          {
            "name": "/dev/vda1",
            "type": "part",
            "size": 1073741824,
            "used": 0,
            "available": 0,
            "physicalSector": 512,
            "logicalSector": 512,
            "mountPoint": "/boot",
            "partitionTable": "unknown",
            "usedRatio": 0,
            "multipath": false
          },
          {
            "name": "/dev/vda2",
            "type": "part",
            "size": 428421939200,
            "used": 0,
            "available": 0,
            "physicalSector": 512,
            "logicalSector": 512,
            "children": [
              {
                "name": "/dev/mapper/zstack-root",
                "type": "lvm",
                "size": 419950493696,
                "used": 0,
                "available": 0,
                "physicalSector": 512,
                "logicalSector": 512,
                "mountPoint": "/",
                "partitionTable": "unknown",
                "usedRatio": 0,
                "multipath": false
              },
              {
                "name": "/dev/mapper/zstack-swap",
                "type": "lvm",
                "size": 8468299776,
                "used": 0,
                "available": 0,
                "physicalSector": 512,
                "logicalSector": 512,
                "mountPoint": "[SWAP]",
                "partitionTable": "unknown",
                "usedRatio": 0,
                "multipath": false
              }
            ],
            "partitionTable": "unknown",
            "usedRatio": 0,
            "multipath": false
          }
        ],
        "partitionTable": "unknown",
        "usedRatio": 0,
        "multipath": false
      }
    ]
  }
}
名字 类型 描述 起始版本
success boolean 4.3.0
blockDevices BlockDevices 详情参考blockDevices 4.3.0
error ErrorCode 错误码,若不为null,则表示操作失败, 操作成功时该字段为null。 详情参考error 4.3.0
#blockDevices
名字 类型 描述 起始版本
unusedBlockDevices List 详情参考unusedBlockDevices 4.3.0
usedBlockDevices List 详情参考usedBlockDevices 4.3.0
#unusedBlockDevices
名字 类型 描述 起始版本
name String 硬盘设备名字 zsv 4.3.0
type String 磁盘类型 zsv 4.3.0
size long 磁盘容量 zsv 4.3.0
used long 磁盘已使用容量 zsv 4.10.0
available long 磁盘可使用容量 zsv 4.10.0
physicalSector long 物理扇区大小 zsv 4.3.0
logicalSector long 逻辑扇区大小 zsv 4.3.0
mountPoint String 挂载点 zsv 4.3.0
partitionTable String 分区表类型 zsv 4.3.0
fsType String 文件系统类型 zsv 4.10.0
serialNumber String 序列号 zsv 4.10.0
model String 型号 zsv 4.10.0
mediaType String 介质类型 zsv 4.10.0
usedRatio String 使用率 zsv 4.10.0
smartPassed Boolean 获取磁盘smart状态 zsv 4.10.0
smartMessage String 获取磁盘smart状态失败时输出信息 zsv 4.10.0
multipath boolean 是否为多路径设备;true 表示该磁盘自身为 multipath 设备或为 multipath 底层路径盘 zsv 5.0.0
children List 详情参考children zsv 4.3.0
#usedBlockDevices
名字 类型 描述 起始版本
name String 硬盘设备名字 zsv 4.3.0
type String 磁盘类型 zsv 4.3.0
size long 磁盘容量 zsv 4.3.0
used long 磁盘已使用容量 zsv 4.10.0
available long 磁盘可使用容量 zsv 4.10.0
physicalSector long 物理扇区大小 zsv 4.3.0
logicalSector long 逻辑扇区大小 zsv 4.3.0
mountPoint String 挂载点 zsv 4.3.0
partitionTable String 分区表类型 zsv 4.3.0
fsType String 文件系统类型 zsv 4.10.0
serialNumber String 序列号 zsv 4.10.0
model String 型号 zsv 4.10.0
mediaType String 介质类型 zsv 4.10.0
usedRatio String 使用率 zsv 4.10.0
smartPassed Boolean 获取磁盘smart状态 zsv 4.10.0
smartMessage String 获取磁盘smart状态失败时输出信息 zsv 4.10.0
multipath boolean 是否为多路径设备;true 表示该磁盘自身为 multipath 设备或为 multipath 底层路径盘 zsv 5.0.0
children List 详情参考children zsv 4.3.0
#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

SDK示例

Java SDK
GetPhysicalMachineBlockDevicesAction action = new GetPhysicalMachineBlockDevicesAction();
action.username = "username";
action.password = "password";
action.sshPort = 22;
action.hostName = "192.168.1.1";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
GetPhysicalMachineBlockDevicesAction.Result res = action.call();
Python SDK
action = GetPhysicalMachineBlockDevicesAction()
action.username = "username"
action.password = "password"
action.sshPort = 22
action.hostName = "192.168.1.1"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()

挂载硬盘到挂载点 (MountBlockDevice)

API请求

URLs
POST zstack/v1/host/mount-block-device
Headers
Authorization: OAuth the-session-uuid
Body
{
  "params": {
    "username": "username",
    "password": "password",
    "sshPort": 22,
    "hostName": "192.168.1.1",
    "path": "/dev/vdb",
    "mountPoint": "/root/data",
    "filesystemType": "xfs"
  },
  "systemTags": [],
  "userTags": []
}
Note: 上述示例中systemTags、userTags字段可以省略。列出是为了表示body中可以包含这两个字段。

Curl示例

curl -H "Content-Type: application/json;charset=UTF-8" \
-H "Authorization: OAuth b86c9016b4f24953a9edefb53ca0678c" \
-X POST -d '{"params":{"username":"username","password":"password","sshPort":22,"hostName":"192.168.1.1","path":"/dev/vdb","mountPoint":"/root/data","filesystemType":"xfs"}}' \
http://localhost:8080/zstack/v1/host/mount-block-device
参数列表
名字 类型 位置 描述 可选值 起始版本
username String body(包含在params结构中) 主机名 4.3.0
password (可选) String body(包含在params结构中) 主机密码 4.3.0
sshPort Integer body(包含在params结构中) 主机端口 4.3.0
hostName String body(包含在params结构中) 主机IP 4.3.0
path String body(包含在params结构中) 硬盘绝对路径(例如:/dev/vdb) 4.3.0
mountPoint String body(包含在params结构中) 挂载点 4.3.0
filesystemType (可选) String body(包含在params结构中) 文件系统类型
  • ext4
  • xfs
4.3.0
systemTags (可选) List body 系统标签 4.3.0
userTags (可选) List body 用户标签 4.3.0

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
MountBlockDeviceAction action = new MountBlockDeviceAction();
action.username = "username";
action.password = "password";
action.sshPort = 22;
action.hostName = "192.168.1.1";
action.path = "/dev/vdb";
action.mountPoint = "/root/data";
action.filesystemType = "xfs";
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c";
MountBlockDeviceAction.Result res = action.call();
Python SDK
action = MountBlockDeviceAction()
action.username = "username"
action.password = "password"
action.sshPort = 22
action.hostName = "192.168.1.1"
action.path = "/dev/vdb"
action.mountPoint = "/root/data"
action.filesystemType = "xfs"
action.sessionId = "b86c9016b4f24953a9edefb53ca0678c"
res = action.call()
开发手册 | ZStack ZSphere · ZVF | ZStack 资源中心