The New-Datastore cmdlet takes by default all the available space.
If you want to specify a specific size, you will have to use the CreateVmfsDatastore method.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can I remove this thread ?
It's a duplicate of the one I moved to the Developer community
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes I am not able to specify the size in createvmfsdatastore method. It is directly taking the size of available vmfs device.
Yes please move to developer community it wil be helpfull. Shall i send the code snippet which we are using?
Thanks,
Sainath
/// Create the HostDatastoreSystem managed object
VimApi::ManagedObjectReference ^imor = gcnew VimApi::ManagedObjectReference();
imor->type = "HostDatastoreSystem";
imor->Value = HostDatastoreSystemKey;
/// Query for VmfsDatastoreCreateOptions
VimApi::VimService ^pVim = pVmwSession->getVimService();
array<String^>^ sHostVersionParts = HostVersion->Split('.');
if (nullptr != pVim && nullptr != sDatastoreName)
{
if(sHostVersionParts->Length > 0)
{
if(Convert::ToInt32(sHostVersionParts[0]) == 5 || Convert::ToInt32(sHostVersionParts[0]) == 6)
{
array<VimApi::VmfsDatastoreOption^> ^vmfsDSoptions = gcnew array<VimApi::VmfsDatastoreOption^>{};
//
// Get the device path of the vdisk assigned to this ESXServer
//
Rawhide::Model::VMW_Helper::GetAvailableDisksForVmfs(pVmwSession, this);
//String^ p_DiskDevicePath = GetDatastorePathLookup(pVDisk->ObjectId);
String^ p_DiskDevicePath ="/vmfs/devices/disks/naa."+pVDisk->GlobalID->ToLower()+"";
String^ spartitionType = "Unknown";
array<HostDiskPartitionInfo^>^ hostpart = nullptr;
if(p_DiskDevicePath != nullptr)
{
//
// this set of code is to allign partition.
//
array<String^>^ deviceInfoList = gcnew array<String^>(1){p_DiskDevicePath};
hostpart = pVim->RetrieveDiskPartitionInfo(m_pHcm->storageSystem,deviceInfoList);
if(hostpart!= nullptr && hostpart->Length > 0)
{
spartitionType = hostpart[0]->layout->partition[0]->type;
}
else
{
LOG_WARN("Unable to find the disk partition for creating Datastore");
}
}
//
// Change the layout partition settings.This is default setting for datastore partititon allign.
//
HostDiskPartitionLayout^ HdiskPartLay = gcnew HostDiskPartitionLayout();
if(hostpart!= nullptr && hostpart->Length > 0)
{
hostpart[0]->layout->partition[0]->partition = 1;
hostpart[0]->layout->partition[0]->partitionSpecified = true;
hostpart[0]->layout->partition[0]->type = "vmfs";
// Setting HostDiskPartitionLayout object.
HdiskPartLay = hostpart[0]->layout;
}
HostDiskPartitionInfo^ HdPartInfo = gcnew HostDiskPartitionInfo();
//
// Getting the best partition calculation like end sector value,start sector value according to vdisk size.
//
if((Convert::ToInt32(sHostVersionParts[0]) == 5 && ESX5VMFSSpecified) || (Convert::ToInt32(sHostVersionParts[0]) == 6 && ESX5VMFSSpecified))
{
HdPartInfo = pVim->ComputeDiskPartitionInfo(m_pHcm->storageSystem,p_DiskDevicePath,HdiskPartLay,"mbr");
}
else if((Convert::ToInt32(sHostVersionParts[0]) == 5 && ESX5VMFSSpecified == false) || (Convert::ToInt32(sHostVersionParts[0]) == 6 && ESX5VMFSSpecified == false))
{
HdPartInfo = pVim->ComputeDiskPartitionInfo(m_pHcm->storageSystem,p_DiskDevicePath,HdiskPartLay,"gpt");
}
else
{
HdPartInfo = pVim->ComputeDiskPartitionInfo(m_pHcm->storageSystem,p_DiskDevicePath,HdiskPartLay,"mbr");
}
/// Only check for partitioning info in case of assign as datastore where we will create datastore
/// Based on user input
if(p_DiskDevicePath)
{
if(nullptr != HdPartInfo->spec->partition)
{
array<String^>^ sHostVersionParts = HostVersion->Split('.');
if(sHostVersionParts->Length > 0)
{
if(ESX5VMFSSpecified)
{
vmfsDSoptions = pVmwSession->getVimService()->QueryVmfsDatastoreCreateOptions(imor,p_DiskDevicePath,3,true);
}
else if(ESX5VMFSSpecified == false)
{
vmfsDSoptions = pVmwSession->getVimService()->QueryVmfsDatastoreCreateOptions(imor,p_DiskDevicePath,5,true);
}
/*else
{
vmfsDSoptions = pVmwSession->getVimService()->QueryVmfsDatastoreCreateOptions(imor,p_DiskDevicePath,3,true);
}*/
}
(((VimApi::HostVmfsSpec^)((((VimApi::VmfsDatastoreCreateSpec^)(((VimApi::VmfsDatastoreSpec^)(vmfsDSoptions[0]->spec)))))->vmfs)))->volumeName = sDatastoreName;
(((VimApi::HostVmfsSpec^)((((VimApi::VmfsDatastoreCreateSpec^)(((VimApi::VmfsDatastoreSpec^)(vmfsDSoptions[0]->spec)))))->vmfs)))->blockSizeMb = iBlockSize;
if(sHostVersionParts->Length > 0)
{
if(ESX5VMFSSpecified)
{
(((VimApi::HostVmfsSpec^)((((VimApi::VmfsDatastoreCreateSpec^)(((VimApi::VmfsDatastoreSpec^)(vmfsDSoptions[0]->spec)))))->vmfs)))->majorVersion = 3;
}
else if(ESX5VMFSSpecified == false)
{
(((VimApi::HostVmfsSpec^)((((VimApi::VmfsDatastoreCreateSpec^)(((VimApi::VmfsDatastoreSpec^)(vmfsDSoptions[0]->spec)))))->vmfs)))->majorVersion = 5;
}
/*else
{
(((VimApi::HostVmfsSpec^)((((VimApi::VmfsDatastoreCreateSpec^)(((VimApi::VmfsDatastoreSpec^)(vmfsDSoptions[0]->spec)))))->vmfs)))->majorVersion = 3;
}*/
}
(((VimApi::HostDiskPartitionSpec^)((((VimApi::VmfsDatastoreCreateSpec^)(((VimApi::VmfsDatastoreSpec^)(vmfsDSoptions[0]->spec)))))->partition)))->partition = HdPartInfo->spec->partition;
//
// Create the datastore
//
ManagedObjectReference ^createDatastore = pVmwSession->getVimService()->CreateVmfsDatastore(imor,(VimApi::VmfsDatastoreCreateSpec^)vmfsDSoptions[0]->spec);
}
}
}
}
}
This is code snippet we are using to createmvfsdatastore.
Thanks,
Sainath
Thread moved to the VMware DeveloperVMware Developer community
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference