Hi Guys,

I need python script to assign 100 IP addresses to VMs present in the same ESX host.
can anyone help me with this.

Recommended Answers

All 11 Replies

I don't know ESX, but in principle, if you can describe precisely how to do it manually, python should be able to do it.

Thanks for the response Gribouillis.

I need to assign IPs to the systems (virtual Machines). from the server (ESX Host). I need to run the script from the server to assign IPs for the systems connected to the server.

It's not exactly what I mean. Suppose you're sitting at a terminal on the server machine. How would you do to assign IPs to three VMs without a script ? If you can do this on your server and describe the procedure in detail, it can then be automatized by a script.

I think this steps will be helpful.

say for example its a windows 2008 R2 server,

  1. login to the system disable DHCP assign IP and Subnetmask mannually (ip should be preferred by me at the time of code execution).

  2. Change the Default gate way in the network adapter settings.

  3. And need to change the system name to the Specific name and change it from WORKGROUP to my domain.(from copmuter properies)

  4. while changing Doamin it required the Username and Password of the domain and it will required a reboot to take effect.

does it make sense..

It makes sense, but you must go one step further: can you execute each of these steps completely on the command line ? Then can you write down everything that you write in your terminal ?

No,I used GUI to change the IP address and Domain for windows virtual machines(windows server 2008 R2,and windows server 2003). so, Currently i need it only for the windows machines. is it possible to automate.

If you want to automate, it will be much easier if you find command line tools to do the same thing. I'm usually not a windows user, but for example I found this by googling: http://www.petri.com/configure_tcp_ip_from_cmd.htm . Could such a tool replace your using the GUI ? Also is there a way to execute a command on the virtual machine from a terminal running on the server ?

Edit: There is a script Click Here for you to try, to see if it changes the parameters the way you do it with the GUI.

Googling about VMs, I fell on pysphere. Does this module apply to your case ?

I got this code from the link you shared.

import wmi

# Obtain network adaptors configurations
nic_configs = wmi.WMI().Win32_NetworkAdapterConfiguration(IPEnabled=True)

# First network adaptor
nic = nic_configs[0]

# IP address, subnetmask and gateway values should be unicode objects
ip = u'192.168.0.11'
subnetmask = u'255.255.255.0'
gateway = u'192.168.0.1'

# Set IP address, subnetmask and default gateway
# Note: EnableStatic() and SetGateways() methods require *lists* of values to be passed
nic.EnableStatic(IPAddress=[ip],SubnetMask=[subnetmask])
nic.SetGateways(DefaultIPGateway=[gateway])

its looks like i am supposed to login to each system and run this code to change the IPs right? but i am looking for the code which i can use it on ESX server for assigning IPS for the number of same Guest os VMs.

I am not aware of this pysphere. but its seems like quiet interesting i think we can log in and change the files of the vms through the server. hope it will helpful..

its looks like i am supposed to login to each system and run this code to change the IPs right? but i am looking for the code which i can use it on ESX server for assigning IPS for the number of same Guest os VMs.

It is true, but I think that in your manual procedure, you login to each VM and you change the IP manually by running a GUI in the VM right ? In the same way, an automated script will probably need to run one or more processes on each VM. These processes can be calling python programs or calling commands such as netsh.

Did you succeed in changing IP and subnet mask manually by launching the command netsh with convenient arguments in a VM ?
Or you can try by running a python script in the VM with the
above code (with an arbitrary IP). It would be a starting point, meaning that you can replace your step 1 above by a step without GUI.

In the same way, see if you can do the other steps without a GUI.

It would be great if you test if pysphere apply to your system. Install pysphere and run python code similar to the code in the pysphere getting started page. If it works, it would be a great step because pysphere can launch processes on the virtual machines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.