除了 vSphere Client,還可以使用資料中心 CLI (DCLI) 命令建立和管理虛擬機器類別。DCLI 命令可讓您更加靈活地存取 vSphere Client 中未提供的虛擬機器組態選項。
必要條件
使用根使用者帳戶登入 vCenter Server,然後輸入 dcli +i 以在互動模式下使用 DCLI。
如需 DCLI 命令的相關資訊,請參閱 DCLI 命令執行概觀。
可用的 DCLI 命令
命令 | 說明 |
---|---|
namespacemanagement virtualmachineclasses create | 建立虛擬機器類別物件。 |
namespacemanagement virtualmachineclasses delete | 刪除虛擬機器類別物件。 |
namespacemanagement virtualmachineclasses get | 傳回虛擬機器類別的相關資訊。 |
namespacemanagement virtualmachineclasses list | 傳回所有虛擬機器類別的相關資訊。 |
namespacemanagement virtualmachineclasses update | 更新虛擬機器類別物件的組態。 |
使用資料中心 CLI 建立虛擬機器類別
身為 vSphere 管理員,可以使用 DCLI com vmware vcenter namespacemanagement virtualmachineclasses create 命令建立虛擬機器類別。您可以設定 CPU、記憶體、記憶體保留區、網路介面卡等虛擬機器內容。
引數 | 說明 |
---|---|
-h, --help | 顯示此說明訊息並結束。 |
--config-spec CONFIG_SPEC | 與虛擬機器類別相關聯的 VirtualMachineConfigSpec (json 輸入)。 |
--cpu-count CPU_COUNT | 必要。為此類虛擬機器設定的 CPU 數目 (整數)。 |
--cpu-reservation CPU_RESERVATION | 為虛擬機器保留的可用 CPU 總數量的百分比 (整數)。 |
--description DESCRIPTION | 虛擬機器類別的說明 (字串)。 |
--devices-dynamic-direct-path-io-devices DEVICES_DYNAMIC_DIRECT_PATH_IO_DEVICES | 動態 DirectPath I/O 裝置清單 (json 輸入)。 |
--devices-vgpu-devices DEVICES_VGPU_DEVICES | vGPU 裝置清單 (json 輸入)。 |
--id ID | 必要。虛擬機器類別的識別碼 (字串)。 |
--instance-storage-policy INSTANCE_STORAGE_POLICY | 與執行個體儲存區對應的儲存區原則 (字串)。 |
--instance-storage-volumes INSTANCE_STORAGE_VOLUMES | 執行個體儲存磁碟區清單 (json 輸入)。 |
--memory-mb MEMORY_MB | 必要。為此類虛擬機器設定的記憶體量 (以 MB 為單位) (整數)。 |
--memory-reservation MEMORY_RESERVATION | 為此類別的虛擬機器保留的可用記憶體百分比。 |
使用下列範例建立具有不同內容的虛擬機器類別。
CPU 和記憶體
com vmware vcenter namespacemanagement virtualmachineclasses create --id cpu-mem-class --cpu-count 2 --memory-mb 2048 --config-spec '{"_typeName":"VirtualMachineConfigSpec","numCPUs":2,"memoryMB":2048}'
在組態規格中設定 numCPUs
和 memoryMB
是可選作業。如果選擇設定這些參數,則這些參數必須與必填 --cpu-count
和 --memory-mb
vAPI 欄位具有相同的值。
CPU 和記憶體保留區
使用具有 CPU 和記憶體保留的組態規格建立虛擬機器類別時,memoryAllocation 的記憶體保留或限制以 MB 為單位,cpuAllocation 的 CPU 保留或限制以 MHz 為單位。
com vmware vcenter namespacemanagement virtualmachineclasses create --id cpu-res-class-1 --config-spec '{"_typeName":"VirtualMachineConfigSpec","numCPUs":2,"memoryMB":2048,"cpuAllocation":{"_typeName":"ResourceAllocationInfo","reservation":200,"limit":200},"memoryAllocation":{"_typeName":"ResourceAllocationInfo","reservation":200,"limit":200}}' --cpu-count 2 --memory-mb 2048
網路介面卡
com vmware vcenter namespacemanagement virtualmachineclasses create --id class-w-e1000 --cpu-count 2 --memory-mb 2048 --config-spec '{"_typeName":"VirtualMachineConfigSpec","deviceChange":[{"_typeName":"VirtualDeviceConfigSpec","operation":"add","device":{"_typeName":"VirtualE1000","key":-100}}]}'
vGPU
com vmware vcenter namespacemanagement virtualmachineclasses create --id vmclass-1 --devices-vgpu-devices '[{"profile_name": "mockup-vmiop-8c"}]' --memory-reservation 100 --cpu-count 2 --memory-mb 4096
com vmware vcenter namespacemanagement virtualmachineclasses create --id vmclass-2 --cpu-count 2 --memory-mb 4096 --config-spec '{"_typeName":"VirtualMachineConfigSpec","deviceChange":[{"_typeName":"VirtualDeviceConfigSpec","operation":"add","device":{"_typeName":"VirtualPCIPassthrough","key":20,"backing":{"_typeName":"VirtualPCIPassthroughVmiopBackingInfo","vgpu":"mockup-vmiop-8c"}}}]}' --memory-reservation 100
執行個體儲存區
com vmware vcenter namespacemanagement virtualmachineclasses create --id vmclass-ist-1 --instance-storage-volumes '[{"size":47}]' --instance-storage-policy "e28d4352-1d1e-431b-b3f7-528bef5838a0" --cpu-count 2 --memory-mb 4096
com vmware vcenter namespacemanagement virtualmachineclasses create --id vmclass-ist-2 --cpu-count 2 --memory-mb 2048 --config-spec '{"_typeName":"VirtualMachineConfigSpec","deviceChange":[{"_typeName":"VirtualDeviceConfigSpec","operation":"add","fileOperation":"create","device":{"_typeName":"VirtualDisk","key":0,"backing":{"_typeName":"VirtualDiskFlatVer2BackingInfo","fileName":"","diskMode":"","thinProvisioned":false},"capacityInKB":0,"capacityInBytes":49283072,"vDiskId":{"_typeName":"ID","id":"e28d4352-1d1e-431b-b3f7-528bef5838a0"}},"profile":[{"_typeName":"VirtualMachineDefinedProfileSpec","profileId":"e28d4352-1d1e-431b-b3f7-528bef5838a0","profileData":{"_typeName":"VirtualMachineProfileRawData","extensionKey":"com.vmware.vim.sps"}}]}]}'
使用資料中心 CLI 更新虛擬機器類別
身為 vSphere 管理員,請使用 DCLI com vmware vcenter namespacemanagement virtualmachineclasses update 命令修改虛擬機器類別。
可參考以下範例。
修改 CPU 和記憶體
com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class cpu-mem-class com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class cpu-mem-class --cpu-count 4 --memory-mb 4096
修改 CPU 和記憶體保留區
使用具有 CPU 和記憶體保留的組態規格建立虛擬機器類別時,memoryAllocation 的記憶體保留或限制以 MB 為單位,cpuAllocation 的 CPU 保留或限制以 MHz 為單位。
com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class cpu-res-class-1 com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class cpu-res-class-1 --cpu-reservation 100 --memory-reservation 100 com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class cpu-res-class-1
此外,還可以使用組態規格更新 CPU 和記憶體保留區。將覆寫任何現有的 CPU 或記憶體保留區。可參考以下範例:
com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class cpu-res-class-1 --config-spec '{"_typeName":"VirtualMachineConfigSpec","cpuAllocation":{"_typeName":"ResourceAllocationInfo","reservation":200,"limit":200},"memoryAllocation":{"_typeName":"ResourceAllocationInfo","reservation":200,"limit":200}}'
新增 vGPU
com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class class-w-e1000 com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class class-w-e1000 --devices-vgpu-devices '[{"profile_name": "mockup-vmiop-8c"}]' com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class class-w-e1000
com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-1 com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-1 --config-spec '{"_typeName":"VirtualMachineConfigSpec","deviceChange":[{"_typeName":"VirtualDeviceConfigSpec","operation":"add","device":{"_typeName":"VirtualPCIPassthrough","key":20,"backing":{"_typeName":"VirtualPCIPassthroughVmiopBackingInfo","vgpu":"mockup-vmiop-8c"}}},{"_typeName":"VirtualDeviceConfigSpec","operation":"add","device":{"_typeName":"VirtualPCIPassthrough","key":20,"backing":{"_typeName":"VirtualPCIPassthroughVmiopBackingInfo","vgpu":"mockup-vmiop"}}}]}' com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-1
移除 vGPU
com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-1 --devices-vgpu-devices '[]' com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-1
新增執行個體儲存區
com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-1 --instance-storage-volumes '[{"size":47}]' --instance-storage-policy "e28d4352-1d1e-431b-b3f7-528bef5838a0" com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-1
com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-ist-2 com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-ist-2 --instance-storage-volumes '[{"size":51},{"size":50}]' --instance-storage-policy "e28d4352-1d1e-431b-b3f7-528bef5838a0" com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-ist-2 com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-ist-2 --config-spec '{"_typeName":"VirtualMachineConfigSpec","deviceChange":[{"_typeName":"VirtualDeviceConfigSpec","operation":"add","fileOperation":"create","device":{"_typeName":"VirtualDisk","key":0,"backing":{"_typeName":"VirtualDiskFlatVer2BackingInfo","fileName":"","diskMode":"","thinProvisioned":false},"capacityInKB":0,"capacityInBytes":52428800,"vDiskId":{"_typeName":"ID","id":"cc737f33-2aa3-4594-aa60-df7d6d4cb984"}},"profile":[{"_typeName":"VirtualMachineDefinedProfileSpec","profileId":"e28d4352-1d1e-431b-b3f7-528bef5838a0","profileData":{"_typeName":"VirtualMachineProfileRawData","extensionKey":"com.vmware.vim.sps"}}]}]}' com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-ist-2
移除執行個體儲存區
com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-ist-1 --instance-storage-volumes '[]' --instance-storage-policy "" com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-ist-1
新增網路介面卡
此命令可將執行個體儲存區和 e1000 NIC 新增至虛擬機器類別。
com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-ist-2 --config-spec '{"_typeName":"VirtualMachineConfigSpec","deviceChange":[{"_typeName":"VirtualDeviceConfigSpec","operation":"add","fileOperation":"create","device":{"_typeName":"VirtualDisk","key":0,"backing":{"_typeName":"VirtualDiskFlatVer2BackingInfo","fileName":"","diskMode":"","thinProvisioned":false},"capacityInKB":0,"capacityInBytes":52428800,"vDiskId":{"_typeName":"ID","id":"cc737f33-2aa3-4594-aa60-df7d6d4cb984"}},"profile":[{"_typeName":"VirtualMachineDefinedProfileSpec","profileId":"e28d4352-1d1e-431b-b3f7-528bef5838a0","profileData":{"_typeName":"VirtualMachineProfileRawData","extensionKey":"com.vmware.vim.sps"}}]},{"_typeName":"VirtualDeviceConfigSpec","operation":"add","device":{"_typeName":"VirtualE1000","key":-100}}]}' com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-ist-2
清空組態規格
com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class class-w-e1000 --config-spec ''
後續步驟
使用 DCLI 建立的虛擬機器類別將在 vCenter Server 中可用。可以使用 vSphere Client 將這些虛擬機器類別指派給命名空間。請參閱使用 vSphere Client 將虛擬機器類別與命名空間相關聯。