anonymous
anonymous

Reputation: 21

Can I change the IP address of a virtual machine with vmware package?

I created virtual machine on ESX (on vSphere Client) by vmware package: Look here . but I can not set the IP address from the code.

I tried:

ServiceInstance si = new ServiceInstance(new URL(Url), user, password, true);
  VirtualMachine vm = (VirtualMachine) new InventoryNavigator(si.getRootFolder()).searchManagedEntity("VirtualMachine", "NewVmName");
  System.out.println( vm.getGuest().toolsRunningStatus);
  vm.getGuest().setIpAddress(ipAddress);

But it didn't change. Does anyone know what can be done to update IP Address?

Upvotes: 2

Views: 19273

Answers (2)

YSK
YSK

Reputation: 1614

There are at least two ways to do this.

One way is to use the CustomizeVM_Task command and give it a customization spec that changes the IP. The VM will need to be powered off when you do it, and when you turn it on after customization it will boot, change the IP, and then boot again. See examples here and here.

Another way is to leverage the ProcessManager of the GuestOperationsManager to launch a command which changes the IP (the exact command will depend on the guest OS). This will not require a reboot but note that you will need to provide valid credentials for the guest.

If you're open to using PowerCLI then you can use Invoke-VMScript. See e.g. this example.

Upvotes: 0

WhatsYourIdea
WhatsYourIdea

Reputation: 351

The IP Address of a Virtual Machine is controlled by the Virtual Machine itself. If you do want to set the IP Address of the Virtual Machine, change the network adapter to "Bridged" and set the IP Address in the Virtual Machine itself. Refer to: Setting IP Address on Windows, Linux, and Mac.

Sources: Superuser, OSXDaily

Upvotes: 1

Related Questions