How do I create datastore of specific size say 2.5 TB using Vmware perl API CreateVmfsDatastore ?
I have used following block of code, where i am passing $dataStoreSize as the argument -
my $dataStoreSize = 2.5; # datastore size is set in TB
my $newDatastoreOptions = $ds_view->QueryVmfsDatastoreCreateOptions( devicePath => $hostScsiDisk->devicePath ) ;
my $HostDiskPartitionInfo = $hs_view->ComputeDiskPartitionInfo ( devicePath => $hostScsiDisk->devicePath , layout => @$newDatastoreOptions[0]->info->layout );
my $diskname = @$newDatastoreOptions[0]->spec->vmfs->extent->diskName ;
my $partition = @$newDatastoreOptions[0]->spec->vmfs->extent->partition ;
my $diskUuid = @$newDatastoreOptions[0]->spec->diskUuid ;
my $partitionarr = @$newDatastoreOptions[0]->spec->partition->partition ;
my $hostDiskPartitionSpec = HostDiskPartitionSpec->new(
chs => @$newDatastoreOptions[0]->spec->partition->chs ,
partition => @$newDatastoreOptions[0]->spec->partition->partition,
totalSectors => $dataStoreSize * ???,
partitionFormat => @$newDatastoreOptions[0]->spec->partition->partitionFormat
);
my $hostScsiDiskPartition = new HostScsiDiskPartition( diskName => $diskname, partition => @$newDatastoreOptions[0]->spec->vmfs->extent->partition );
my $hostVmfsSpec = new HostVmfsSpec( blockSizeMb => 1, extent => $hostScsiDiskPartition, majorVersion => @$newDatastoreOptions[0]->spec->vmfs->majorVersion, volumeName => $dataStore);
my $vmfsDatastoreCreateSpec = new VmfsDatastoreCreateSpec( partition => $hostDiskPartitionSpec, vmfs => $hostVmfsSpec , diskUuid => $diskUuid );
$newDatastore = $ds_view->CreateVmfsDatastore( spec => $vmfsDatastoreCreateSpec );
I wanted to know how the totalSectors would be calculated -
totalSectors => $dataStoreSize *??? |
Can we use API call ComputeDiskPartitionInfo, while creating a datastore of specific size?
Instead of trying to calculate all the parameters yourself, you could do this to create a new VMFS Datastore.
# Get HostDatastoreSystem MO to call CreateVMFSDatastore() method
my $hdSystem_mo_ref = $host_view -> configManager -> datastoreSystem;
# Get Managed Object so we can run methods on it
my $hdSystem_view = Vim::get_view (mo_ref => $hdSystem_mo_ref ) ;
my $vmfs_datastore_options = $hdSystem_view -> QueryVmfsDatastoreCreateOptions (
devicePath => $esxLun -> devicePath,
vmfsMajorVersion => 5 );
my $vmfs_spec = @$vmfs_datastore_options[0] -> spec;
# Here you can modify $vmfs_spec to what you need, such as the volume name:
$vmfs_spec->{vmfs}->{volumeName} = $lun->lun();
# Create the Datastore!
my $datastore = $hdSystem_view -> CreateVmfsDatastore( spec => $vmfs_spec );
Documentation for this is described here: Online Documentation - vSphere Management SDK 5.5 - VMware Developer Center