Tutorial

The Tintri Python SDK (PySDK) is a library that provides a Pythonic way to access Tintri APIs.

Installing

Download the PySDK wheel from the Python SDK repository by clicking the Download button. Install the wheel using pip:

pip install tintri-0.1-py2-none-any.whl

Introduction

There are two classes: a common Tintri Class and a v310 class. An example is below:

from tintri.common import TintriServerError
from tintri.v310 import Tintri
from tintri.v310 import VirtualMachineFilterSpec

The common class contains the exceptions, the Tintri Base class, and the Tintri Page class; while the v310 class contains the v310 APIs and Data Transfer Objects (DTOs). When an API uses a DTO, the API documentation links to their definitions.

The PySDK supports both Tintri servers, VMstore and TGC.

Code examples can be found on Tintri’s GitHub site.

Usage

Before any APIs can be called, the Tintri object must be instantiated:

tintri = Tintri(server_name)

Login has not occured yet, but the version and product information can be obtained:

version_info = tintri.version
product_name = version_info.productName
print product_name + " with version: " + version_info.preferredVersion

Tintri server login and logout are straight-forward:

tintri.login(user_name, password)

tintri.logout()

Passwords are protected by using HTTPS.

Exceptions

There are many Tintri exceptions, however it it recommended to use TintriServerError:

try:
    # instantiate the Tintri server.
    tintri = Tintri(server_name)

    # Login to VMstore
    tintri.login(user_name, password)

except TintriServerError as tse:
    print_error(tse.__str__())
    sys.exit(2)

Collecting Server Information

For classes like appliance, datastore, service groups, virtual disk, virtual machine, and vmstore, there are two getters, a single getter and a multiple getter. For the multiple getter, pagination is taken care of by the PySDK in iteration. For example to obtain virtual machine information, there are two APIs methods get_vm() and get_vms(). A unique ID, UUID is required for get_vm(). For get_vms(), a VirtualMachineFilterSpec can be used to filter VMs by name, aliveness, etc. An example that filters by name is below:

vm_filter_spec = VirtualMachineFilterSpec()
vm_filter_spec.name = vm_name

vms = tintri.get_vms(filters = vm_filter_spec)
if vms.filteredTotal == 0:
    print_error("No VMs present")
    tintri.logout()
    sys.exit()

count = 1
print "Total: " + str(vms.filteredTotal)

# Get more VM information until done.
for vm in vms:
    vm_name = vm.vmware.name
    vm_uuid = vm.uuid.uuid
    print(str(count) + ": " + vm_name + ", " + vm_uuid)
    count += 1

For appliance, it is similar: get_appliance() and get_appliances().

Creating Server Information

Creating objects are usually done with create_ methods. For example to create a manual snapshot using create_snapshot(). The snapshot UUID is returned.:

from tintri.v310 import Tintri
from tintri.v310 import SnapshotSpec

def take_snapshot(tintri, vm_uuid, snapshot_name, consistency_type):
    snapshot_spec = SnapshotSpec()
    snapshot_spec.consistency = consistency_type
    snapshot_spec.retentionMinutes = 240  # 4 hours
    snapshot_spec.snapshotName = snapshot_name
    snapshot_spec.sourceVmTintriUUID = vm_uuid

    snapshot_specs = [snapshot_spec]

    snapshot_result = tintri.create_snapshot(snapshot_specs)
    print snapshot_name + ": " + snapshot_result[0]
    return

There is one exception, to clone a VM, use the clone_vm method.

Modifying Server Information

Updating objects are done with update_ methods.

One method using update_appliance() is using named parameters:

# Create the appliance maintenance mode object.
new_maint_mode_info = ApplianceMaintenanceMode()

if (new_is_enabled):
    # Add attributes for enabling.
    new_maint_mode_info.isEnabled =  new_is_enabled
    new_maint_mode_info.endTime =  add_6_str
    new_maint_mode_info.startTime =  now_str
else:
    # Add attributes for disabling.
    new_maint_mode_info.isEnabled =  new_is_enabled

server.update_appliance(None, "default",
                        maintenance_mode = new_maint_mode_info)

Another method is to use MultipleSelectionRequest with update_vms_qos_config():

# Create new QoS object with the fields to be changed
modify_qos_info = VirtualMachineQoSConfig()
modify_qos_info.minNormalizedIops = new_min_qos
modify_qos_info.maxNormalizedIops = new_max_qos

# Create the MultipleSelectionRequest object
MS_Request = MultipleSelectionRequest()
MS_Request.ids = [vm1.get_uuid(), vm2.get_uuid()]
MS_Request.newValue = modify_qos_info
MS_Request.propertyNames = ["minNormalizedIops", "maxNormalizedIops"]

# Update the min and max IOPs using a multiple selection request.
tintri.update_vms_qos_config(request = MS_Request)

Deleting Server Information

Deleting objecs are done the delete_ methods. A unique ID is needed to delete objects.:

snapshot_result = tintri.get_snapshots()
snapshot = snapshot_result[0]
snapshot_uuid = snapshot.uuid.uuid

# Delete the snapshot
tintri.delete_snapshot(snapshot_uuid)

Help

To get more details about API, please examine the API documentation that is available from the Tintri support site. Tintri has a community site for asking questions. On the corporate blog, use the pull down to find blogs on APIs. Also, there is another blog, Tintri API and UI Ramblings for more API information. Comments and questions can be e-mailed to pysdk@tintri.com.