KThorlund
Enthusiast
Enthusiast

Set storage policy

Jump to solution

Hi, 

is it possible to set a storage policy on a VM / disks via vRO?

I havent been able to located any workflow, actions or documenation about this..

Can anyone give a hint?

Thanks K

1 Solution

Accepted Solutions
KThorlund
Enthusiast
Enthusiast

Thanks Jonathan,

I have figured it out, thou never came to update the thread. Here is my code / suggestion on how to handle it.

//FTT1 - VM Storage Policy / 06165014-b10d-45e3-9d7d-57f236c2def3

//FTT2 - VM Storage Policy / 4a01fe5e-4407-4c92-aa4c-ccfcd596e911

//vSAN Default Storage Policy / aa6d5a82-1c88-45da-85d3-3d74b91a5bad

var myVcVirtualMachineConfigSpec = new VcVirtualMachineConfigSpec() ;

var myVcVirtualMachineDefinedProfileSpec = new VcVirtualMachineDefinedProfileSpec() ;

myVcVirtualMachineDefinedProfileSpec.profileId = "06165014-b10d-45e3-9d7d-57f236c2def3";

var changeSpec = [];

var deviceChangeSpec = [];

changeSpec.push(myVcVirtualMachineDefinedProfileSpec);

var devices = vm.config.hardware.device; 

for each (controller in devices)

     var is_scsi = controller instanceof VcVirtualBusLogicController || controller instanceof VcVirtualLsiLogicController || controller instanceof VcParaVirtualSCSIController || controller instanceof      VcVirtualLsiLogicSASController; 

     if (!is_scsi)

     { 

         continue; 

     } 

 

     var controller_label = controller.deviceInfo.label; 

     System.log("SCSI controller found: " + controller_label); 

     for each (device in devices)

     { 

          if (device.controllerKey == controller.key)

          { 

               var scsi_id = controller.busNumber + ":" + device.unitNumber; 

               System.log("    device found:  '" + device.deviceInfo.label + "'  'SCSI (" + scsi_id + ")'"); 

               //System.log("device: " + device);

               var myVcVirtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec() ;

               myVcVirtualDeviceConfigSpec.device = device;

               myVcVirtualDeviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;

               myVcVirtualDeviceConfigSpec.profile = changeSpec;

               deviceChangeSpec.push(myVcVirtualDeviceConfigSpec);

         } 

     } 

myVcVirtualMachineConfigSpec.deviceChange = deviceChangeSpec;

vm.reconfigVM_Task(myVcVirtualMachineConfigSpec);

View solution in original post

2 Replies
jonathanvh
Enthusiast
Enthusiast
KThorlund
Enthusiast
Enthusiast

Thanks Jonathan,

I have figured it out, thou never came to update the thread. Here is my code / suggestion on how to handle it.

//FTT1 - VM Storage Policy / 06165014-b10d-45e3-9d7d-57f236c2def3

//FTT2 - VM Storage Policy / 4a01fe5e-4407-4c92-aa4c-ccfcd596e911

//vSAN Default Storage Policy / aa6d5a82-1c88-45da-85d3-3d74b91a5bad

var myVcVirtualMachineConfigSpec = new VcVirtualMachineConfigSpec() ;

var myVcVirtualMachineDefinedProfileSpec = new VcVirtualMachineDefinedProfileSpec() ;

myVcVirtualMachineDefinedProfileSpec.profileId = "06165014-b10d-45e3-9d7d-57f236c2def3";

var changeSpec = [];

var deviceChangeSpec = [];

changeSpec.push(myVcVirtualMachineDefinedProfileSpec);

var devices = vm.config.hardware.device; 

for each (controller in devices)

     var is_scsi = controller instanceof VcVirtualBusLogicController || controller instanceof VcVirtualLsiLogicController || controller instanceof VcParaVirtualSCSIController || controller instanceof      VcVirtualLsiLogicSASController; 

     if (!is_scsi)

     { 

         continue; 

     } 

 

     var controller_label = controller.deviceInfo.label; 

     System.log("SCSI controller found: " + controller_label); 

     for each (device in devices)

     { 

          if (device.controllerKey == controller.key)

          { 

               var scsi_id = controller.busNumber + ":" + device.unitNumber; 

               System.log("    device found:  '" + device.deviceInfo.label + "'  'SCSI (" + scsi_id + ")'"); 

               //System.log("device: " + device);

               var myVcVirtualDeviceConfigSpec = new VcVirtualDeviceConfigSpec() ;

               myVcVirtualDeviceConfigSpec.device = device;

               myVcVirtualDeviceConfigSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;

               myVcVirtualDeviceConfigSpec.profile = changeSpec;

               deviceChangeSpec.push(myVcVirtualDeviceConfigSpec);

         } 

     } 

myVcVirtualMachineConfigSpec.deviceChange = deviceChangeSpec;

vm.reconfigVM_Task(myVcVirtualMachineConfigSpec);

View solution in original post