SpotInst¶
Documentation¶
kingpin.actors.spotinst
¶
The Spotinst package allows you to create, manage and destroy Spotinst ElastiGroups.
https://spotinst.atlassian.net/wiki/display/API/API+Semantics
Environment Variables
SPOTINST_DEBUG: | If set, then every single response body from Spotinst will be printed out in the debug logs for Kingpin. This can include credentials, and can be extremely verbose, so use with caution. |
---|---|
SPOINST_TOKEN: | SpotInst API Token generated at https://console.spotinst.com/#/settings/tokens |
ElastiGroup¶
-
class
kingpin.actors.spotinst.
ElastiGroupSchema
[source] Light validation against the Spotinst ElastiGroup schema.
For full description of the JSON data format, please see: https://spotinst.atlassian.net/wiki/display/API/Create+Group#CreateGroup-JF
This schema handles the following validation cases:
- Only allow a single
SubnetID
for eachavailabilityZone
object. - Disallow
t2|hc1
instance types for thespot
instance section. - Ensure that the
scaling.up
andscaling.down
arrays are eithernull
or contain at least 1 record.
- Only allow a single
-
class
kingpin.actors.spotinst.
ElastiGroup
(*args, **kwargs)[source] Manages an ElastiGroup in Spotinst.
Spotinst ElastiGroups act as smarter EC2 AutoScalingGroups that scale up and down leveraging Amazon Spot instances wherever possible. These ElastiGroups are completely configurable through a JSON Blob.
For a fully functional example JSON config, see
this one
. You can also write your files in YAML if you prefer – Kingpin will handle the conversion.UserData Startup Script
The Spotinst API wants the instances UserData script to be supplied as a Base64-encoded string – which you can do if you wish. However, there is no need, as Kingpin will automatically convert your plain-text script into a Base64 blob for you behind the scenes.
Rolling out Group Changes
We will trigger the “roll group” API if the
roll_on_change
parameter is set toTrue
after any change to an ElastiGroup. It is difficult to know which changes may or may not require a replacement of your existing hosts, so we leave this up to the user to decide on the behavior.Known Limitations
- At this time, this actor only makes changes to ElastiGroups or creates/deletes them. It does not trigger rolling changes, or wait until instances have launched or terminated before returning.
- The Spotinst API does not allow you to change an ElastiGroup scaling ‘unit’ (ie, CPU Count or Instance Count). You can also not change an ElastiGroup’s basic platform (ie, VPC Linux vs Non VPC Linux). We warn about this on each change.
Options
Name: The desired name of the ElastiGroup. Note that this will override whatever value is inside your configuration JSON/YAML blob.
Config: Path to the ElastiGroup configuration blob (JSON or YAML) file. Token-replacement can be used inside of your configuration files allowing environment variables to replace
%VAR%
strings.This file will be checked against a light-schema defined in
ElastiGroupSchema
before any authentication is required. The file will be further validated against the Spotinst API during the DRY run, but this requires authentication.Tokens: A dict of key/value pairs that can be used to swap in variables into a common ElastiGroup template. These are added to (and override) the Environment variables that Kingpin already uses for variables swapping (as described in the Token-replacement section.
Roll_on_change: Whether or not to forcefully roll out changes to the ElastiGroup. If
True
, we will issue a ‘roll call’ to SpotInst and trigger all of the instances to be replaced. Defaults toFalse
.Roll_batch_size: Indicates in percentage the amount of instances should be replaced in each batch. Defaults to
20
.Roll_grace_period: Indicates in seconds the timeout to wait until instance become healthy in the ELB. Defaults to
600
.Wait_on_create: If set to
True
, Kingpin will loop until the ElastiGroup has fully launched – this only applies if the group is being created from scratch. On updates, see thewait_on_roll
setting below. Defaults toFalse
.Wait_on_roll: If set to
True
, Kingpin will loop until the rollout of any changes has completed. This can take a long time, depending on your rollout settings. Defaults toFalse
.Examples
{ "actor": "spotinst.ElastiGroup", "options": { "name": "my-group", "config": "./group_config.json", } }
Dry Mode
Will discover the current state of the ElastiGroup (present, absent), and whether or not the current configuration is different than the desired configuration. Will also validate the desired configuration against the SpostInst API to give you a heads up about any potential failures up front.