概述
vdsm-client 一个存在13个预设的方法域,也就是13个大模块,下面以存储和网络为例进行命令行调用的演示
存储
1.获取所有的方法域
[root@ovirt-node-198 ~]# vdsm-client --help
usage: vdsm-client [-h] [-a HOST] [-p PORT] [--insecure] [--flow-id FLOW_ID]
[--timeout TIMEOUT] [-f FILE]
namespace method [arg=value] ...
optional arguments:
-h, --help show this help message and exit
-a HOST, --host HOST host address (default localhost)
-p PORT, --port PORT port (default 54321)
--insecure insecure connection
--flow-id FLOW_ID flow id to be used for the call. This argument
simplifies tracking a series of method calls - each
will be annotated with provided value in the log
files.
--timeout TIMEOUT timeout (default 60 seconds)
-f FILE, --file FILE read method parameters from json file. Set to '-' to
read from standard input
Namespaces:
namespace method [arg=value]
Task
LVMVolumeGroup
Image
Host
VM
Volume
StorageDomain
ISCSIConnection
StoragePool
SDM
NBD
ManagedVolume
Lease
2.举例:存储池有哪些方法,以下查询出一个有23个方法,其中值得关注的是创建方法
[root@ovirt-node-198 ~]# vdsm-client StoragePool --help
usage: vdsm-client StoragePool [-h] method [arg=value] ...
optional arguments:
-h, --help show this help message and exit
StoragePool methods:
method [arg=value]
getBackedUpVmsList Get a list of backed up virtual machines from a Backup
Storage Domain.
spmStop Instruct this host to release the Storage Pool Manager
role for this pool.
reduceVolume Reduce volume size. Mainly used after merge operation.
create Create a new Storage Pool.
disconnectStorageServer
Remove backing storage connections.
connectStorageServer
Establish a connection to backing storage.
getDomainsContainingImage
Get a list of Data Storage Domains that contain an
Image.
getSpmStatus Get the status of the Storage Pool Manager role.
getBackedUpVmsInfo Get information about backed-up virtual machines from
a Backup StorageDomain.
removeVM Remove a previously saved virtual machine definition.
updateVMs Store virtual machine OVF files on a Storage Domain in
the Storage Pool.
reconstructMaster Recover a Storage Pool by reconstructing its Storage
Domains.
prepareMerge This operation is required before performing (cold)
merge. Prepare merge will calculate the required
allocation for base volume, extend the base volume or
enlarge it (if the size of volume being removed is
larger than the base size), and mark it as ILLEGAL.
refresh Refresh Storage Pool information.
disconnect Disconnect and optionally remove a Storage Pool.
fence Fence the SPM host via the storage.
finalizeMerge This operation is required after (cold) merge
completes. Finalize will update qcow metadata and the
vdsm volume metadata to reflect that a volume is being
removed from the chain.
spmStart Instruct this host to acquire the Storage Pool Manager
role for this pool.
upgrade Upgrade all Storage Domains in this Storage Pool to a
new version.
getInfo Get information about a Storage Pool and its Active
Storage Domains.
connect Connect to an existing Storage Pool.
setDescription Set the Storage Pool description. Deprecated since
'4.0'.
destroy Destroy a Storage Pool.
3.举例:创建存储池时都需要哪些参数,通过以下方式查询
[root@ovirt-node-198 ~]# vdsm-client StoragePool create --help
usage: vdsm-client StoragePool create [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value masterVersion: The Storage Domain version of the master domain
leaseTimeSec: The maximum number of seconds that the leaseholder may retain the lease without renewing it. 0 selects the default value.
name: A human-readable name for the Storage Pool
domainList: A list of Storage Domain UUIDs that should be attached to the Storage Pool
lockRenewalIntervalSec: The number of seconds to wait before renewing lease (Should be less than leaseTimeSec). 0 selects the default value.
leaseRetries: The number of times to attempt lease renewal before failure. 0 selects the default value.
storagepoolID: The UUID of the Storage Pool
ioOpTimeoutSec: The maximum number of seconds that an I/O operation may take to complete. 0 selects the default value.
masterSdUUID: The UUID of the Storage Domain that will be used as the master domain
JSON representation:
{
"masterVersion": "int",
"leaseTimeSec": "int",
"name": "string",
"domainList": [
{
"UUID": "UUID"
}
],
"lockRenewalIntervalSec": "int",
"leaseRetries": "int",
"storagepoolID": {
"UUID": "UUID"
},
"ioOpTimeoutSec": "int",
"masterSdUUID": {
"UUID": "UUID"
}
}
optional arguments:
-h, --help show this help message and exit
4.创建存储池需要的参数就是如下的关键字:
StoragePool:
JSON representation:
{
"masterVersion": "int",
"leaseTimeSec": "int",
"name": "string",
"domainList": [
{
"UUID": "UUID"
}
],
"lockRenewalIntervalSec": "int",
"leaseRetries": "int",
"storagepoolID": {
"UUID": "UUID"
},
"ioOpTimeoutSec": "int",
"masterSdUUID": {
"UUID": "UUID"
}
}
5.创建存储域需要的参数:
StorageDomain:
JSON representation:
{
"maxHosts": "int",
"name": "string",
"domainType": {
"StorageDomainType": "enum ['FCP', 'CIFS', 'UNKNOWN', 'ISCSI', 'GLUSTERFS', 'LOCALFS', 'NFS', 'SHAREDFS']"
},
"domainClass": {
"StorageDomainImageClass": "enum ['Iso', 'Data', 'Backup', 'Unknown']"
},
"blockSize": "int",
"typeArgs": {
"StorageDomainCreateArguments": [
[
"StorageDomainCreateArgumentsBlock",
"object"
],
[
"StorageDomainCreateArgumentsLocal",
"object"
],
[
"StorageDomainCreateArgumentsNfs",
"object"
]
]
},
"version": "int",
"storagedomainID": {
"UUID": "UUID"
}
}
JSON representation:
{
"vmParams": {
"acpiEnable": "string",
"emulatedMachine": "string",
"vmId": "UUID",
"memGuaranteedSize": "uint",
"transparentHugePages": "string",
"timeOffset": "string",
"cpuType": "string",
"cpuShares": "string",
"guestNumaNodes": [
{
"nodeIndex": "int",
"cpus": "string",
"memory": "int"
}
],
"xml": "string",
"hypervEnable": "boolean",
"smp": "string",
"vmType": "enum ['kvm']",
"memnodes": [
{
"vmNodeIndex": "string",
"nodeset": "string"
}
],
"launchPaused": "boolean",
"memSize": "uint",
"nodeset": "string",
"vmName": "string",
"nice": "string",
"custom": "map",
"maxMemSize": "uint",
"bootMenuEnable": "string",
"smpThreadsPerCore": "string",
"agentChannelName": "string",
"smartcardEnable": "string",
"maxMemSlots": "uint",
"smpCoresPerSocket": "string",
"kvmEnable": "string",
"pitReinjection": "string",
"displayNetwork": "string",
"devices": [
{
"VmDevice": [
[
"VmDiskDevice",
"object"
],
[
"VmInterfaceDevice",
"object"
],
[
"VmVideoDevice",
"object"
],
[
"VmSoundDevice",
"object"
],
[
"VmControllerDevice",
"object"
],
[
"VmBalloonDevice",
"object"
],
[
"VmChannelDevice",
"object"
],
[
"VmWatchdogDevice",
"object"
],
[
"VmConsoleDevice",
"object"
],
[
"VmSmartcardDevice",
"object"
],
[
"VmGraphicsDevice",
"object"
],
[
"VmHostDevice",
"object"
],
[
"VmRngDevice",
"object"
],
[
"VmTpmDevice",
"object"
],
[
"VmLeaseDevice",
"object"
]
]
}
],
"mode": "string",
"maxVCpus": "string",
"display": "enum ['vnc', 'qxl']"
},
"vmID": {
"UUID": "UUID"
}
}
6.获取当前vdsm主机可用存储域
positional arguments:
arg=value storageType: Limit to Domains of this StorageDomainType
storagepoolID: Limit to Domains belonging to this Storage Pool
remotePath: Limit to Domains having this remotePath.
domainClass: Limit to Domains of this StorageDomainImageClass
JSON representation:
{
"storageType": {
"StorageDomainType": "enum ['FCP', 'CIFS', 'UNKNOWN', 'ISCSI', 'GLUSTERFS', 'LOCALFS', 'NFS', 'SHAREDFS']"
},
"storagepoolID": {
"UUID": "UUID"
},
"remotePath": "string",
"domainClass": {
"StorageDomainImageClass": "enum ['Iso', 'Data', 'Backup', 'Unknown']"
}
}
optional arguments:
[root@localhost /]# vdsm-client Host getStorageDomains remotePath=/iso
[]
[root@localhost /]# vdsm-client Host getStorageDomains remotePath=/images_old
[]
[root@localhost /]# vdsm-client Host getStorageDomains remotePath=/images
[
"22dbca44-0891-43c2-ab51-6bd321aed55e"
]
[root@localhost /]# vdsm-client Host getStorageDomains remotePath=/img
[
"aa54891c-feec-45e0-b284-587bc672c4e4"
]
[root@localhost /]# vdsm-client Host getStorageDomains remotePath=/img2
[
"774f3593-7a43-4e34-9a24-af9fa0215656"
7.获取当前可用存储池:
[root@localhost /]# vdsm-client Host getConnectedStoragePools --help
usage: vdsm-client Host getConnectedStoragePools [-h]
[arg=value [arg=value ...]]
positional arguments:
arg=value
optional arguments:
-h, --help show this help message and exit
[root@localhost /]# vdsm-client Host getConnectedStoragePools
[
"5abb963e-0da2-48d9-99ff-fa172744b435"
]
8.获取卷组:
[root@localhost /]# vdsm-client Host getLVMVolumeGroups --help
usage: vdsm-client Host getLVMVolumeGroups [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value storageType: Limit results to Volume Groups of a specific storage type
JSON representation:
{
"storageType": {
"BlockDeviceType": "enum ['FCP', 'MIXED', 'iSCSI']"
}
}
optional arguments:
-h, --help show this help message and exit
[root@localhost /]# vdsm-client Host getLVMVolumeGroups
[]
[root@localhost /]# vdsm-client Host getLVMVolumeGroups [storageType=[BlockDeviceType=FCP]]
[]
[root@localhost /]# vdsm-client Host getLVMVolumeGroups [storageType=[BlockDeviceType=MIXED]]
[]
[root@localhost /]# vdsm-client Host getLVMVolumeGroups [storageType=[BlockDeviceType=ISCSI]]
9.获取存储域的统计数据:
[root@localhost /]# vdsm-client StorageDomain getStats --help
usage: vdsm-client StorageDomain getStats [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value storagedomainID: The UUID of the Storage Domain
JSON representation:
{
"storagedomainID": {
"UUID": "UUID"
}
}
optional arguments:
-h, --help show this help message and exit
[root@localhost /]# vdsm-client StorageDomain getStats storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656
{
"mdasize": 0,
"mdathreshold": true,
"mdavalid": true,
"diskfree": "32077094912",
"disktotal": "53660876800",
"mdafree": 0
}
10.获取当前存储域可用镜像集合:
[root@localhost /]# vdsm-client StorageDomain getImages storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656
[
"b4234a74-79ee-4f1d-936b-b6446b2b9c8e",
"f7d8d78d-a8d0-4ad1-8a95-e52c6ef4a192",
"57a43140-e8e8-4b33-a0e5-8a96b5cac9ab",
"42a3dd3d-a398-4dec-920c-abd58d98d2cd",
"d04c89f5-3e1e-4acc-9d40-e5f6f087902b",
"6d82c03c-4682-49a8-b555-dee504629101"
]
11.获取存储域的可用卷集合:
[root@localhost /]# vdsm-client StorageDomain getVolumes --help
usage: vdsm-client StorageDomain getVolumes [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value storagepoolID: The UUID of the Storage Pool
imageID: Limit results to Volumes associated with a single Image
storagedomainID: The UUID of the Storage Domain
JSON representation:
{
"storagepoolID": {
"UUID": "UUID"
},
"imageID": {
"UUID": "UUID"
},
"storagedomainID": {
"UUID": "UUID"
}
}
optional arguments:
[root@localhost /]# vdsm-client StorageDomain getVolumes storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435
[
"b8ebba4d-75e4-4be3-a763-4ffeaab57e39",
"d29ad4ce-5446-48b6-919a-e5083b20fa65",
"c93ffdac-a33a-4598-a233-e2e6c17a25a7",
"3e0ee78a-5869-4eda-b7b1-8b31f7423ee4",
"00c857ec-d74f-4f36-abf5-4c3608cbf054",
"30cb5fad-5a2e-44f0-9f51-19f97d72b9f1"
]
12.获取存储域的可用卷:通过存储域,存储池,磁盘
[root@localhost /]# vdsm-client StorageDomain getVolumes storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e
[
"b8ebba4d-75e4-4be3-a763-4ffeaab57e39"
]
13.获取存储域的可用卷:通过存储域,存储池,磁盘
[root@localhost /]# vdsm-client StorageDomain getVolumes storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e
[
"b8ebba4d-75e4-4be3-a763-4ffeaab57e39"
]
14.获取存储域包含的镜像:
[root@localhost /]# vdsm-client StoragePool getDomainsContainingImage storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e
[
"774f3593-7a43-4e34-9a24-af9fa0215656"
]
15.获取存储池管理器角色的状态
[root@localhost /]# vdsm-client StoragePool getSpmStatus --help
usage: vdsm-client StoragePool getSpmStatus [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value storagepoolID: The UUID of the Storage Pool
JSON representation:
{
"storagepoolID": {
"UUID": "UUID"
}
}
optional arguments:
-h, --help show this help message and exit
[root@localhost /]# vdsm-client StoragePool getSpmStatus storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435
{
"spmId": 1,
"spmStatus": "SPM",
"spmLver": -1
}
16.获取存储池的概要信息
[root@localhost /]# vdsm-client StoragePool getInfo --help
usage: vdsm-client StoragePool getInfo [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value storagepoolID: The UUID of the Storage Pool
JSON representation:
{
"storagepoolID": {
"UUID": "UUID"
}
}
optional arguments:
-h, --help show this help message and exit
[root@localhost /]# vdsm-client StoragePool getInfo storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435
{
"info": {
"name": "No Description",
"isoprefix": "",
"pool_status": "connected",
"lver": -1,
"spm_id": 1,
"master_uuid": "774f3593-7a43-4e34-9a24-af9fa0215656",
"version": "5",
"domains": "774f3593-7a43-4e34-9a24-af9fa0215656:Active",
"type": "LOCALFS",
"master_ver": 1
},
"dominfo": {
"774f3593-7a43-4e34-9a24-af9fa0215656": {
"status": "Active",
"diskfree": "32072269824",
"isoprefix": "",
"alerts": [],
"disktotal": "53660876800",
"version": 5
}
}
}
17.获取卷的详细:
[root@localhost /]# vdsm-client Volume getInfo --help
usage: vdsm-client Volume getInfo [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value imageID: The Image associated with the Volume
storagepoolID: The Storage Pool associated with the Volume
volumeID: The UUID of the Volume
storagedomainID: The Storage Domain associated with the Volume
JSON representation:
{
"imageID": {
"UUID": "UUID"
},
"storagepoolID": {
"UUID": "UUID"
},
"volumeID": {
"UUID": "UUID"
},
"storagedomainID": {
"UUID": "UUID"
}
}
optional arguments:
[root@localhost /]# vdsm-client Volume getInfo storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e volumeID=b8ebba4d-75e4-4be3-a763-4ffeaab57e39
{
"status": "OK",
"domain": "774f3593-7a43-4e34-9a24-af9fa0215656",
"capacity": "134217728",
"voltype": "LEAF",
"description": "{\"Updated\":true,\"Size\":51200,\"Last Updated\":\"Mon Jun 13 07:24:58 EDT 2022\",\"Storage Domains\":[{\"uuid\":\"774f3593-7a43-4e34-9a24-af9fa0215656\"}],\"Disk Description\":\"OVF_STORE\"}",
"parent": "00000000-0000-0000-0000-000000000000",
"format": "RAW",
"generation": 0,
"image": "b4234a74-79ee-4f1d-936b-b6446b2b9c8e",
"uuid": "b8ebba4d-75e4-4be3-a763-4ffeaab57e39",
"disktype": "OVFS",
"legality": "LEGAL",
"mtime": "0",
"apparentsize": "51200",
"truesize": "53248",
"type": "PREALLOCATED",
"children": [],
"pool": "",
"ctime": "1654860519"
}
18.获取分配卷的大小:
[root@localhost /]# vdsm-client Volume getSize storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e volumeID=b8ebba4d-75e4-4be3-a763-4ffeaab57e39
{
"truesize": "53248",
"apparentsize": "51200"
}
获取通过qemu创建的卷大小:
[root@localhost /]# vdsm-client Volume getQemuImageInfo --help
usage: vdsm-client Volume getQemuImageInfo [-h] [arg=value [arg=value ...]]
positional arguments:
arg=value imageID: The Image associated with the Volume
storagepoolID: The Storage Pool associated with the Volume
volumeID: The UUID of the Volume
storagedomainID: The Storage Domain associated with the Volume
JSON representation:
{
"imageID": {
"UUID": "UUID"
},
"storagepoolID": {
"UUID": "UUID"
},
"volumeID": {
"UUID": "UUID"
},
"storagedomainID": {
"UUID": "UUID"
}
}
optional arguments:
-h, --help show this help message and exit
[root@localhost /]# vdsm-client Volume getQemuImageInfo storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e volumeID=b8ebba4d-75e4-4be3-a763-4ffeaab57e39
{
"format": "raw",
"virtualsize": 51200,
"actualsize": 53248
}
19.获取镜像中的卷信息:
root@localhost /]# vdsm-client Image getVolumes storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656 storagepoolID=5abb963e-0da2-48d9-99ff-fa172744b435 imageID=b4234a74-79ee-4f1d-936b-b6446b2b9c8e
[
"b8ebba4d-75e4-4be3-a763-4ffeaab57e39"
]
20.获取存储域的信息:
[root@localhost /]# vdsm-client StorageDomain getInfo storagedomainID=774f3593-7a43-4e34-9a24-af9fa0215656
{
"uuid": "774f3593-7a43-4e34-9a24-af9fa0215656",
"pool": [
"5abb963e-0da2-48d9-99ff-fa172744b435"
],
"version": "5",
"role": "Master",
"remotePath": "/img2",
"block_size": 512,
"type": "LOCALFS",
"class": "Data",
"alignment": 1048576,
"name": "img2"
}
21.创建存储域:
vdsm-client StorageDomain create maxHosts=2 name=test domainType=LOCALFS domianClass=Data blockSize=512 typeArgs=StorageDomainCreateArgumentsLocal version=5 storagedomainID=b8ebba4d-75e4-4be3-a763-4ffeaab57e45
网络
1.创建Linuxbridge网络:创建网络需要的参数结构比较复杂,需要使用json文件加载参数,通过 -f 参数来导入参数值
business.json文件内容如下:
{
"bondings": {},
"networks": {
"tenant": {
"ipv6autoconf": false,
"nic": "enp0s9",
"ipaddr": "172.19.0.112",
"switch": "legacy",
"mt": 1500,
"netmask": "255.255.255.0",
"dhcpv6": false,
"STP": "no",
"bridged": "true",
"gateway": "172.19.0.1"
}
},
"options": {
"connectivityCheck": "false",
"connectivityTimeout": 120,
"commitOnSuccess": false
}
}
[root@localhost /]# vdsm-client -f business.json Host setupNetworks
上述如果要创建ovs网桥,那么只需要修改switch 参数为 ovs,如果需要指定默认路由,则添加参数"defaultRoute":true
2.删除网络:依然需要使用文件加载参数和值,依然调用setupNetworks值
del.json 内容如下
{
"bondings": {},
"networks": {
"store17210": {
"remove": true
}
},
"options": {}
}
[root@localhost /]# vdsm-client -f business.json Host setupNetworks