Creating and Managing Datastores
Each datastore is a logical container, analogous to a file system on a logical volume, where the host places virtual disk files and other virtual machine files. Datastores hide specifics of the physical storage device and provide a uniform model for storing virtual machine files.
The HostDatastoreSystem managed object provides methods for creating and managing datastores. All HostDatastoreSystem methods require a managed object reference to HostDatastoreSystem, and return a reference to the Datastore object after it is created.
HostDatastoreSystem allows you to create and expand, query, and remove or update datastores. HostDatastoreSystem also allows you to configure a datastore principal for a host by calling ConfigureDatastorePrincipal. All virtual machine-related file I/O is performed under this user.
VMFS provisioning tasks are often performed as follows:
1
Call QueryAvailableDisksForVmfs to get the subset of disks that are well suited for holding VMFS datastores.
QueryAvailableDisksForVmfs obtains a list of disks that can be used to contain VMFS datastore extents. You can provide a datastore name to obtain the list of disks that can contain extents for the specified VMFS datastore. The operation does not return disks currently used by the VMFS datastore, nor does it return management LUNs and disks that are referenced by RDMs. RDM disks are not usable for VMFS datastores.
2
QueryVmfsDatastoreCreateOptions – Obtains information about options for creating a new VMFS datastore on a disk. The method returns an array of VmfsDatastoreOption data objects.
QueryVmfsDatastoreExpandOptions – Obtains information about options for expanding the extents of an existing VMFS datastore.
QueryVmfsDatastoreExtendOptions – Obtains information about options for extending an existing VMFS datastore for a disk.
3
If required, change the layout by calling HostStorageSystem.ComputeDiskPartitionInfo and then HostStorageSystem.UpdateDiskPartition to resize the partition.
4
Call CreateVmfsDatastore, ExtendVmfsDatastore, or ExpandVmfsDatastore to complete the VMFS provisioning operation.
Accessing Datastores
Datastore Managed Object illustrates how you can access or specify datastores. See Datacenter Inventory for more information about the hierarchy of managed objects.
Each Datacenter managed object has a datastore property that contains an array of datastores.
Each Datacenter managed object has a datastoreFolder property that is a reference to the folder (or folder hierarchy) that contains the datastores for this datacenter.
Each Datacenter managed object has a hostFolder property that is a reference to the folder (or folder hierarchy) that contains the compute resources, including hosts and clusters, for this datacenter. Each HostSystem or ComputeResource has a datastore property that is an array of Datastore managed objects.
Datastore Managed Object
Creating and Modifying a VMFS Datastore
A datastore is a manageable storage entity, usually used as a repository for virtual machine files including log files, scripts, configuration files, virtual disks, and so on. See Virtual Machine Files.
VMFS is a proprietary file system VMware designed for virtual machines. VMFS is well suited for storing a small number of large data files like virtual disks. These files are mostly used by a single host. VMFS differs from other filesystem formats like FAT16/FAT32 and so on in that it can be accessed by multiple hosts connected to the same SAN LUN.
You can set up a VMFS datastore on any SCSI-based storage device that the host can access. VMFS volume creation, extension, and expansion requires first partitioning operations and the VMFS volume operations.
Setting Up Disk Partitions
Setting up the disk partitions consists of these tasks:
1
Call HostStorageSystem.RetrieveDiskPartitionInfo to retrieve information about existing partitions.
2
Call HostStorageSystem.ComputeDiskPartition, passing in the desired disk layout. The server computes a new partition information object for a specific disk representing the desired layout and returns a HostDiskPartitionInfo object that you can use in the HostDiskPartitionSpec you pass into UpdateDiskPartitions.
3
Call HostStorageSystem.UpdateDiskPartitions to update partitions by passing in a HostDiskPartitionSpec.
Creating the VMFS Datastore
Creating the VMFS datastore consists of these tasks:
1
2
Call HostDatastoreSystem.QueryAvailableDisksForVmfs for information about disks that can be used to contain VMFS datastore.
This method filters out disks that are currently in use by an existing VMFS unless the VMFS using the disk is one being extended. It will also filter out management LUNs and disks that are referenced by RDMs. These disk LUNs are also unsuited for use by a VMFS. The method returns an array of HostScisiDisk objects.
3
Call HostDatastoreSystem.QueryVmfsDatastoreCreateOptions for information about options for for creating a new VMFS datastore. The call returns an array of VmfsDatastoreCreateOption data objects that allow you to access the UUIDs of suitable data stores.
4
(Optional) If no suitable partitions for your VMFS volume exist, you might have to create them. Use the ComputeDiskPartitionInfo and UpdateDiskPartitions methods in HostStorageSystem.
5
Call HostDatastoreSystem.CreateVmfsDatastore to create a VMFS datastore. The method takes a VmfsDatastoreCreateSpec data object that consists of a a partition, a HostVmfsSpec, and an optional extent. The HostVmfsSpec allows you to specify the block size, extent, major version, and volume name for the VMFS.
Call HostDatastoreSystem.CreateNasDatastore to create a network-attached storage based datastore.
You can later expand and extend the VMFS datastore by calling one of the following methods.
Call first QueryVmfsDatastoreExpandOptions and then ExpandVmfsDatastore to expand an existing VMFS datastore using the specification provided in the VmfsDatastoreExpandSpec data object (which contains the name of the extent and partition information). ExpandVmfsDatastore increases the size of the datastore up to the full size provisioned for the datastore, if necessary.
Call first QueryVmfsDatastoreExtendOptions and then ExtendVmfsDatastore to extend an existing VMFS datastore using the specification provided in the VmfsDatastoreExtendSpec data object.
Removing and Updating Datastores
RemoveDatastore – Removes a datastore from a host.
UpdateLocalSwapDatastore – Choose the localSwapDatastore for this host. Any change to this setting affects virtual machines that subsequently power on or resume from a suspended state at this host, or that migrate to this host while powered on. Virtual machines that are currently powered on at this host are not affected.
See the vSphere API Reference for more information about the HostDatastoreSystem operations, including constraints and limitations.
Managing VMFS Datastores with HostStorageSystem
In most cases, the Datastore methods are appropriate for creating and managing VMFS datastores. However, in some cases the following HostStorageSystem commands are used instead:
AttachVmfsExtent – Extends a VMFS by attaching a disk partition as an extent.
ExpandVmfsExtent – Expands a VMFS extent as specified by the disk partition specification.
FormatVmfs – Formats a new VMFS on a disk partition based on the HostVmfsSpec that you pass in. Returns a HostVmfsVolume that represents the new VMFS file system. The HostVmfsVolume includes the block size, list of partition names of the disk’s VMFS extents, and other information including the UUID.
This command is a low-level API you can use to partition disks explicitly. In most cases, the Datastore VMFS commands are more suitable.
RescanVmfs – Rescans for new VMFS instances.
UpgradeVmfs – Upgrades the VMFS to the current VMFS version.
Update and Upgrade
HostStorageSystem.UpdateScsiLunDisplayName – Update the mutable display name associated with a SCSI LUN. The SCSI LUN to be updated is identified using the LUN UUID.
HostStorageSystem.UpgradeVmLayout – Iterates over all registered virtual machines. For each virtual machine, upgrades the layout and logs an event. After the method has been called, the information in the VirtualMachineFileLayout data object data object is correct.