Document navigation

Local Storage Related Interfaces

AddLocalPrimaryStorage

API Request

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: In the example above, systemTags and userTags fields can be omitted. They are listed to indicate that the body can contain these two fields.
Curl Examples
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
Parameter List
Name Type Location Description Allowed Values Starting Version
url String body (nested in params structure) Local storage path 0.6
name String body (nested in params structure) Local storage data storage name 0.6
description (optional) String body (nested in params structure) Detailed description of the local storage data storage 0.6
type (optional) String body (nested in params structure) Type is LocalStorage 0.6
zoneUuid String body (nested in params structure) Data Center UUID 0.6
resourceUuid (optional) String body (nested in params structure) Resource UUID. If specified, the local storage data storage will use this value as its UUID. 0.6
systemTags (optional) List body System tags 0.6
userTags (optional) List body User tags 0.6

API Response

Response Example
{
"inventory": {
"name": "PS1",
"url": "/Cloud_ps",
"type": "LocalStorage",
"state": "Enabled",
"status": "Connected",
"attachedClusterUuids": [
"562116d368c8467c95c53321757538dc"
    ]
  }
}
Name Type Description Starting Version
error ErrorCode Error code. If not null, indicates the operation failed. This field is null when the operation succeeds. For details, see error 0.6
inventory PrimaryStorageInventory For details, see inventory 0.6
#error
Name Type Description Starting Version
code String Error code number, globally unique identifier for the error, such as SYS.1000, HOST.1001 0.6
description String Brief description of the error 0.6
details String Detailed error information 0.6
elaboration String Reserved field, defaults to null 0.6
opaque LinkedHashMap Reserved field, defaults to null 0.6
cause ErrorCode Root cause. The source error that triggered the current error. If there is no original error, this field is null 0.6
#inventory
Name Type Description Starting Version
uuid String Resource UUID, uniquely identifies the resource 0.6
zoneUuid String Data Center UUID 0.6
name String Resource name 0.6
url String The URL. 0.6
description String Detailed description of the resource 0.6
totalCapacity Long The total capacity. 0.6
availableCapacity Long The available capacity. 0.6
totalPhysicalCapacity Long The total physical capacity. 0.6
availablePhysicalCapacity Long The available physical capacity. 0.6
systemUsedCapacity Long The system used capacity. 0.6
type String The resource type. 0.6
state String The resource state. 0.6
status String The resource status. 0.6
mountPath String The mount path. 0.6
createDate Timestamp Creation time 0.6
lastOpDate Timestamp Last modification time 0.6
attachedClusterUuids List The attached cluster UUIDs. 0.6

SDK Examples

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 Request

URLs
GET zstack/v1/primary-storage/local-storage/resource-refs
Headers
Authorization: OAuth the-session-uuid
Curl Examples
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

Queryable Fields

Run the CLI command tool, enter QueryLocalStorageResourceRef and press Tab to view all queryable fields and resource names that support cross-table queries.

API Response

When the API succeeds, it returns an empty JSON structure {}. When an error occurs, the returned JSON structure contains an error field, for example:
{
"error": {
"code": "SYS.1001",
"description": "A message or a operation timeout",
"details": "Create VM on KVM timeout after 300s"
    }
}

SDK Examples

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 Request

URLs
PUT zstack/v1/primary-storage/local-storage/volumes/{volumeUuid}/actions
Headers
Authorization: OAuth the-session-uuid
Body
{
"localStorageMigrateVolume": {
"destHostUuid": "511e02b9b8c9427c9fbbac55b8c7ec62"
  },
"systemTags": [],
"userTags": []
}
Note: In the example above, systemTags and userTags fields can be omitted. They are listed to indicate that the body can contain these two fields.
Curl Examples
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
Parameter List
Name Type Location Description Allowed Values Starting Version
volumeUuid String url Disk UUID 0.6
destHostUuid String body (nested in localStorageMigrateVolume structure) Destination Host UUID 0.6
systemTags (optional) List body System tags 0.6
userTags (optional) List body User tags 0.6

API Response

Response Example
{
"inventory": {
"resourceUuid": "bad5e950cf014275bf9ba6e4cfe78a97",
"primaryStorageUuid": "81d893539a6b4ce7b9957c7a5d6c5df8",
"hostUuid": "9d250b88ae90449db567cfa18a75fecc",
"size": 2.4035328E7
  }
}
Name Type Description Starting Version
error ErrorCode Error code. If not null, indicates the operation failed. This field is null when the operation succeeds. For details, see error 0.6
inventory LocalStorageResourceRefInventory For details, see inventory 0.6
#error
Name Type Description Starting Version
code String Error code number, globally unique identifier for the error, such as SYS.1000, HOST.1001 0.6
description String Brief description of the error 0.6
details String Detailed error information 0.6
elaboration String Reserved field, defaults to null 0.6
opaque LinkedHashMap Reserved field, defaults to null 0.6
cause ErrorCode Root cause. The source error that triggered the current error. If there is no original error, this field is null 0.6
#inventory
Name Type Description Starting Version
resourceUuid String The resource UUID. 0.6
primaryStorageUuid String Data Storage UUID 0.6
hostUuid String Host UUID 0.6
size Long The size. 0.6
resourceType String The resource type. 0.6
createDate Timestamp Creation time 0.6
lastOpDate Timestamp Last modification time 0.6

SDK Examples

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 Request

URLs
GET zstack/v1/primary-storage/local-storage/{primaryStorageUuid}/capacities
Headers
Authorization: OAuth the-session-uuid

Curl Examples

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
Parameter List
Name Type Location Description Allowed Values Starting Version
hostUuid (optional) String query Host UUID 0.6
primaryStorageUuid String url Data Storage UUID 0.6
systemTags (optional) List query System tags 0.6
userTags (optional) List query User tags 0.6

API Response

Response Example
{
"inventories": [
    {
"hostUuid": "02b36a53204d496290c4f2f8b31a7575",
"totalCapacity": 1.073741824E9,
"availableCapacity": 9.73078528E8,
"totalPhysicalCapacity": 1.073741824E9,
"availablePhysicalCapacity": 9.73078528E8
    }
  ]
}
Name Type Description Starting Version
error ErrorCode Error code. If not null, indicates the operation failed. This field is null when the operation succeeds. For details, see error 0.6
inventories List For details, see inventories 0.6
#error
Name Type Description Starting Version
code String Error code number, globally unique identifier for the error, such as SYS.1000, HOST.1001 0.6
description String Brief description of the error 0.6
details String Detailed error information 0.6
elaboration String Reserved field, defaults to null 0.6
opaque LinkedHashMap Reserved field, defaults to null 0.6
cause ErrorCode Root cause. The source error that triggered the current error. If there is no original error, this field is null 0.6
#inventories
Name Type Description Starting Version
hostUuid String Host UUID 0.6
totalCapacity long The total capacity. 0.6
availableCapacity long The available capacity. 0.6
totalPhysicalCapacity long The total physical capacity. 0.6
availablePhysicalCapacity long The available physical capacity. 0.6

SDK Examples

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

Check which hosts can migrate disks on local storage.

API Request

URLs
GET zstack/v1/volumes/{volumeUuid}/migration-target-hosts
Headers
Authorization: OAuth the-session-uuid

Curl Examples

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?
Parameter List
Name Type Location Description Allowed Values Starting Version
volumeUuid String url Disk UUID 0.6
systemTags (optional) List query Optional. The system tags. 0.6
userTags (optional) List query Optional. The user tags. 0.6

API Response

When the API succeeds, it returns an empty JSON structure {}. When an error occurs, the returned JSON structure contains an error field, for example:
{
"error": {
"code": "SYS.1001",
"description": "A message or a operation timeout",
"details": "Create VM on KVM timeout after 300s"
    }
}

SDK Examples

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 Request

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

Curl Examples

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
Parameter List
Name Type Location Description Allowed Values Starting Version
username String query Username 4.3.0
password (optional) String query Password 4.3.0
sshPort Integer query SSH Port 4.3.0
hostName String query Host IP 4.3.0
excludedTypes (optional) List query Specified disk types to exclude 4.3.0
systemTags (optional) List query System tags 4.3.0
userTags (optional) List query User tags 4.3.0

API Response

Response Example
{
  "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
      }
    ]
  }
}
Name Type Description Starting Version
success boolean Whether the operation succeeded. 4.3.0
blockDevices BlockDevices For details, see blockDevices 4.3.0
error ErrorCode Error code. If not null, indicates the operation failed. This field is null when the operation succeeds. For details, see error 4.3.0
#blockDevices
Name Type Description Starting Version
unusedBlockDevices List For details, see unusedBlockDevices 4.3.0
usedBlockDevices List For details, see usedBlockDevices 4.3.0
#unusedBlockDevices
Name Type Description Starting Version
name String Disk device name 4.3.0
type String Disk type 4.3.0
size long Disk capacity 4.3.0
used long Used disk capacity 4.10.0
available long Available disk capacity 4.10.0
physicalSector long Physical sector size 4.3.0
logicalSector long Logical sector size 4.3.0
mountPoint String Mount point 4.3.0
partitionTable String Partition table type 4.3.0
fsType String File system type 4.10.0
serialNumber String Serial number 4.10.0
model String Model 4.10.0
mediaType String Media type 4.10.0
usedRatio String Usage ratio 4.10.0
smartPassed Boolean Disk SMART status 4.10.0
smartMessage String Output message when failed to get disk SMART status 4.10.0
multipath boolean Whether it is a multipath device. true means the disk itself is a multipath device or an underlying path disk of multipath 5.0.0
children List For details, see children 4.3.0
#usedBlockDevices
Name Type Description Starting Version
name String Disk device name 4.3.0
type String Disk type 4.3.0
size long Disk capacity 4.3.0
used long Used disk capacity 4.10.0
available long Available disk capacity 4.10.0
physicalSector long Physical sector size 4.3.0
logicalSector long Logical sector size 4.3.0
mountPoint String Mount point 4.3.0
partitionTable String Partition table type 4.3.0
fsType String File system type 4.10.0
serialNumber String Serial number 4.10.0
model String Model 4.10.0
mediaType String Media type 4.10.0
usedRatio String Usage ratio 4.10.0
smartPassed Boolean Disk SMART status 4.10.0
smartMessage String Output message when failed to get disk SMART status 4.10.0
multipath boolean Whether it is a multipath device. true means the disk itself is a multipath device or an underlying path disk of multipath 5.0.0
children List For details, see children 4.3.0
#error
Name Type Description Starting Version
code String Error code number, globally unique identifier for the error, such as SYS.1000, HOST.1001 0.6
description String Brief description of the error 0.6
details String Detailed error information 0.6
elaboration String Reserved field, defaults to null 0.6
opaque LinkedHashMap Reserved field, defaults to null 0.6
cause ErrorCode Root cause. The source error that triggered the current error. If there is no original error, this field is null 0.6

SDK Examples

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 Request

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: In the example above, systemTags and userTags fields can be omitted. They are listed to indicate that the body can contain these two fields.

Curl Examples

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
Parameter List
Name Type Location Description Allowed Values Starting Version
username String body (nested in params structure) Username 4.3.0
password (optional) String body (nested in params structure) Password 4.3.0
sshPort Integer body (nested in params structure) SSH Port 4.3.0
hostName String body (nested in params structure) Host IP 4.3.0
path String body (nested in params structure) Absolute path of the disk (for example: /dev/vdb) 4.3.0
mountPoint String body (nested in params structure) Mount point 4.3.0
filesystemType (optional) String body (nested in params structure) File system type
  • ext4
  • xfs
4.3.0
systemTags (optional) List body System tags 4.3.0
userTags (optional) List body User tags 4.3.0

API Response

When the API succeeds, it returns an empty JSON structure {}. When an error occurs, the returned JSON structure contains an error field, for example:
{
	"error": {
		"code": "SYS.1001",
		"description": "A message or a operation timeout",
		"details": "Create VM on KVM timeout after 300s"
	}
}

SDK Examples

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()
API Reference | ZStack ZSphere · ZVF | ZStack Resource Center