vsphere 6.0 release of yavijava the vijava alternative available in maven

Today I am proud to announce that I have released yavijava-6.0.01 This was a huge task for me to complete. While doing it I realized if I wanted to get these done in a timely manor going forward I would need some automated tool to help get the work done. I spent a couple of days and built a tool called yavijava_generator. It is a tool written in Groovy that will parse the HTML docs provided by VMWare and generate the new classes and update old ones with new properties speeding up the process to deliver new versions by 100’s of times. This release today includes some bug fixes as well. A security flaw was pointed out to on the vijava forums about vijava changing the global security context when you passed the ignoreInvalidSSL flag. I have addressed that in this release. I have also included a massive amount of logging. If you want to see ALL the SOAP payloads being sent to the server, and the payloads the server is sending you all you have to do is enable trace level logging on com.vmware Please be aware this WILL INCLUDE PASSWORDS in plain text in your log files. I have also made a lot of progress in testing coverage. Please upgrade to this version and et me know if you run into any problems.

yavijava 6.0 beta release ready for vsphere 6.0

I’ve been hard at work adding support for vSphere 6.0 to yavijava, the vijava fork. Im happy to announce that I am done and ready for a beta release. I am not going to push this to public maven right now. For those of you who want to test this release out please download the release from GitHub. Next follow these simple instructions to build a jar.

  • Unzip the 6.0.01b1.zip file
  • Enter the yavijava-6.0.01b1 folder
  • On Linux or Mac use ./gradlew build
  • On Windows use gradlew.bat build

A jar file will be built for you and it will be located in the build/libs directory.

If you run into any issues please please please report them to me so I can get them fixed. Simply go to https://github.com/yavijava/yavijava/issues and open a new issue.
Enjoy!

How to Fix SSL issues with pyvmomi and python 2.7.9

As many of you may or may not know there were some significant changes with regards to SSL in python 2.7.9 which introduce a default verify ssl cert where in the past it was ignored. This creates one hell of a problem when using pyVmomi because 99% of us use the default self signed certs created during the install process of our vCenters or ESXi systems. This problem has been reported a few times now. I answered the question on the mailing list of how to work around the problem, but figured I would add it here as well because there is so much confusion over how to work around the problem until we are able to get upstream pyVmomi patched up.

To work around this issue:

import requests
requests.packages.urllib3.disable_warnings()

import ssl

try:
    _create_unverified_https_context = ssl._create_unverified_context
except AttributeError:
    # Legacy Python that doesn't verify HTTPS certificates by default
    pass
else:
    # Handle target environment that doesn't support HTTPS verification
    ssl._create_default_https_context = _create_unverified_https_context

Add this to your scripts or tools that need to connect. This will make your scripts continue to work like they did on 2.7.8 and older where the default was to ignore the cert and not check it. I hope to see a fix added to upstream pyVmomi soon.

vijava not working with vSphere 6? Try YAVIJAVA instead!

If you are using vijava 5.x stable or beta release and you are ready to move on to vSphere 6 then find your InventoryNavigator is giving you problems and your code isnt working as expected anymore give yavijava a try. I fixed an issue with the InventoryNavigator class that is part of 5.5.10-DEVELOPMENT and newer releases of YAVIJAVA. Since 6.0 went GA today I will be pushing 5.5.10 to public maven this weekend.

Im currently working on adding all the new ManagedObjects and DataObjects that are part of 6.0 to YAVIJAVA and should have an official 6.0 release in a couple of weeks. If you want to help out with those efforts or just follow the development feel free to tune into this branch on GitHub where I am pushing all of the vSphere 6 code before it gets merged into the primary release branch.

yavijava now available in maven central

I began working on a fork of VIJAVA several months ago. I have reached a point where I feel it is ready for its first mainstream release. I have now pushed it to central maven. I have been using this in production now for a few months, and I am no longer giving it the beta mark and I am calling it production ready for vSphere 5.5 The versioning I am using is . so the current production release is 5.5.07 where 5.5 is the vSphere version and 07 is the release number. Please use and report any bugs to the Github issue tracker. YAVIJAVA is basically a drop in replacement for VIJAVA with the exception that new dependencies have been added, but this will NOT require a code change to use. One of the biggest benefits this release gains you from using VIJAVA is logging. Logging has been missing from VIJAVA and at times can really make troubleshooting issues nearly impossible. Now there is TONS of logging. Just configure your log4j for com.vmware Another benefit is the ability to use your own custom http clients. I have provided 1 using the Apache Http Commons library as an example, but the original http client is the default.

Using pyvmomi to set metadata on a VirtualMachine in vSphere

Do you need to set some kind of Key, Value info up on a VirtualMachine in vCenter that you can access from the API? I thought with 5.5 and the addition of this that there was going to be some kind of actual Matadata fields added to the vSphere API, but it seems that still hasnt happened, as this is incomplete and missing any way to actually use it. The good news is that since 4.0 there has been a way to add key value pairs to the vm.config.extraConfig. The key has to be a String, and the Value can be an object. I have used this to store all kinds of stuff from Strings to JSON and XML payloads and even base64 encoded files. I wrote a sample for the pyVmomi-community-samples project that uses the vm.config.extraConfig to store some key value pairs. You can get it here until it gets accepted by the project and merged into master.

Thunderhead Bug Release — The Python SDK for VMware vCloud Usage Meter

I ran into an issue the other day when non ascii characters were in the Customer name. I tracked down the issue and put out a bug fix release for that today. You can read more about the bug here. Coming up in the next couple of weeks for version 0.5 will be support for vCloud Director. To update to the latest version of thunderhead simply run:

pip install -U thunderhead

And this will update you from 0.4 to 0.4.1 If you have any questions or need any help please feel free to reach out to me.

Reset vCenter Alarms from red to green using yavijava the vijava fork

I recently added a patch to YAVIJAVA that allows you to reset an alarm status. William Lam has posted in the past about how to hack the perl sdk to add this functionality, so I thought it would be a good idea to add this functionality to YAVIJAVA. I have manually implemented this in Groovy and in python for pyVmomi so adding it to the primary library I use seemed logical. Im still doing a bit more re-work to YAVIJAVA but if you want to use that now you can check out a copy from GitHub and use the gradle build script to build a copy for your self.

Using this new functionality in YAVIJAVA from Groovy (which is how I do it) would look something like this:

ServiceInstance si = new ServiceInstance(new URL(""),"","", true)
Folder rootFolder = si.getRootFolder()
HostSystem hostSystem = rootFolder.getChildEntity()[0].hostFolder.childEntity[0]
AlarmState[] alarmState = hostSystem.triggeredAlarmState
Alarm foo = alarmState[0].alarm as Alarm
AlarmManager am = new AlarmManager(si.getServerConnection(), foo.getMOR())
am.setAlarmStatus(foo, hostSystem, "green")

I havent tested this yet so YMMV. Before I do the next official release of YAVIJAVA I will have tested it out and include a working sample.

Ignore SSL warnings in pyVmomi caused by requests

pyVmomi made a switch to using requests a while back where it used urllib2 in the past. One of the side effects of doing that was that when you connect to a vCenter or ESX/i HostSystem that has a self signed ssl cert (which is the default) you get a warning like:

>>> from pyVim.connect import SmartConnect
>>> si = SmartConnect(host='172.16.214.129', user='administrator@vsphere.local', pwd='password')
/Users/errr/venvs/pyVmomi/lib/python2.7/site-packages/requests/packages/urllib3/connectionpool.py:730: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.org/en/latest/security.html (This warning will only appear once by default.)
  InsecureRequestWarning)

How can you disable that message though? Well thats pretty simple. Let me show you how to do it. Since as I mentioned above pyVmomi now uses requests we can disable this at the top of our script like so:

>>> from pyVim.connect import SmartConnect
>>> import requests
>>> requests.packages.urllib3.disable_warnings()
>>> si = SmartConnect(host='172.16.214.129', user='administrator@vsphere.local', pwd='password')
>>> 

As you can see I imported requests, then I set requests.packages.urllib3.disable_warnings() and that disabled the warning message for my script.

Related post: Fix SSL issues with pyVmomi on Python 2.7.9

Using pyVmomi to set a note on a VirtualMachine

Have you ever noticed the “Notes” section when looking at the VirtualMachine view either from the web client or from the vi client? Its a handy little place to leave various bits of information. I like to use it to put in who built the VirtualMachine and when, and if it had a ticket number that I could tie it to.

vCenter Notes

Right now this VirtualMachine has no note set, and I want to set one using pyVmomi, but how do you do that? Well I made a sample that demonstrates how to do it. Lets walk though how to use this sample. First lets see what the options are:

± |master ✗| → python set_note.py -h
usage: set_note.py [-h] -s HOST [-o PORT] -u USER [-p PASSWORD] -j UUID -m
                   MESSAGE

Standard Arguments for talking to vCenter

optional arguments:
  -h, --help            show this help message and exit
  -s HOST, --host HOST  vSphere service to connect to
  -o PORT, --port PORT  Port to connect on
  -u USER, --user USER  User name to use when connecting to host
  -p PASSWORD, --password PASSWORD
                        Password to use when connecting to host
  -j UUID, --uuid UUID  UUID of the VirtualMachine you want to add a note to.
  -m MESSAGE, --message MESSAGE
                        Message to add to the notes field.

Like the last couple of samples I have covered this one takes the same basic options of Host, User, Password, and Port. This sample adds 2 new options though. The first is the -j or –uuid. What is the UUID though and why do you need it? The UUID is a unique identifier given to the VirtualMachine by the vCenter. This makes it a good choice to use for tracking the asset. If you are unsure of where to get the UUID you can use the vminfo_quick script from my previous post. The next option is the -m or –message. This option set the message that will be added to the Notes section. Lets give it a try and see how it works out.

± |master ✗| → python set_note.py -s 10.12.254.137 -u 'administrator@vsphere.local' -p password -j 421b3c9a-3aef-3662-c476-5b564d045c08 -m "Built by: Michael Rice"
Found: vCloud Director
Done.

Which leaves our vCenter with this:

updated vcenter

If you have any questions about this process please feel free to ask me and Ill try to help. Happy note setting!