Month: July 2016

Adding VMs to a Service Group


A colleague, Adam  Cavaliere, wrote a Python script that adds VM name from a CSV file to a TGC Service Group. The script, is now on Tintri’s GitHub site.

This script asks for the user name and password interactively instead being on the command line.  The command line only has the TGC server name, the TGC service group to put the names into, and the CSV file name that contains the VM names.

Let’s look at the salient part of the code.

if service_group_exists:
    target_sg_api = "/v310/servicegroup/" + target_sg + "/members/static"
    print("Service Group Found")

payload = {'typeId':'', \
           'objectIdsAdded': uuid_list

# Set the static members.
tt.api_put(server_name, target_sg_api, payload, session_id)

Here we have the API invoke to update the static members of the specified service group with a list of VM UUIDs.  The list of VM UUIDs are added to payload before the api_put() call.

The code below obtains the target_sg for the update service group static members API URL  It performs a GET servicegroup and looks for the specified service group and extracts the service group UUID.

# Get List of Service Groups
api = "/v310/servicegroup"
results = tt.api_get(server_name, api, session_id)
service_groups = results.json()

service_group_exists = False

# setup API for adding VMs to proper Service Group
for item in service_groups["items"]:
    if item["name"] == service_group:
        service_group_exists = True
        target_sg = item["uuid"]["uuid"]

From a list VM names, the VM UUIDs are collected in the get_vm_uuids() function. This function takes as input a list of VM names and returns a list of found VM names and their UUIDs.  The GET vm API is is used.  I have discussed this in previous blogs. The UUID list is used in the payload above.

That pretty much covers it,

– Rick –


Obtain a VM CSV Report


A new Python API example,, has been uploaded to our Tintri GitHub site.  This new script outputs a CSV report file on all the VMs known to the Tintri server.  (A Tintri server is currently a VMstore or TGC.)  The script also takes a CSV input file that controls which columns are returned.

The tintri-api-examples/reports directory includes vm_report_fields.csv, vm_latency_report_fields.csv, and of course  Let’s discuss the CSV files first.

The file vm_report_fields.csv is a template that contains all the fields or columns that can be included in the VM report.  Each line contains the field name and a short description. To customize your report, copy vm_report_fields.csv to a new file and uncomment the field lines in the new file to be included in the report.  An example of this is vm_latency_report_fields.csv.  Upon examination, you’ll see that the following field lines are uncommented: VmName, TotalLatency, NewtorkLatency, StorageLatency, and DiskLatency.

The Python script reads the input CSV for the fields, and places the fields in the DTO. The API is invoked and a URL is returned.  Using the URL, the report is downloaded.  The library was modified to include a file download function.

Until next time,

– Rick –