VMware {code} Community
jeffsong
Contributor
Contributor

How to use SDK API to assign static IP address to VM

Hi All,

Can I use SDK API to assign static IP address to VM when cloning a new VM? I used VI Client to do it but it failed. Therefore, I am wondering if SDK API can do this. Can anyone give me a sample code?

Thank you very much.

Jeff

Reply
0 Kudos
8 Replies
heyitspablo
VMware Employee
VMware Employee

Jeff,

I thought we had some sample code posted on Code Central but now I cant find it,,;( What language were you needing this in.. ?

regards,

Pablo

http://communities.vmware.com/community/developer/codecentral

Keep up with latest info on vSphere PowerCLI http://blogs.vmware.com/vipowershell - Follow me on Twitter @heyitspablo
Reply
0 Kudos
jeffsong
Contributor
Contributor

Hi Pablo,

Thanks for your response. I need java example for assigning IP address to VM and I did not find any sample code yet.

Can you give me a sample code for that?

regards,

Jeff

Reply
0 Kudos
heyitspablo
VMware Employee
VMware Employee

I asked our SDK Dev Support to lend a hand,,, Java it is,, anyone for C# ?

-P

Keep up with latest info on vSphere PowerCLI http://blogs.vmware.com/vipowershell - Follow me on Twitter @heyitspablo
Reply
0 Kudos
jeffsong
Contributor
Contributor

Thank you very much!!!

Jeff

Reply
0 Kudos
navadavuluri
Contributor
Contributor

Hello Jeff,

Please find the attached sample code that our dev team cooked up.

Note:

In this class, look for “deployVMFromTemplate” method. That

method contains “CustomizationIPSettings” object, and we are setting the IP of

that object to DHCP IP. To make it static instead of setting its IP to

“CustomizationDhcpIpGenerator”, the user needs to set it to

“CustomizationFixedIp” which has “ipAddress” as its property.

Thank you,

Nava

http://communities.vmware.com/community/developer/codecentral
Reply
0 Kudos
Gonzalez2011
Contributor
Contributor

Hi,

There's only one field named ipAddress in CustomizationFixedIp, and how to specify netmask and gateway? Thanks.

Reply
0 Kudos
balajiyelmar1
Contributor
Contributor

Hi,

Have you got the exact code to assign static IP?

Thanks,

Reply
0 Kudos
atishbits
Contributor
Contributor

Here's some sample code leveraging vSphere Management SDK for Java to assign static IP to a VM as part of cloning an existing template to create the new VM.

https://blog.profiq.cz/2015/02/24/using-java-to-create-customized-virtual-machine-clones-on-vmware-i...

The code samples from above link are not from me. Besides, ensure that VMware tools are installed in your template (i.e. in the VM you use for template creation). Since assigning an IP to a VM is an operation on the guest OS, you need VMware tools to be able to pass the values to the guest OS.

Reply
0 Kudos