public void configureStaticIp3(String vmPath) { this.si = getServiceInstance(); try { // Connect to vCenter Server //ServiceInstance serviceInstance = new ServiceInstance(new URL("https:///sdk"), "", "", true); // Get the root folder of vCenter inventory Folder rootFolder = this.si.getRootFolder(); //VirtualMachine vm = (VirtualMachine) new InventoryNavigator(rootFolder).searchManagedEntity("VirtualMachine", vmPath); VirtualMachine vm = (VirtualMachine) si.getSearchIndex().findByInventoryPath(vmPath); // Create the specification for the new IP settings CustomizationSpec custSpec = new CustomizationSpec(); CustomizationAdapterMapping[] adapterMappings = new CustomizationAdapterMapping[1]; CustomizationAdapterMapping adapterMapping = new CustomizationAdapterMapping(); adapterMapping.setAdapter(new CustomizationIPSettings()); CustomizationFixedIp fixedIp = new CustomizationFixedIp(); fixedIp.setIpAddress("10.11.33.12"); adapterMapping.getAdapter().setIp(fixedIp); adapterMapping.getAdapter().setSubnetMask("255.255.255.0"); adapterMapping.getAdapter().setDnsDomain("example.com"); adapterMapping.getAdapter().setGateway(new String[] { "10.11.33.1" }); adapterMappings[0] = adapterMapping; custSpec.setNicSettingMap(adapterMappings); // Apply the customization specification to the virtual machine VirtualMachineConfigSpec configSpec = new VirtualMachineConfigSpec(); configSpec.setAnnotation("Applying Static IP Settings"); configSpec.setChangeVersion(vm.getConfig().getChangeVersion()); configSpec.setExtraConfig(new OptionValue[] { new OptionValue() }); configSpec.getExtraConfig()[0].setKey("guestinfo.vmware.tools.customization.spec"); configSpec.getExtraConfig()[0].setValue(custSpec); Task task = vm.reconfigVM_Task(configSpec); task.waitForTask(); TaskInfo taskInfo = task.getTaskInfo(); if (taskInfo.getState() == TaskInfoState.success) { System.out.println("Static IP settings applied successfully."); } else if (taskInfo.getState() == TaskInfoState.error) { System.out.println("Failed to apply static IP settings."); System.out.println("Error: " + taskInfo.getError().getLocalizedMessage()); } // Disconnect from vCenter Server this.si.getServerConnection().logout(); } catch (Exception e) { e.printStackTrace(); } }