Using vSphere Java API in Jython and Other JVM languages

As a by-product, the vSphere Java API makes Jython programming a lot easier. The following is a very simple sample written in Jython to print out the name of the first virtual machine in inventory.

    from java.net import *
    from com.vmware.vim25.mo import *

    si= ServiceInstance(URL(“https://sjin-dev1/sdk”),\
    “root”, “password”, True)
    rootFolder = si.getRootFolder()
    vms = InventoryNavigator(rootFolder) \
    .searchManagedEntities(“VirtualMachine”)
    print “Hello ” + vms[0].getName()
    si.getServerConnection().logout()

As you can see, it really brings in the benefit of VI Java API into Python community at almost no extra cost.

Click here for the presentation for more details including setting up an IDE. For more about what JVM languages you can use with vSphere Java API, check out here.




This entry was posted in vSphere API and tagged , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. Reuben
    Posted April 4, 2014 at 4:54 am | Permalink

    Hi Steve,

    I am writing an Affinity rule code in python to disable DRS for a particular VM. I am using pyVmomi API and am taking help from VI java sample DrsAff.java . I am not able to proceed further. Please share some ideas.

    Thanks,
    Reuben

  2. Posted April 4, 2014 at 3:13 pm | Permalink

    Hi Reuben, what is the issue blocking you?

    Steve

One Trackback

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • NEED HELP?


    My consulting helps clients with virtualization and cloud computing, including VMware infrastructure automation and orchestration, vSphere management APIs, and deep product integration with hypervisors. Current training offerings include vSphere APIs training, vCenter Orchestrator training, and etc. Should you, or someone you know, need these consulting services or training, please feel free to contact me: steve __AT__ doublecloud.org.

    Me: Steve Jin, VMware vExpert who authored the VMware VI and vSphere SDK by Prentice Hall, and created the de factor open source vSphere Java API while working at VMware engineering. Companies like Cisco, EMC, NetApp, HP, Dell, VMware, are among the users of the API and other tools I developed for their products, internal IT orchestration, and test automation.