VMware Cloud Community
millesonz
Enthusiast
Enthusiast
Jump to solution

Change VM's video card settings

After upgrading many VMs to the latest hardware version, a few of our VMs experienced an issue where 3D was enabled and auto-detect was set to manual. Some adverse effects were experienced. I am now looking to create a workflow to disable 3D and set auto-detect for our servers. I found the properties "enable3DSupport" and "useAutoDetect" under VirtualDeviceConfigSpec.VirtualDevice.VirtualMachineVideoCard.

I planned to script this into an action and create a workflow to pass it a VM that a user selects.

I fired up Onyx and pulled the following info:

// ------- ReconfigVM_Task -------
var spec = new VcVirtualMachineConfigSpec();
spec.changeVersion = "2013-02-21T16:34:32.130873Z";
spec.deviceChange = System.getModule("com.vmware.onyx").array(VcVirtualDeviceConfigSpec, 1);
spec.deviceChange[0] = new VcVirtualDeviceConfigSpec();
spec.deviceChange[0].operation = VcVirtualDeviceConfigSpecOperation.edit;
spec.deviceChange[0].device = new VcVirtualMachineVideoCard();
spec.deviceChange[0].device.key = 500;
spec.deviceChange[0].device.deviceInfo = new VcDescription();
spec.deviceChange[0].device.deviceInfo.label = "Video card ";
spec.deviceChange[0].device.deviceInfo.summary = "Video card";
spec.deviceChange[0].device.controllerKey = 100;
spec.deviceChange[0].device.unitNumber = 0;
spec.deviceChange[0].device.videoRamSizeInKB = 8192;
spec.deviceChange[0].device.numDisplays = 1;
spec.deviceChange[0].device.useAutoDetect = true;
spec.deviceChange[0].device.enable3DSupport = false;
managedObject.reconfigVM_Task(spec);  // VirtualMachine

I know most of that is not needed but I tried a couple different ways and received the following error:

Cannot convert com.vmware.vim.vi4.VirtualDeviceConfigSpec@1 to com.vmware.vim.vi4.VirtualDeviceConfigSpec[] (Dynamic Script Module name : changeVideoCard3DEnable#9)

Can anyone provide some guidance? It seems like most of the actions and workflows in vCO are geared towards getting information in the environment rather than changing items.

Thanks,

-Zach

-Zach
0 Kudos
1 Solution

Accepted Solutions
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

Morning,

untested but try it this way:

var spec = new VcVirtualMachineConfigSpec();
var myDeviceChange = new Array();
var myVirtualMachineVideoCard = new VcVirtualMachineVideoCard();
var configSpec = new VcVirtualDeviceConfigSpec();
myVirtualMachineVideoCard.useAutoDetect = true;
myVirtualMachineVideoCard.enable3DSupport = false;
configSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
configSpec.device = myVirtualMachineVideoCard;
myDeviceChange.push(configSpec);
spec.deviceChange = myDeviceChange;
vm.reconfigVM_Task(spec);

But it is untetested.

Regards

View solution in original post

0 Kudos
6 Replies
tschoergez
Leadership
Leadership
Jump to solution

Hi Zach!

Try to split up the generation of the deviceChange Array, rather than relying on the onyx action (have a look at the action, quite simple to understand what it’s supposed to do...)

So a

var myDeviceChange = new Array();

var configSpec = new VcVirtualDeviceConfigSpec();

.....

myDeviceChange.push(configSpec);

spec.deviceChange = myDeviceChange;

You can also System.debug()-out the variables in between to make sure that the spec has the proper format...

Cheers,

Joerg

Von: Zach Milleson

Gesendet: Freitag, 22. Februar 2013 22:41

An: Joerg Lew

Betreff: New message: "Change VM's video card settings"

VMware Communities<http://communities.vmware.com/index.jspa>

Change VM's video card settings

created by Zach Milleson<http://communities.vmware.com/people/millesonz> in Orchestrator - View the full discussion<http://communities.vmware.com/message/2200139#2200139

0 Kudos
millesonz
Enthusiast
Enthusiast
Jump to solution

Joerg,

I'm not the greatest with Arrays. The error I received confirms that. ha! Here's what I came up with:

var spec = new VcVirtualMachineConfigSpec();
spec.deviceChange = new Array(VcVirtualDeviceConfigSpec, 1);
var myDeviceChange = new Array();
var configSpec = new VcVirtualDeviceConfigSpec();
configSpec[0].operation = VcVirtualDeviceConfigSpecOperation.edit;
configSpec[0].device = new VcVirtualMachineVideoCard();
configSpec[0].device.useAutoDetect = true;
configSpec[0].device.enable3DSupport = false;
myDeviceChange.push(configSpec);
spec.deviceChange = myDeviceChange;
vm.reconfigVM_Task(spec);

The exception that it spat out is:

Cannot convert org.mozilla.javascript.NativeArray@704646e2 to com.vmware.vim.vi4.VirtualDeviceConfigSpec[] (Dynamic Script Module name : changeVideoCard3DEnable_1_1#13)

Thanks again for your assistance.

-Zach
0 Kudos
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

Morning,

untested but try it this way:

var spec = new VcVirtualMachineConfigSpec();
var myDeviceChange = new Array();
var myVirtualMachineVideoCard = new VcVirtualMachineVideoCard();
var configSpec = new VcVirtualDeviceConfigSpec();
myVirtualMachineVideoCard.useAutoDetect = true;
myVirtualMachineVideoCard.enable3DSupport = false;
configSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
configSpec.device = myVirtualMachineVideoCard;
myDeviceChange.push(configSpec);
spec.deviceChange = myDeviceChange;
vm.reconfigVM_Task(spec);

But it is untetested.

Regards

0 Kudos
millesonz
Enthusiast
Enthusiast
Jump to solution

Christian,

I took your script and put it into a new action and tested it. It completed but within vCenter, it gave me an error saying it was an invalid configuration for device '0'. A co-worker and I began talking and I had mentioned that within Onyx it spat out a whole array of info when all I had changed was a single value. He said that it probably needs all of that information from the array to successfully apply the one setting I need to change. I then took your script and added the rest of the values that were in the array and kicked off the workflow. It completed within vCO and within vCenter with success! I've listed what I've entered into the action below:

var spec = new VcVirtualMachineConfigSpec();
var myDeviceChange = new Array();
var myVirtualMachineVideoCard = new VcVirtualMachineVideoCard();
var configSpec = new VcVirtualDeviceConfigSpec();
myVirtualMachineVideoCard.key = 500;
myVirtualMachineVideoCard.deviceInfo = new VcDescription();
myVirtualMachineVideoCard.deviceInfo.label = "Video card";
myVirtualMachineVideoCard.deviceInfo.summary = "Video card";
myVirtualMachineVideoCard.controllerKey = 100;
myVirtualMachineVideoCard.unitNumber = 0;
myVirtualMachineVideoCard.videoRamSizeInKB = 8192;
myVirtualMachineVideoCard.numDisplays = 1;
myVirtualMachineVideoCard.useAutoDetect = true;
myVirtualMachineVideoCard.enable3DSupport = false;
configSpec.operation = VcVirtualDeviceConfigSpecOperation.edit;
configSpec.device = myVirtualMachineVideoCard;
myDeviceChange.push(configSpec);
spec.deviceChange = myDeviceChange;
vm.reconfigVM_Task(spec);

-Zach
0 Kudos
ChristianWehner
VMware Employee
VMware Employee
Jump to solution

Morning,

nice you get it work. I only saw an error with the array and corrected it the best way I know, as said it was untested and I also took no look which parameter where required.

Often you will find more detailed information which parameter are required if you take a look to the online documentation (which I found is better to read) or the vSphere API (https://yourvcenterserver.domain.com/mob/)

Regards,

Chris

0 Kudos
tschoergez
Leadership
Leadership
Jump to solution

Christian, Thanks  for chimin' in and providing the solution!

Cheers,

Joerg

0 Kudos