In addition the vSphere Client, you can use the Data Center CLI (DCLI) commands to create and manage the VM classes. The DCLI commands give you more flexibility and access to VM configuration options not available in the vSphere Client.

Prerequisites

Log in to vCenter Server using the root user account and type dcli +i to use the DCLI in interactive mode.

For information about DCLI commands, see Overview of Running DCLI Commands.

Available DCLI Commands

Command Description
namespacemanagement virtualmachineclasses create Create a VM class object.
namespacemanagement virtualmachineclasses delete Delete the VM class object.
namespacemanagement virtualmachineclasses get Return information about a VM class.
namespacemanagement virtualmachineclasses list Return information about all VM classes.
namespacemanagement virtualmachineclasses update Update configuration of the VM class object.

Create a VM Class Using Data Center CLI

As a vSphere administrator, use the DCLI com vmware vcenter namespacemanagement virtualmachineclasses create command to create a VM class. You can configure such VM properties as CPU, memory, memory reservations, network adapters, and so on.

The command takes the following arguments.
Argument Description
-h, --help Show this help message and exit.
--config-spec CONFIG_SPEC A VirtualMachineConfigSpec associated with the VM class (json input).
--cpu-count CPU_COUNT Required. The number of CPUs configured for virtual machine of this class (integer).
--cpu-reservation CPU_RESERVATION The percentage of total available CPUs reserved for a virtual machine (integer).
--description DESCRIPTION Description for the VM class (string).
--devices-dynamic-direct-path-io-devices DEVICES_DYNAMIC_DIRECT_PATH_IO_DEVICES List of Dynamic DirectPath I/O devices (json input).
--devices-vgpu-devices DEVICES_VGPU_DEVICES List of vGPU devices (json input).
--id ID Required. Identifier of the virtual machine class (string).
--instance-storage-policy INSTANCE_STORAGE_POLICY Storage policy corresponding to the instance storage (string).
--instance-storage-volumes INSTANCE_STORAGE_VOLUMES List of instance storage volumes (json input).
--memory-mb MEMORY_MB Required. The amount of memory in MB configured for virtual machine of this class (integer).
--memory-reservation MEMORY_RESERVATION The percentage of available memory reserved for a virtual machine of this class.

Use the following examples to create VM classes with different properties.

CPU and Memory

com vmware vcenter namespacemanagement virtualmachineclasses create --id cpu-mem-class --cpu-count 2 --memory-mb 2048 --config-spec '{"_typeName":"VirtualMachineConfigSpec","numCPUs":2,"memoryMB":2048}'

Setting numCPUs and memoryMB in the Config Spec is optional. If you chose to set them, they must have the same values as the mandatory --cpu-count and --memory-mb vAPI fields.

CPU and Memory Reservations

When you create a VM Class by using a Config Spec having CPU and memory reservation, the memory reservation or limit is in MB for memoryAllocation, MHz for cpuAllocation.

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

Network Adapter

The following command creates a network adapter of type E1000.
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}}]}'

vGPUs

In these examples, the first command creates a VM class with a vGPU by using the field --devices-vgpu-devices. The second command creates a VM class with a vGPU by using a configSpec.
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

Instance Storage

The following examples create VM classes that use instance storage by using the --instance-storage-volumes and --instance-storage-policy fields.
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
The ID field in this example is a well-known virtualDisk ID that represents an instance storage device in the VM Service VMs.
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"}}]}]}'

Update a VM Class Using Data Center CLI

As a vSphere administrator, use the DCLI com vmware vcenter namespacemanagement virtualmachineclasses update command to modify a VM class.

Use the following as examples.

Modify CPU and Memory

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

Modify CPU and Memory Reservations

When you create a VM Class by using a Config Spec having CPU and memory reservation, the memory reservation or limit is in MB for memoryAllocation, MHz for cpuAllocation.

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

You can also use Config Spec to update the CPU and memory reservations. Any existing CPU or memory reservations will be overwritten. Use the following as an example:

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}}'

Add vGPUs

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

Remove vGPU

com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class vmclass-1 --devices-vgpu-devices '[]'
 com vmware vcenter namespacemanagement virtualmachineclasses get --vm-class vmclass-1

Add Instance Storage

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

Remove Instance Storage

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

Add Network Adapters

This command adds both an instance storage and an e1000 NIC to the VM class.

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

Empty Config Spec

com vmware vcenter namespacemanagement virtualmachineclasses update --vm-class class-w-e1000 --config-spec ''

What to do next

The VM classes that you create with the DCLI, become available in vCenter Server. You can use the vSphere Client to assign these VM classes to a namespace. See Associate a VM Class with a Namespace Using the vSphere Client.