The Tiktalik REST API enables developers to perform various operations on the service. Most actions that can be executed using the admin panel can also be perfomed using the REST API. To allow developers to use the API with ease, we created Software Development Kits for various programming languages.
The purpose of this tutorial is to present basic usage patterns of the Tiktalik SDK. We recommend looking at our REST API documentation before reading this tutorial.
Before using the API, you need to obtain an API Key bound to your account. API Keys can be generated in the API Keys section of your admin panel.
Each API Key has a API Secret Key assigned to it. The API Key + API Secret Key pair is used to authorize all REST API requests.
The Tiktalik SDK is currently available for the Python programming language only. Support for other languages is on the way.
You can install the Python SDK using pip:
$ pip install tiktalik
The basic entry point to the REST API is the Connection object. Creating it is very simple, you just need to pass it your API credentials. The Connection object communicates with the Tiktalik Computing API using the secure HTTPS protocol.
from tiktalik.computing import ComputingConnection
conn = ComputingConnection(<API Key>, <API Secret>)
That's it! All core operations are performed using the Connection object. We will assume throughout this tutorial that the connection object already exists.
You can enumerate various collections using the SDK. This includes list of instances, backups etc. All listing functions return collections of API objects, details on which can be found either in SDK-specific documentation, or the REST API documentation.
Example:
# Fetch all instances, including cost per hour
instances = conn.list_instances(cost=True)
# Print some info
for i in instances:
print "Instance", i.hostname, "has", len(i.interfaces), "network interfaces"
# Calculate total cost per hour
total = sum(i.gross_cost_per_hour for i in instances)
Listing your backups is equally simple:
# Fetch all images available to the user
images = conn.list_images()
# We're interested in backups only
backups = [i for i in images if i.type == "backup"]
for b in backups:
print b.uuid, b.create_time
The REST API requires an UUID when performing operations on entities. This applies to Instances also. The SDK is more friendly to the developer, and exposes methods on most API objects.
Let's assume we have a cluster of instances named "node-1", "node-2" etc, that we want to start and stop occasionally. This can be easily achieved using the SDK:
instances = conn.list_instances()
# We only want hostnames that start with "node-"
nodes = [i for i in instances if i.hostname.startswith("node-")]
# Stop the cluster
for node in nodes:
node.stop()
You can also start, stop, force-stop, backup and delete instances in that manner.
Creating new instances can also be performed using the SDK. To create an instance you need to specify:
The VPS Image can be either one of images that Tiktalik Computing provides, or one of your own images (eg. a backup). This allows you to eg. automatically add new webserver nodes from a template image.
# This is the (imaginary) image uuid we want to use. You'd usually
# obtain it using conn.list_images().
image_uuid = "bb3fcb4e-d4fe-4f86-9bae-e0b7b501a934"
hostname = "web-123"
# Size of the instance. 4 maps to "4U"
size = 4
# We want the instance to be available in the public network, as well as all our private networks.
# This means we pass UUIDs of all networks that are available to us
networks = conn.list_networks()
# We need a list of network UUIDs
network_uuids = [n.uuid for n in networks]
# Finally, create the instance
conn.create_instance(hostname, size, image_uuid, network_uuids)
Typically, because networks don't change that often, you'd have a list of network UUIDs prepared upfront, to skip the step or listing them.
There are other actions you can perform using the SDK, like: