?王越:VMware存儲API整理,比如核心的存儲池與卷兩者的CURD。
可以參考:VMware in OpenStack、華為對接VMware這兩個平臺,兩個平臺地址或源碼長生有。
華為的納管說明書:
http://support.huawei.com/enterprise/docinforeader!loadDocument1.action?contentId=DOC1000117733&partNo=10012#_ZH-CN_TOPIC_0025959320
兩種:
- 納管,元數據導出來,目標是導入Cinder
- 使用,
圖 1.Vcenter managed objects結構圖
一、連接vmware服務器
Vmware Api調用,需要獲取與vmware服務器連接的session:
from oslo_vmware import api
session = api.VMwareAPISession('172.24.26.20', 'administrator@ruijie.local', 'RuiJie@123', 1, 0.1)
二、集群
Cinder對接vmware,cinder-volume.conf配置后端需要設置參數vmware_cluster_name = cluster,這個vmware_cluster_name就是對應vmware平臺的集群(Managed Object - ClusterComputeResource)。所以vmware的一個集群,對于cinder來說其實就是一個存儲池。
平臺操作:
1.創建集群
Folder.CreateCluster接口說明
參數:
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the Folder used to make the method call.
name xsd:string Name for the new cluster.
spec ClusterConfigSpec Specification for the cluster.
返回值:
TYPE DESCRIPTION
ManagedObjectReference
to a ClusterComputeResource A new ClusterComputeResource instance.
接口調用:
def get_host_folder():
"""
從datacenter獲取集群文件夾列表,我們這里就取出第一個來用
:return:
"""
datacenter = session.invoke_api(vim_util, 'get_objects',
session.vim,
'Datacenter',
max_objects).objects[0].obj
hostFolder = session.invoke_api(vim_util,
'get_object_property',
session.vim,
datacenter,
'hostFolder')
return hostFolder
def create_cluster(cluster_name):
"""
創建集群
:param cluster_name:
:return:
"""
hostfolder = get_host_folder()
cluster_spec = session.vim.client.factory.create('ns0:ClusterConfigSpec')
# EVC模式設置為禁用
cluster_spec.drsConfig.enableVmBehaviorOverrides = False
task = session.invoke_api(session.vim,
"CreateCluster",
hostfolder,
name=cluster_name,
spec=cluster_spec)
return task
2.刪除集群
def remove_cluster(cluster_name):
"""
刪除集群
:param cluster_name:
:return:
"""
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'ClusterComputeResource',
max_objects)
for c in retrieve_result.objects:
if c.propSet[0].val == cluster_name:
cluster = c.obj
task = session.invoke_api(session.vim,
"Destroy_Task",
cluster)
三、存儲池Datastore
Properties
NAME TYPE DESCRIPTION
browser ManagedObjectReference
to aHostDatastoreBrowser DatastoreBrowser used to browse this datastore.
capability DatastoreCapability Capabilities of this datastore.
host* DatastoreHostMount[] Hosts attached to this datastore.
info DatastoreInfo Specific information about the datastore.
iormConfiguration* StorageIORMInfo Configuration of storage I/O resource management for the datastore. Currently we only support storage I/O resource management on VMFS volumes of a datastore.
This configuration may not be available if the datastore is not accessible from any host, or if the datastore does not have VMFS volume. The configuration can be modified using the method ConfigureDatastoreIORM_Task
summary DatastoreSummary Global properties of the datastore.
vm* ManagedObjectReference[]
to a VirtualMachine[] Virtual machines stored on this datastore.
1.查詢存儲池
# 查詢Datastore列表,返回host、summary、vm屬性
# host:存儲掛載設備的信息
# summary:存儲的基本信息,可以看到容量、存儲類型等
# vm:掛載這個存儲的虛機列表
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'Datastore',
max_objects,
properties_to_collect=['host', 'summary', 'vm'])
返回值:
(ObjectContent){
obj =
(obj){
value = "datastore-954"
_type = "Datastore"
}
propSet[] =
(DynamicProperty){
name = "host"
val =
(ArrayOfDatastoreHostMount){
DatastoreHostMount[] =
(DatastoreHostMount){
key =
(key){
value = "host-195"
_type = "HostSystem"
}
mountInfo =
(HostMountInfo){
path = "/vmfs/volumes/02950f8a-1ba54877-0000-000000000000"
accessMode = "readWrite"
mounted = True
accessible = True
}
},
}
},
(DynamicProperty){
name = "summary"
val =
(DatastoreSummary){
datastore =
(datastore){
value = "datastore-954"
_type = "Datastore"
}
name = "Datastore_NFS"
url = "ds:///vmfs/volumes/02950f8a-1ba54877-0000-000000000000/"
capacity = 204010946560
freeSpace = 202497806336
uncommitted = 70654537728
accessible = True
multipleHostAccess = False
type = "NFS41"
maintenanceMode = "normal"
}
},
(DynamicProperty){
name = "vm"
val =
(ArrayOfManagedObjectReference){
ManagedObjectReference[] =
(ManagedObjectReference){
value = "vm-961"
_type = "VirtualMachine"
},
(ManagedObjectReference){
value = "vm-958"
_type = "VirtualMachine"
},
}
},
}
也可以調用HostDatastoreBrowser.SearchDatastore_Task根據datastore路徑查找
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the HostDatastoreBrowser used to make the method call.
datastorePath xsd:string
searchSpec* HostDatastoreBrowserSearchSpec
*Need not be set
Return Value
TYPE DESCRIPTION
ManagedObjectReference
to a Task This method returns a Task object with which to monitor the operation. The info.result property in the Task contains the HostDatastoreBrowserSearchResults upon success.
設置datastore的地址,格式是’[path]’
datastore_path = "[datastore1]"
設置查詢用的spec
search_spec = session.vim.client.factory.create('ns0:HostDatastoreBrowserSearchSpec')
search_spec.matchPattern = match_pttern
啟動搜索任務
task = session.invoke_api(session.vim,
"SearchDatastore_Task",
browser,
datastorePath=datastore_path,
searchSpec=search_spec)
session.wait_for_task(task)
search_result = session.invoke_api(vim_util,
'get_object_property',
session.vim,
task,
'info').result
print search_result
返回值
(HostDatastoreBrowserSearchResults){
datastore =
(datastore){
value = "datastore-199"
_type = "Datastore"
}
folderPath = "[datastore1]"
}
2.添加存儲池
創建存儲池有四種方法:
方法 說明
CreateLocalDatastore 創建本地存儲池
CreateNasDatastore 在nfs共享中創建nas存儲池
CreateVmfsDatastore 在磁盤、lan上創建vmfs存儲池
CreateVvolDatastore
以HostDatastoreSystem.CreateNasDatastore為例,該方法需要傳兩個參數:
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the HostDatastoreSystem used to make the method call.
spec HostNasVolumeSpec The specification for creating a network-attached storage volume.
?_this
_this是HostDatastoreSystem對象。如果想通過get_objects查詢ManagedObjectReference是獲取不到的,檢查文檔可知HostDatastoreSystem是HostConfigManager的屬性datastoreSystem;HostConfigManager通過get_objects也是拿不到的,而HostConfigManager又是HostSystem的屬性configManager,HostSystem通過get_objects可以拿到,我們再從屬性查。
代碼:
def get_datastoreSystem():
# 獲取 HostSystem 資源清單
retrieve_result = session.invoke_api(
vim_util,
'get_objects',
session.vim,
'HostSystem',
max_objects)
datastore_system = None
# 獲取HostSystem的屬性configManager.datastoreSystem
if retrieve_result.objects:
hostsystem = retrieve_result.objects[0].obj
datastore_system = session.invoke_api(vim_util,
'get_object_property',
session.vim,
hostsystem,
'configManager.datastoreSystem')
return datastore_system
?spec
Spec是HostNasVolumeSpec,封裝了創建存儲池的基本參數,可通過session.vim.client.factory.create('ns0:HostNasVolumeSpec')創建的。
HostNasVolumeSpec Properties List
NAME TYPE DESCRIPTION
accessMode xsd:string Access mode for the mount point.
Mounting in read-write mode would be successful irregardless on how the mount point is exported or access permissions. For example, mounting a volume that is exported as read-only as readWrite will succeed. Hence, that a readWrite mount succeeds should not be taken as an indication that all files on a mount is writable.
If a file system is mounted readOnly, the system cannot create or modify any files on the file system. This is mostly useful for storing ISO images and templates, since a virtual machine cannot be powered on from a readOnly volume.
The access mode of a mounted NFS volume can be obtained at accessMode.
See HostMountMode
localPath xsd:string The localPath refers to the name of the NAS datastore to be created using this specification.
In the case of ESX Server, the datastore name is a component in the file system path at which the NAS volume can be found. For example, if localPath is set to "nas_volume" the created NAS datastore will be named "nas_volume" and it can be accessed via the file system path "/vmfs/volumes/nas_volume".
In the case of VMware Server, the localPath will also be used as the datastore name, but the datastore name may not necessarily be reflected in the file system path where the NAS volume may be accessed.
password* xsd:string If type is CIFS, the password to use when connecting to the CIFS server. If type is NFS, this field will be ignored.
Since VI API 2.5
remoteHost xsd:string The host that runs the NFS v3 or CIFS server. For NFS v4.1 and beyond use remoteHostNames defined later. The field remotehost may be deprecated in future for NFS, so clients should plan to use the property remoteHostNames to send in the host name(s) for both NFS v3 and v4.1
remoteHostNames* xsd:string[] Hostnames or IP addresses of remote NFS server. In case of NFS v4.1 this may have multiple entries. For NFS v3 the input should be same in both remoteHost and remoteHostNames.
Since vSphere API 6.0
remotePath xsd:string The remote path of the NFS mount point.
securityType* xsd:string Provided during mount indicating what security type, if any, to use See HostNasVolumeSecurityType
Since vSphere API 6.0
type* xsd:string Specifies the type of the the NAS volume. Supported types are CIFS, NFS, NFS41 If not specified, defaults to NFS
Since VI API 2.5
userName* xsd:string If type is CIFS, the user name to use when connecting to the CIFS server. If type is NFS, this field will be ignored.
Since VI API 2.5
創建NFS存儲我們需要設置以下幾個參數:
def host_nas_volume_spec(client_factory, name, remote_host_name=None,
remote_path=None, nas_type=None, access_mode=None):
rel_spec = client_factory.create('ns0:HostNasVolumeSpec')
# 遠端服務器地址
rel_spec.remoteHost = remote_host_name
# 遠端服務器地址數組,nfs4.1要求
rel_spec.remoteHostNames = [remote_host_name]
# 遠端nfs路徑
rel_spec.remotePath = remote_path
# nfs類型,可選值CIFS/NFS/NFS41
rel_spec.type = nas_type
# 本地存儲路徑名,也作為本地存儲池的名字
rel_spec.localPath = name
# 存儲訪問模式,可選值readOnly和readWrite
if not access_mode:
rel_spec.accessMode = 'readWrite'
return rel_spec
有了這兩個參數,我們就可執行創建了:
def create_nas_datastore():
client_factory = session.vim.client.factory
datastoresystem = get_datastoreSystem()
spec = host_nas_volume_spec(
client_factory,
'storage_nfs2',
'172.24.3.172',
'/wangyue_test_nfs2',
'NFS41')
task = session.invoke_api(
session.vim,
"CreateNasDatastore",
datastoresystem,
spec=spec)
3.刪除存儲池
可調用方法HostDatastoreSystem.RemoveDatastore。參數如下:
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the HostDatastoreSystem used to make the method call.
datastore ManagedObjectReference
to a Datastore The datastore to be removed.
def get_special_datastore(datastore_name):
"""
根據存儲池名字獲取存儲池對象
:param datastore_name:
:return:
"""
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'Datastore',
max_objects)
if retrieve_result.objects:
for obj_content in retrieve_result.objects:
props = _get_object_properties(obj_content)
if 'name' in props and props['name'] == datastore_name:
return obj_content.obj
def remove_nas_datastore():
"""
刪除nas數據庫
:return:
"""
datastoresystem = get_datastoreSystem()
datastore = get_special_datastore('storage_nfs2')
task = session.invoke_api(
session.vim,
"RemoveDatastore",
datastoresystem,
datastore=datastore)
4.修改存儲池
Datastore.RenameDatastore可修改存儲池名稱
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the Datastore used to make the method call.
newName xsd:string The new name to assign to the datastore.
def rename_datastore(oldname, newname):
"""
修改存儲池名稱
:param oldname:
:param newname:
:return:
"""
datastore = get_special_datastore(oldname)
task = session.invoke_api(
session.vim,
"RenameDatastore",
datastore,
newName=newname)
5.判斷cluster是否連接datastore
ClusterComputeResource 和 datastore 都有host屬性,表示所連接的host。只要判斷兩者的host是否一樣即可。
代碼:
def check_cluster_access_datastore(cluster_name, datastore_name):
"""
判斷cluster連接著datastore
:param cluster_name:
:param datastore_name:
:return:
"""
# 1. 根據名字查找cluster
cluster_result = session.invoke_api(
vim_util,
'get_objects',
session.vim,
'ClusterComputeResource',
max_objects
)
cluster = None
if cluster_result.objects:
for obj_content in cluster_result.objects:
props = _get_object_properties(obj_content)
if props['name'] == cluster_name:
cluster = obj_content.obj
if not cluster:
print('ERROR~there is no cluster %s ~' % cluster_name)
return False
# 2. 獲取cluster的host屬性
cluster_hosts = session.invoke_api(vim_util,
'get_object_property',
session.vim,
cluster,
'host')
# 轉成數組
cluster_valid_hosts = [host_ref.value for host_ref in cluster_hosts.ManagedObjectReference]
# 3. 根據名字查找datastore
datastore = get_special_datastore(datastore_name)
# 4. 獲取datastore的host
if datastore:
datastore_hosts = session.invoke_api(vim_util,
'get_object_property',
session.vim,
datastore,
'host')
# 5. 判斷datastore的host有沒有在cluster的host列表里
for dh in datastore_hosts.DatastoreHostMount:
if dh.key.value in cluster_valid_hosts:
return True
print('ERROR~the datastore %s is not belongs cluster %s' % (datastore_name, cluster_name))
return False
6.獲取存儲池信息
Cinder對接vmware,cinder配置后端存儲的時候只需要配置vmware的集群名字,一個vmware集群可以擁有多個datastore。Cinder上不配置指定vmware的datastore,創建、掛載卷的時候,vmware driver會從集群里找一個能用的datastore來存放vmdk文件。
Cinder getpools --detail 獲取的vmware存儲池信息是由vmware driver方法cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver#get_volume_stats 拿到的。但是目前這個方法,total_capacity_gb和free_capacity_gb寫死unknown。
驅動這樣做的原因,可能是因為一個cluster可以有多個datastore,容量不好獲取,如果是用全部datastore的容量總和作為容量返回,可能10個datastore每個只剩下1G容量,返回總容量有10G,但是想要創建2G的vmdk文件是創建不了的。
四、硬盤/卷信息
1.查看虛機的硬盤信息
VirtualMachine.config.hardware包含以下屬性,可以查看虛機配置的內存、cpu、存儲等。
NAME TYPE DESCRIPTION
device* VirtualDevice[] The set of virtual devices belonging to the virtual machine. This list is unordered.
memoryMB xsd:int Memory size, in MB.
numCoresPerSocket* xsd:int Number of cores used to distribute virtual CPUs among sockets in this virtual machine. If the value is unset it implies to numCoresPerSocket = 1.
Since vSphere API 5.0
numCPU xsd:int Number of virtual CPUs present in this virtual machine.
virtualICH7MPresent* xsd:boolean Does this virtual machine have Virtual Intel I/O Controller Hub 7
Since vSphere API 5.0
virtualSMCPresent* xsd:boolean Does this virtual machine have System Management Controller
Since vSphere API 5.0
代碼:
def get_storage(vm_name):
# 獲取虛機列表
retrieve_result = session.invoke_api(vim_util,
'get_objects',
session.vim,
'VirtualMachine',
max_objects)
# 遍歷虛機列表,根據名稱找到虛機對象,作為backing
vms = retrieve_result.objects
backing = None
for vm in vms:
if vm.propSet[0].val == vm_name:
backing = vm.obj
# 獲取backing的屬性config.hardware.device
hardware_devices = session.invoke_api(vim_util,
'get_object_property',
session.vim,
backing,
'config.hardware.device')
hardware_devices = hardware_devices.VirtualDevice
devices = []
for device in hardware_devices:
# 返回所有VirtualDisk對象
if device.__class__.__name__ == "VirtualDisk":
devices.append(device)
return devices
返回:
[(VirtualDisk){
key = 2000
deviceInfo =
(Description){
label = "Hard disk 1"
summary = "10,485,760 KB"
}
backing =
(VirtualDiskFlatVer2BackingInfo){
fileName = "[storage_nfs3] wangyue_vm/wangyue_vm.vmdk"
datastore =
(datastore){
value = "datastore-1001"
_type = "Datastore"
}
backingObjectId = None
diskMode = "persistent"
split = False
writeThrough = False
thinProvisioned = True
uuid = "6000C29f-9286-0b6b-21c5-4154503fb734"
contentId = "be21a9c0aa3ffdf2413ea572fffffffe"
digestEnabled = False
sharing = "sharingNone"
}
controllerKey = 1000
unitNumber = 0
capacityInKB = 10485760
capacityInBytes = 10737418240
shares =
(SharesInfo){
shares = 1000
level = "normal"
}
storageIOAllocation =
(StorageIOAllocationInfo){
limit = -1
shares =
(SharesInfo){
shares = 1000
level = "normal"
}
reservation = 0
}
diskObjectId = "708-2000"
}]
2.增加硬盤
調用VirtualDiskManager.CreateVirtualDisk_Task往datastore指定路徑里添加vmdk文件
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualDiskManager used to make the method call.
name xsd:string The name of the disk, either a datastore path or a URL referring to the virtual disk to be created.
datacenter* ManagedObjectReference
to a Datacenter If name is a datastore path, the datacenter for that datastore path. Not needed when invoked directly on ESX. If not specified on a call to VirtualCenter, name must be a URL.
spec VirtualDiskSpec The specification of the virtual disk to be created.
VirtualDiskSpec屬性:
NAME TYPE DESCRIPTION
adapterType xsd:string The type of the virtual disk adapter for the new virtual disk.
See VirtualDiskAdapterType
diskType xsd:string The type of the new virtual disk.
See VirtualDiskType
adapterType Enum Constants:
NAME DESCRIPTION
busLogic Use BusLogic emulation for the virtual disk
ide Use IDE emulation for the virtual disk
lsiLogic Use LSILogic emulation for the virtual disk
diskType Enum Constants:
NAME DESCRIPTION
delta A redo log disk. This format is only applicable as a destination format in a clone operation, and not usable for disk creation.
Since vSphere API 5.5
eagerZeroedThick An eager zeroed thick disk has all space allocated and wiped clean of any previous contents on the physical media at creation time. Such disks may take longer time during creation compared to other disk formats.
flatMonolithic A preallocated monolithic disk. Disks in this format can be used with other VMware products. This format is only applicable as a destination format in a clone operation, and not usable for disk creation.
Since vSphere API 4.0
preallocated A preallocated disk has all space allocated at creation time and the space is zeroed on demand as the space is used.
raw Raw device.
rdm Virtual compatibility mode raw disk mapping. An rdm virtual disk grants access to the entire raw disk and the virtual disk can participate in snapshots.
rdmp Physical compatibility mode (pass-through) raw disk mapping. An rdmp virtual disk passes SCSI commands directly to the hardware, but the virtual disk cannot participate in snapshots.
seSparse A sparse (allocate on demand) format with additional space optimizations.
Since vSphere API 5.1
sparse2Gb A sparse disk with 2GB maximum extent size. Disks in this format can be used with other VMware products. The 2GB extent size makes these disks easier to burn to dvd or use on filesystems that don't support large files. This format is only applicable as a destination format in a clone operation, and not usable for disk creation.
sparseMonolithic A sparse monolithic disk. Disks in this format can be used with other VMware products. This format is only applicable as a destination format in a clone operation, and not usable for disk creation.
Since vSphere API 4.0
thick A thick disk has all space allocated at creation time. This space may contain stale data on the physical media. Thick disks are primarily used for virtual machine clustering, but they are generally insecure and should not be used. Due to better performance and security properties, the use of the 'preallocated' format is preferred over this format.
thick2Gb A thick disk with 2GB maximum extent size. Disks in this format can be used with other VMware products. The 2GB extent size makes these disks easier to burn to dvd or use on filesystems that don't support large files. This format is only applicable as a destination format in a clone operation, and not usable for disk creation.
thin Space required for thin-provisioned virtual disk is allocated and zeroed on demand as the space is used.
def create_diskdevice(vm_name, disk_name):
# 獲取datastore的datacenter,從Vcenter managed objects結構圖看出datacenter是datastore的上級
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'Datastore',
max_objects)
if retrieve_result.objects:
for obj_content in retrieve_result.objects:
props = _get_object_properties(obj_content)
if 'name' in props and props['name'] == 'storage_nfs3':
backing = obj_content.obj
datacenter = _get_parent(backing, 'Datacenter')
virtual_disk_manager = session.vim.service_content.virtualDiskManager
# 生成VirtualDiskSpec
cf = session.vim.client.factory
spec = cf.create('ns0:FileBackedVirtualDiskSpec')
spec.capacityKb = 1024 * 1024 * 8
spec.adapterType = 'busLogic'
spec.diskType = 'preallocated'
disk_name = '[%s] %s' % ('storage_nfs3',
"%s/%s%s.vmdk" % (vm_name, vm_name, disk_name))
# 向datastore里添加vmdk文件,路徑datastore/{vm_name}/{vm_name}{disk_name}.vmdk
task = session.invoke_api(session.vim,
"CreateVirtualDisk_Task",
virtual_disk_manager,
name=disk_name,
datacenter=datacenter,
spec=spec)
3.刪除硬盤
調用VirtualDiskManager.DeleteVirtualDisk_Task刪除datastore的vmdk文件
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualDiskManager used to make the method call.
name xsd:string The name of the disk, either a datastore path or a URL referring to the virtual disk to be deleted.
datacenter* ManagedObjectReference
to a Datacenter If name is a datastore path, the datacenter for that datastore path. Not needed when invoked directly on ESX. If not specified on a call to VirtualCenter, name must be a URL.
def delete_diskdevice(ds_name, disk_folder, disk_name):
# 查詢datastore的datacenter
backing = None
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'Datastore',
max_objects)
if retrieve_result.objects:
for obj_content in retrieve_result.objects:
props = _get_object_properties(obj_content)
if 'name' in props and props['name'] == ds_name:
backing = obj_content.obj
data_center = _get_parent(backing, 'Datacenter')
virtual_disk_manager = session.vim.service_content.virtualDiskManager
disk_name = '[%s] %s' % (ds_name,
"%s/%s%s.vmdk" % (disk_folder, disk_folder, disk_name))
# 向datastore里刪除vmdk文件,路徑{ds_name}/{disk_folder}/{disk_folder}{disk_name}.vmdk
task = session.invoke_api(session.vim,
"DeleteVirtualDisk_Task",
virtual_disk_manager,
name=disk_name,
datacenter=data_center)
print task
4.Datastore之間遷移磁盤
調用VirtualDiskManager.MoveVirtualDisk_Task遷移datastore的vmdk文件到另一個datastore
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualDiskManager used to make the method call.
sourceName xsd:string The name of the source, either a datastore path or a URL referring to the virtual disk to be moved.
sourceDatacenter* ManagedObjectReference
to a Datacenter If sourceName is a datastore path, the datacenter for that datastore path. Not needed when invoked directly on ESX. If not specified on a call to VirtualCenter, sourceName must be a URL.
destName xsd:string The name of the destination, either a datastore path or a URL referring to the destination virtual disk.
destDatacenter* ManagedObjectReference
to a Datacenter If destName is a datastore path, the datacenter for that datastore path. Not needed when invoked directly on ESX. If not specified on a call to VirtualCenter, it is assumed that the destination path belongs to the source datacenter.
force* xsd:boolean If true, overwrite any indentically named disk at the destination. If not specified, it is assumed to be false
profile* VirtualMachineProfileSpec[] User can specify new set of profile when moving virtual disk.
Since vSphere API 5.5
def move_vmdk_file(src_dc_name, dest_dc_name, disk_folder, disk_name):
# 獲取原datastore
src_dc = get_special_datastore(src_dc_name)
# 獲取目標datastore
dest_dc = get_special_datastore(dest_dc_name)
# 獲取原datastore的datacenter
src_data_center = _get_parent(src_dc, 'Datacenter')
# 獲取目標datastore的datacenter
des_data_center = _get_parent(dest_dc, 'Datacenter')
diskMgr = session.vim.service_content.virtualDiskManager
# 設置源、目標的文件地址
src_vmdk_file_path = '[%s] %s' % (src_dc_name,
"%s/%s%s.vmdk" % (disk_folder, disk_folder, disk_name))
dest_vmdk_file_path = '[%s] %s' % (dest_dc_name,
"%s/%s%s.vmdk" % ('wangyuetest', disk_folder, disk_name))
task = session.invoke_api(session.vim,
'MoveVirtualDisk_Task',
diskMgr,
sourceName=src_vmdk_file_path,
sourceDatacenter=src_data_center,
destName=dest_vmdk_file_path,
destDatacenter=des_data_center,
force=True)
print task
5.Datastore之間復制磁盤
調用VirtualDiskManager.CopyVirtualDisk_Task遷移datastore的vmdk文件到另一個datastore。
參數和調用方式都跟VirtualDiskManager.MoveVirtualDisk_Task一樣,方法名字改下而已。
task = session.invoke_api(session.vim,
'CopyVirtualDisk_Task',
diskMgr,
sourceName=src_vmdk_file_path,
sourceDatacenter=src_data_center,
destName=dest_vmdk_file_path,
destDatacenter=des_data_center,
force=True)
6.查詢datastore下面vmdk文件
Datastore有屬性browser,類型是HostDatastoreBrowser。
NAME TYPE DESCRIPTION
browser ManagedObjectReference
to aHostDatastoreBrowser DatastoreBrowser used to browse this datastore.
HostDatastoreBrowser對象包含方法SearchDatastoreSubFolders_Task,就是用于查詢datastore下的文件和文件夾,返回列表。該方法的官方說明是:
Returns the information for the files that match the given search criteria as a SearchResults[] object. Searches the folder specified by the datastore path and all subfolders. The Datastore.Browse privilege must be held on the datastore identified by the datastore path.
調用該方法,需要傳遞參數:
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the HostDatastoreBrowser used to make the method call.
datastorePath xsd:string
searchSpec* HostDatastoreBrowserSearchSpec
返回值是一個task
TYPE DESCRIPTION
ManagedObjectReference
to a Task This method returns a Task object with which to monitor the operation. The info.result property in the Task contains the HostDatastoreBrowserSearchResults upon success.
這個task不會很快結束得到查詢結果,我們需要通過while一直檢查task.info.state是否從running變為success,然后才能拿到task.info.result。Result是FileInfo類型的數組,我們從FileInfo對象拿到文件大小、路徑等屬性。
NAME TYPE DESCRIPTION
fileSize* xsd:long The size of the file in bytes.
modification* xsd:dateTime The last date and time the file was modified.
owner* xsd:string The user name of the owner of the file.
Since vSphere API 4.0
path xsd:string The path relative to the folder path in the search results.
代碼:
def get_allfile_in_datastore(ds_name):
"""
查詢datastore下的所有文件列表
:param ds_name:
:return:
"""
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'Datastore',
max_objects)
if retrieve_result.objects:
for obj_content in retrieve_result.objects:
props = _get_object_properties(obj_content)
# 查詢datastore對象
if 'name' in props and props['name'] == ds_name:
browser = session.invoke_api(vim_util,
'get_object_property',
session.vim,
obj_content.obj,
'browser')
summary = session.invoke_api(vim_util,
'get_object_property',
session.vim,
obj_content.obj,
'summary')
# 設置datastore的地址,格式是[summary.name]
datastore_path = "[" + summary.name + "]"
# 設置查詢用的spec
search_spec = session.vim.client.factory.create('ns0:HostDatastoreBrowserSearchSpec')
search_spec.matchPattern = '*'
# 啟動搜索任務
task = session.invoke_api(session.vim,
"SearchDatastoreSubFolders_Task",
browser,
datastorePath=datastore_path,
searchSpec=search_spec)
# 一直循環查詢任務的狀態info.state是否從running變成success
search_result = session.invoke_api(vim_util,
'get_object_property',
session.vim,
task,
'info')
while search_result.state == 'running':
search_result = session.invoke_api(vim_util,
'get_object_property',
session.vim,
task,
'info')
print search_result.result
查詢結果:
(ArrayOfHostDatastoreBrowserSearchResults){
HostDatastoreBrowserSearchResults[] =
(HostDatastoreBrowserSearchResults){
datastore =
(datastore){
value = "datastore-1001"
_type = "Datastore"
}
folderPath = "[storage_nfs3] wangyue_vm/"
file[] =
(FileInfo){
path = "wangyue_vm-flat.vmdk"
},
(FileInfo){
path = "wangyue_vmdisk1-flat.vmdk"
},
(FileInfo){
path = "wangyue_vm-511c0281.hlog"
},
(FileInfo){
path = "wangyue_vm.vmdk"
},
(FileInfo){
path = "volume-377cb9aa-ad18-44c3-9524-924570a1f949"
},
(FileInfo){
path = "wangyue_vm.vmx"
},
(FileInfo){
path = "wangyue_vmdisk1.vmdk"
},
(FileInfo){
path = "wangyue_vm.vmsd"
},
},
(HostDatastoreBrowserSearchResults){
datastore =
(datastore){
value = "datastore-1001"
_type = "Datastore"
}
folderPath = "[storage_nfs3]"
file[] =
(FileInfo){
path = "volume-d5c58e06-d231-4f65-9c82-aafa970045fe"
},
(FileInfo){
path = "volume-377cb9aa-ad18-44c3-9524-924570a1f949"
},
(FileInfo){
path = "wangyue_vm"
},
},
}
7.給硬盤擴展空間
調用VirtualDiskManager.ExtendVirtualDisk_Task
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualDiskManager used to make the method call.
name xsd:string The name of the disk, either a datastore path or a URL referring to the virtual disk whose capacity should be expanded.
datacenter* ManagedObjectReference
to a Datacenter If name is a datastore path, the datacenter for that datastore path. Not needed when invoked directly on ESX. If not specified on a call to VirtualCenter, name must be a URL.
newCapacityKb xsd:long The new capacty of the virtual disk in Kb.
eagerZero* xsd:boolean If true, the extended part of the disk will be explicitly filled with zeroes.
Since vSphere API 4.0
代碼:
def extend_disk():
data_store = get_special_datastore('storage_nfs3')
data_center = _get_parent(data_store, 'Datacenter')
virtual_disk_manager = session.vim.service_content.virtualDiskManager
vmdk_file_path = '[storage_nfs3] wangyue_vm/wangyue_vmdisk1.vmdk'
capacityKb = 1024 ** 3 * 2
task = session.invoke_api(session.vim,
"ExtendVirtualDisk_Task",
virtual_disk_manager,
datacenter=data_center,
name=vmdk_file_path,
newCapacityKb=capacityKb,
eagerZero=True)
session.wait_for_task(task)
result = session.invoke_api(vim_util,
'get_object_property',
session.vim,
task,
'info')
print result
8.虛機上掛載、卸載卷
這些工作主要有nova那邊負責。我從nova vmware driver代碼了解了實現原理:
本質都是調用VirtualMachine.ReconfigVM_Task重配置虛機。
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualMachine used to make the method call.
spec VirtualMachineConfigSpec The new configuration values.
VirtualMachineConfigSpec對象有個deviceChange屬性,保存用戶對虛機磁盤設備修改操作。
deviceChange* VirtualDeviceConfigSpec[] Set of virtual devices being modified by the configuration operation.
VirtualDeviceConfigSpec:
Properties
NAME TYPE DESCRIPTION
device VirtualDevice Device specification, with all necessary properties set.
fileOperation* VirtualDeviceConfigSpecFileOperation Type of operation being performed on the backing of the specified virtual device. If no file operation is specified in the VirtualDeviceSpec, then any backing filenames in theVirtualDevice must refer to files that already exist. The "replace" and "delete" values for this property are only applicable to virtual disk backing files.
operation* VirtualDeviceConfigSpecOperation Type of operation being performed on the specified virtual device. If no operation is specified, the spec. is ignored.
profile* VirtualMachineProfileSpec[] Virtual Device Profile requirement. Profiles are solution specifics. Storage Profile Based Management(SPBM) is a vSphere server extension. The API users who want to provision VMs using Storage Profiles, need to interact with SPBM service. This is an optional parameter and if user doesn't specify profile, the default behavior will apply.
Since vSphere API 5.5
上面有個operation屬性,用于設置你這個磁盤要做什么操作,比如添加或者移除,有三種可選項:
VirtualDeviceConfigSpecOperation Enum Constants:
NAME DESCRIPTION
add Specifies the addition of a virtual device to the configuration.
edit Specifies changes to the virtual device specification.
remove Specifies the removal of a virtual device.
對虛機掛載、卸載磁盤設備,就是往VirtualMachineConfigSpec.deviceChange這個數組里添加VirtualDeviceConfigSpec對象,然后對象設置operation為add或者remove,invoke_api后就能實現。主要是nova的邏輯,在此就不用demo實現了。
五、快照
Cinder以vmware集群為后端創建的卷,在vmware這邊其實是一個虛機,不過這個虛機只有一個沒有操作系統的盤。Cinder給vmware卷創建快照,調用的是vmware虛機快照的方法。最后真正開始做卷快照實際上是在將卷掛載到影子虛擬機上,對影子虛擬機做虛擬機快照。
1.創建快照
VirtualMachineSnapshot.CreateSnapshot_Task
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualMachine used to make the method call.
name xsd:string The name for this snapshot. The name need not be unique for this virtual machine.
description* xsd:string A description for this snapshot. If omitted, a default description may be provided.
memory xsd:boolean If TRUE, a dump of the internal state of the virtual machine (basically a memory dump) is included in the snapshot. Memory snapshots consume time and resources, and thus take longer to create. When set to FALSE, the power state of the snapshot is set to powered off.
capabilities indicates whether or not this virtual machine supports this operation.
quiesce xsd:boolean If TRUE and the virtual machine is powered on when the snapshot is taken, VMware Tools is used to quiesce the file system in the virtual machine. This assures that a disk snapshot represents a consistent state of the guest file systems. If the virtual machine is powered off or VMware Tools are not available, the quiesce flag is ignored.
Return Value
TYPE DESCRIPTION
ManagedObjectReference
to a Task This method returns a Task object with which to monitor the operation. The info.result property in the Task contains the newly created VirtualMachineSnapshot upon success.
代碼:
def create_snapshot(volume_name, snapshot_name, description):
# cinder的卷在vmware對應一個虛機,先查出這個虛機
snapshot = None
retrieve_result = session.invoke_api(vim_util, 'get_objects',
session.vim,
'VirtualMachine',
max_objects)
for vm in retrieve_result.objects:
if vm.propSet[0].val == volume_name:
# We got the result, so cancel further retrieval.
backing = vm.obj
# 對虛機做快照
task = session.invoke_api(session.vim,
'CreateSnapshot_Task',
backing, name=snapshot_name,
description=description,
memory=False, quiesce=False)
task_info = session.wait_for_task(task)
snapshot = task_info.result
return snapshot
2.查詢快照樹
Vmware的快照是一棵樹,每一次快照都是上一次的子快照。
快照VirtualMachineSnapshotInfo屬于虛機VirtualMachine的snapshot屬性。
Properties
NAME TYPE DESCRIPTION
currentSnapshot* ManagedObjectReference
to a VirtualMachineSnapshot Current snapshot of the virtual machine
This property is set by calling Snapshot.revert or VirtualMachine.createSnapshot. This property will be empty when the working snapshot is at the root of the snapshot tree.
rootSnapshotList VirtualMachineSnapshotTree[] Data for the entire set of snapshots for one virtual machine.
代碼:
snapshot = session.invoke_api(vim_util, 'get_object_property',
session.vim, backing,
'snapshot')
輸出:
3.修改快照名
VirtualMachineSnapshot.RenameSnapshot 可用于修改快照名和解釋
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualMachineSnapshot used to make the method call.
name* xsd:string New name for the snapshot.
description* xsd:string New description for the snapshot.
session.invoke_api(session.vim,
'RenameSnapshot',
snapshot,
name=newname,
description=newdes
)
4.刪除快照
VirtualMachineSnapshot.RemoveSnapshot_Task
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualMachineSnapshot used to make the method call.
removeChildren xsd:boolean Flag to specify removal of the entire snapshot subtree.
consolidate* xsd:boolean (optional) If set to true, the virtual disk associated with this snapshot will be merged with other disk if possible. Defaults to true.
Since vSphere API 5.0
task = session.invoke_api(session.vim,
'RemoveSnapshot_Task',
snapshot, removeChildren=False)
5.導出快照
VirtualMachineSnapshot.ExportSnapshot,可用于導出快照,返回值是一個HttpNfcLease。
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualMachineSnapshot used to make the method call.
Return Value
TYPE DESCRIPTION
ManagedObjectReference
to a HttpNfcLease The export lease on this VirtualMachineSnapshot. The export task continues running until the lease is completed by the caller.
6.從快照創建卷
這個功能cinder vmware driver原生支持,入口在cinder.volume.drivers.vmware.vmdk.VMwareVcVmdkDriver#create_volume_from_snapshot。 流程:
① 檢查目標卷是否存在
② 檢查vmware快照的backing是否存在
③ 拿到vmware快照
④ 獲得目標卷的clone_type
⑤ 根據快照克隆到目標卷
Cinder定義了兩種clone_type,用戶可以設置在volume-type的extra_spec,沒設置默認選用FULL_CLONE_TYPE。
LINKED_CLONE_TYPE = 'linked'
FULL_CLONE_TYPE = 'full'
這兩種clone_type分別對應了vmware上的兩種diskMoveType:"createNewChildDiskBacking"和"moveAllDiskBackingsAndDisallowSharing"。"moveAllDiskBackingsAndDisallowSharing"就是把快照原卷的backing全量拷到目標datastore里,"createNewChildDiskBacking"則是目標卷和快照卷共享backing。
Enum - VirtualMachineRelocateDiskMoveOptions詳細說明:
NAME DESCRIPTION
createNewChildDiskBacking Create a new child disk backing on the destination datastore. None of the virtual disk's existing files should be moved from their current locations.
Note that in the case of a clone operation, this means that the original virtual machine's disks are now all being shared. This is only safe if the clone was taken from a snapshot point, because snapshot points are always read-only. Thus for a clone this option is only valid when cloning from a snapshot. Note that in the case of a RelocateVM_Task operation, child disks are created for the virtual disks in the current virtual machine configuration only.
moveAllDiskBackingsAndDisallowSharing All of the virtual disk's backings should be moved to the new datastore. It is not acceptable to attach to a disk backing with the same content ID on the destination datastore. During a clone operation any delta disk backings will be consolidated.
最后實際調用的是VirtualMachine.CloneVM_Task
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the VirtualMachine used to make the method call.
folder P ManagedObjectReference
to a Folder The location of the new virtual machine.
name xsd:string The name of the new virtual machine.
spec VirtualMachineCloneSpec Specifies how to clone the virtual machine. The folder specified in the spec takes precedence over the folder parameter.
VirtualMachineCloneSpec
Properties
NAME TYPE DESCRIPTION
config* VirtualMachineConfigSpec Deprecated. as of vSphere API 6.0. Use deviceChange in location instead for specifying any virtual device changes for disks and networks. All other VM configuration changes should useReconfigVM_Task API after the clone operation finishes.
An optional specification of changes to the virtual hardware. For example, this can be used to, (but not limited to) reconfigure the networks the virtual switches are hooked up to in the cloned virtual machine.
customization* CustomizationSpec An optional guest operating system customization specification. This value is ignored if a template is being created.
location VirtualMachineRelocateSpec A type of RelocateSpec that specifies the location of resources the newly cloned virtual machine will use. The location specifies:
oA datastore where the virtual machine will be located on physical storage. This is always provided because it indicates where the newly created clone will be copied.
oa resource pool and optionally a host. The resource pool determines what compute resources will be available to the clone and the host indicates which machine will host the clone.
memory* xsd:boolean Flag indicating whether to retain a copy of the source virtual machine's memory state in the clone. Retaining the memory state during clone results in a clone in suspended state with all network adapters removed to avoid network conflicts, except those with a VirtualEthernetCard.addressType of "manual". Users of this flag should take special care so that, when adding a network adapter back to the clone, the VM is not resumed on the same VM network as the source VM, or else MAC address conflicts could occur. When cloning between two hosts with different CPUs outside an EVC cluster, users of this flag should be aware that vCenter does not verify CPU compatibility between the clone's memory state and the target host prior to the clone operation, so the clone may fail to resume until it is migrated to a host with a compatible CPU.
This flag is ignored if the snapshot parameter is unset. This flag only applies for a snapshot taken on a running or suspended virtual machine with the 'memory' parameter set to true, because otherwise the snapshot has no memory state. This flag defaults to false.
Since vSphere API 5.5
powerOn xsd:boolean Specifies whether or not the new VirtualMachine should be powered on after creation. As part of a customization, this flag is normally set to true, since the first power-on operation completes the customization process. This flag is ignored if a template is being created.
snapshot* ManagedObjectReference
to aVirtualMachineSnapshot Snapshot reference from which to base the clone.
If this parameter is set, the clone is based off of the snapshot point. This means that the newly created virtual machine will have the same configuration as the virtual machine at the time the snapshot was taken.
If this property is not set then the clone is based off of the virtual machine's current configuration.
Setting this is only supported if the host this virtual machine is currently residing on supports cloning from a snapshot point. Such support does not need to exist on the destination host for the clone.
Setting this is only supported if the virtual machine supports reporting snapshot configuration information. See snapshotConfigSupported. Such support does not need to exist on the destination host for the clone.
Since vSphere API 4.0
template xsd:boolean Specifies whether or not the new virtual machine should be marked as a template.
VirtualMachineConfigSpec和VirtualMachineRelocateSpec參數太多,就不貼出來了。
代碼調用:
def _get_relocate_spec(self, datastore, resource_pool, host,
disk_move_type, disk_type=None, disk_device=None):
"""Return spec for relocating volume backing.
:param datastore: Reference to the datastore
:param resource_pool: Reference to the resource pool
:param host: Reference to the host
:param disk_move_type: Disk move type option
:param disk_type: Destination disk type
:param disk_device: Virtual device corresponding to the disk
:return: Spec for relocation
"""
cf = self._session.vim.client.factory
relocate_spec = cf.create('ns0:VirtualMachineRelocateSpec')
relocate_spec.datastore = datastore
relocate_spec.pool = resource_pool
relocate_spec.host = host
relocate_spec.diskMoveType = disk_move_type
if disk_type is not None and disk_device is not None:
disk_locator = self._create_relocate_spec_disk_locator(datastore,
disk_type,
disk_device)
relocate_spec.disk = [disk_locator]
LOG.debug("Spec for relocating the backing: %s.", relocate_spec)
return relocate_spec
def _get_clone_spec(self, datastore, disk_move_type, snapshot, backing,
disk_type, host=None, resource_pool=None,
extra_config=None):
"""Get the clone spec.
:param datastore: Reference to datastore
:param disk_move_type: Disk move type
:param snapshot: Reference to snapshot
:param backing: Source backing VM
:param disk_type: Disk type of clone
:param host: Target host
:param resource_pool: Target resource pool
:param extra_config: Key-value pairs to be written to backing's
extra-config
:return: Clone spec
"""
if disk_type is not None:
disk_device = self._get_disk_device(backing)
else:
disk_device = None
relocate_spec = self._get_relocate_spec(datastore, resource_pool, host,
disk_move_type, disk_type,
disk_device)
cf = self._session.vim.client.factory
clone_spec = cf.create('ns0:VirtualMachineCloneSpec')
clone_spec.location = relocate_spec
clone_spec.powerOn = False
clone_spec.template = False
clone_spec.snapshot = snapshot
if extra_config:
config_spec = cf.create('ns0:VirtualMachineConfigSpec')
if BACKING_UUID_KEY in extra_config:
config_spec.instanceUuid = extra_config.pop(BACKING_UUID_KEY)
config_spec.extraConfig = self._get_extra_config_option_values(
extra_config)
clone_spec.config = config_spec
LOG.debug("Spec for cloning the backing: %s.", clone_spec)
return clone_spec
clone_spec = self._get_clone_spec(
datastore, disk_move_type, snapshot, backing, disk_type, host=host,
resource_pool=resource_pool, extra_config=extra_config)
task = self._session.invoke_api(self._session.vim, 'CloneVM_Task',
backing, folder=folder, name=name,
spec=clone_spec)
六、QOS控制
VMware vSphere Storage/ Network IO Control可設定存儲和網絡服務質量優先級,確保關鍵業務對資源的訪問。
StorageIORMInfo 對象用于管理datastore存儲IO。
Properties
NAME TYPE DESCRIPTION
congestionThreshold xsd:int The latency beyond which the storage array is considered congested.
If storage I/O resource management is enabled on a datastore, the algorithm tries to maintain the latency to be below or close to this value. The unit is millisecond. The range of this value is between 5 to 100 milliseconds.
congestionThresholdMode xsd:string Mode of congestion threshold specification For more information, see StorageIORMThresholdMode
Since vSphere API 5.1
enabled xsd:boolean Flag indicating whether or not the service is enabled.
percentOfPeakThroughput* xsd:int The percentage of peak throughput to be used for setting congestion threshold of a datastore. Valid values are between 50 to 100. Default value is 90%
For more information, see congestionThreshold
Since vSphere API 5.1
reservableIopsThreshold* xsd:int Storage DRS makes storage migration recommendations if total IOPs reservation for all VMs running on the datastore is higher than specified threshold value. This value (if present) overrides
Since vSphere API 6.0
reservationEnabled xsd:boolean Flag indicating whether IO reservations support is enabled.
Since vSphere API 6.0
statsAggregationDisabled* xsd:boolean Flag indicating whether stats aggregation is disabled.
Since vSphere API 5.0
statsCollectionEnabled xsd:boolean Flag indicating whether service is running in stats collection mode.
Since vSphere API 5.0
1.查看storage io control
Datastore對象有StorageIORMInfo類型的屬性iormConfiguration,保存了當前datastore的io控制配置。
代碼調用:
def query_storage_io(datastore):
io_conf = session.invoke_api(vim_util,
'get_object_property',
session.vim,
datastore,
'iormConfiguration')
print io_conf
返回值:
(StorageIORMInfo){
enabled = True
congestionThresholdMode = "automatic"
congestionThreshold = 30
percentOfPeakThroughput = 88
statsCollectionEnabled = False
reservationEnabled = False
statsAggregationDisabled = False
}
2.設置storage io control
可通過方法StorageResourceManager.ConfigureDatastoreIORM_Task配置。
Parameters
NAME TYPE DESCRIPTION
_this ManagedObjectReference A reference to the StorageResourceManager used to make the method call.
datastore P ManagedObjectReference
to a Datastore The datastore to be configured.
spec StorageIORMConfigSpec The configuration spec.
代碼調用:
def configure_storage_io(ds):
ioconfig_spec = session.vim.client.factory.create('ns0:StorageIORMConfigSpec')
# 啟用storage io 控制,設置手動模式的擁堵閾值
# ioconfig_spec.enabled = True
# ioconfig_spec.congestionThresholdMode = 'manual'
# ioconfig_spec.congestionThreshold = 70
# --------------
# 啟用storage io 控制,設置88% 的吞吐量峰值
# ioconfig_spec.enabled = True
# ioconfig_spec.congestionThresholdMode = 'automatic'
# ioconfig_spec.percentOfPeakThroughput = 88
# --------------
# 禁用storage io 控制。存儲I/O控制默認就是關閉的。
ioconfig_spec.enabled = False
ioconfig_spec.reservationEnabled = False
ioconfig_spec.statsAggregationDisabled = False
ioconfig_spec.statsCollectionEnabled = False
--------------
storage_resource_manager = session.vim.service_content.storageResourceManager
task = session.invoke_api(session.vim,
"ConfigureDatastoreIORM_Task",
storage_resource_manager,
datastore=ds,
spec=ioconfig_spec)
print session.wait_for_task(task)
七、配額控制
Vmware好像沒有配額功能。目前沒看到。