Quantcast
Channel: VMware Communities : All Content - vSphere Management SDK
Viewing all articles
Browse latest Browse all 1860

Help with creating baremetal VM on Storage DRS Cluster (vSphere SDK)

$
0
0

Hello,

 

I would appreciate any help from anyone who has successfully built a baremetal VM on a Storage DRS Cluster in the vSphere SDK.  I am using c#.

I can clone vm's fine on the Storage DRS cluster, but when I am creating a baremetal VM, I am having issues with the ConfigSpec and the PodSelectionSpec.  Specifically, what do I put for the Datastore and fileName properties of the VirtualDiskFlatVer2BackingInfo properties.  I get an error that I have an incorrect parameter in the ConfigSpec and PodSelectionSpec.  Here is some code to create the PodSelectionSpec:

StorageDrsPodSelectionSpec podSelectionSpec = newStorageDrsPodSelectionSpec();

podSelectionSpec.StoragePod = vmOBJ.DataStore.Item2;

StoragePlacementSpec podPlacement = newStoragePlacementSpec();

podPlacement.DisallowPrerequisiteMoves = true;

podPlacement.Folder = vmOBJ.Folder.Item2;

podPlacement.Type = "create";

podPlacement.ConfigSpec = (VirtualMachineConfigSpec)Session["ConfigSpec"];

podPlacement.ResourcePool = vmOBJ.ResourcePool.Item2;

podPlacement.Host = hostMoref;

  

VmPodConfigForPlacement vmPodConfig = newVmPodConfigForPlacement();

vmPodConfig.StoragePod = vmOBJ.DataStore.Item2;

List<PodDiskLocator> podDiskConfig = newList<PodDiskLocator>();

VirtualMachineConfigSpec tempcfgspec = (VirtualMachineConfigSpec)Session["ConfigSpec"];

VirtualDeviceConfigSpec[] tempVDCfg = tempcfgspec.DeviceChange;

foreach (VirtualDeviceConfigSpec vd in tempVDCfg)

{

VirtualDevice VD = vd.Device;

if (VD.DeviceInfo.Label.Equals("Disk"))

{

PodDiskLocator temppodloc = newPodDiskLocator();

temppodloc.DiskId = vd.Device.Key;

VirtualDiskFlatVer2BackingInfo flatBack = newVirtualDiskFlatVer2BackingInfo();

flatBack.ThinProvisioned = true;

flatBack.DiskMode = "persistent";

flatBack.Datastore = null;

flatBack.FileName = "";

temppodloc.DiskBackingInfo = flatBack;

podDiskConfig.Add(temppodloc);

}

}

vmPodConfig.Disk = podDiskConfig.ToArray();

podSelectionSpec.InitialVmConfig = newVmPodConfigForPlacement[]{ vmPodConfig };

podPlacement.PodSelectionSpec = podSelectionSpec;

 

And here is the code to create the backinginfo:

VirtualDiskFlatVer2BackingInfo backInfo = newVirtualDiskFlatVer2BackingInfo();

backInfo.ThinProvisioned = thinProvisioned;

backInfo.DiskMode = "persistent";

backInfo.Datastore = null;

backInfo.FileName = "";

VirtualDisk tempDisk = newVirtualDisk();

tempDisk.Backing = backInfo;

tempDisk.CapacityInKB = size;

tempDisk.ControllerKey = controllerKey;

tempDisk.Key = (1 + i);

tempDisk.UnitNumber = unitNumber;

tempDisk.DeviceInfo = newDescription();

tempDisk.DeviceInfo.Label = "Disk";

tempDisk.DeviceInfo.Summary = "Disk";

VirtualDeviceConfigSpec tempConfigSpec = newVirtualDeviceConfigSpec();

tempConfigSpec.Device = tempDisk;

tempConfigSpec.FileOperation = VirtualDeviceConfigSpecFileOperation.create;

tempConfigSpec.Operation = VirtualDeviceConfigSpecOperation.add;

 

I realize that there is a lot going on but what I can't find the answer to, is how do I let vSphere choose the datastore and what do I need to have in there to create a VM on a Storage DRS Cluster?


Viewing all articles
Browse latest Browse all 1860

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>