除了 vSphere Client,还可以使用数据中心 CLI (DCLI) 命令创建和管理虚拟机类。使用 DCLI 命令时,可以更加灵活地访问 vSphere Client 中未提供的虚拟机配置选项。
必备条件
使用 root 用户帐户登录到 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}'
在 configSpec 中设置 numCPUs
和 memoryMB
是可选操作。如果选择设置这些参数,则这些参数必须与必填 --cpu-count
和 --memory-mb
vAPI 字段具有相同的值。
CPU 和内存预留
使用具有 CPU 和内存预留的 configSpec 创建虚拟机类时,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 和内存预留的 configSpec 创建虚拟机类时,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 网卡添加到虚拟机类。
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 将虚拟机类与命名空间相关联。