Yesterday, I built out a small ViPR instance in my home lab using Virtual Isilon to start messing with the APIs. I wasn't really planning on showing this particular API because I'm wanting to play with a different set of APIs, but I figured I would take the time and show a ruby example of using the ViPR REST API. REST is awesome. Flat out. I spent part of yesterday trying to decipher the vSphere APIs with Rbvmomi and got completely lost. REST is BEST.
This ruby script is pretty simple. We are going to use the rest-client and JSON gems to fetch some information and parse it. The script will log in, spit out information about every vCenter instance, display host information for each vCenter instance, and display ViPR Service Statistics. I don't have anything configured just yet for storage, but the ViPR REST API is incredibly easy to use.
Here is the code:
Here is your expected console output:
Logging into ViPR...Success! Gathering vCenter & Host Information... vCenter name is KCvCenter. KCvCenter version is 5.5.0. KCvCenter is REGISTERED. KCvCenter GUID is 81864A84-BD63-4368-A4B3-9E3BAE476481 KCvCenter has 2 hosts: esxi01.kendrickcoleman.c0m esxi02.kendrickcoleman.c0m esxi01.kendrickcoleman.c0m has the following configured interfaces: 192.168.100.11 fe80::250:56ff:fe61:9424 192.168.20.11 fe80::250:56ff:fe69:3661 fe80::20c:29ff:febb:eb47 fe80::250:56ff:fe64:d5a8 192.168.30.11 192.168.40.11 192.168.40.111 fe80::250:56ff:fe6a:2712 esxi02.kendrickcoleman.c0m has the following configured interfaces: 192.168.40.112 192.168.20.12 192.168.30.12 192.168.100.12 192.168.40.12 Gathering ViPR Service Statistics... Service: authsvc Descriptor ID: 162 Status: ACTIVE Uptime: 18:48:48 Active Threads: 43 Process ID: 5576 Service: apisvc Descriptor ID: 206 Status: ACTIVE Uptime: 18:48:48 Active Threads: 46 Process ID: 5581 Service: controllersvc Descriptor ID: 205 Status: ACTIVE Uptime: 18:48:48 Active Threads: 69 Process ID: 5589 Service: geodbsvc Descriptor ID: 245 Status: ACTIVE Uptime: 18:48:49 Active Threads: 126 Process ID: 5560 Service: coordinatorsvc Descriptor ID: 139 Status: ACTIVE Uptime: 18:48:49 Active Threads: 36 Process ID: 5555 Service: objcontrolsvc Descriptor ID: 208 Status: ACTIVE Uptime: 18:48:48 Active Threads: 42 Process ID: 5594 Service: syssvc Descriptor ID: 209 Status: ACTIVE Uptime: 18:48:48 Active Threads: 118 Process ID: 5592 Service: dbsvc Descriptor ID: 259 Status: ACTIVE Uptime: 18:48:49 Active Threads: 139 Process ID: 5558 Service: fabricctrlsvc Descriptor ID: 195 Status: ACTIVE Uptime: 18:48:48 Active Threads: 38 Process ID: 5600 Service: sasvc Descriptor ID: 220 Status: ACTIVE Uptime: 18:48:48 Active Threads: 55 Process ID: 5607 Service: geosvc Descriptor ID: 205 Status: ACTIVE Uptime: 18:48:48 Active Threads: 39 Process ID: 5583 Service: vasasvc Descriptor ID: 113 Status: ACTIVE Uptime: 18:48:48 Active Threads: 28 Process ID: 5602 Service: portalsvc Descriptor ID: 340 Status: ACTIVE Uptime: 18:48:47 Active Threads: 170 Process ID: 5742