Created
February 13, 2012 07:10
-
-
Save grier/1814544 to your computer and use it in GitHub Desktop.
vSphere API - Change VNC settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void doChangeVnc(String url, String username, String password, String vmname, String vncport) throws Exception | |
{ | |
ServiceInstance si = new ServiceInstance(new URL(url), username, password, true); | |
Folder rootFolder = si.getRootFolder(); | |
VirtualMachine vm = null; | |
vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmname); | |
if(vm==null) | |
{ | |
System.out.println("VM not found"); | |
return; | |
} | |
VirtualMachineConfigSpec vms = new VirtualMachineConfigSpec(); | |
OptionValue opt = new OptionValue(); | |
opt.setKey("remotedisplay.vnc.port"); | |
opt.setValue(vncport); | |
OptionValue opt2 = new OptionValue(); | |
opt2.setKey("remotedisplay.vnc.enabled"); | |
opt2.setValue("TRUE"); | |
vms.extraConfig = new OptionValue[] { opt, opt2 }; | |
Task task = vm.reconfigVM_Task(vms); | |
String result = task.waitForMe(); | |
System.out.println("Successfully changed VNC port on " + vmname + " to " + vncport); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment