mist.client package

Submodules

mist.client.helpers module

class mist.client.helpers.RequestsHandler(mist_uri, data=None, api_token=None, timeout=None)

Bases: object

A wrapper-like class to be used with all the requests being made to mist.io service.

Parameters:
  • mist_uri – The uri to make the requests to.
  • data – Json object with all the params needed by some requests.
  • api_token – If api_token is used, then you do not have to provide username and password.
  • timeout – Optional. If given the request will fail if it lasts longer than the timeout.
Returns:

A RequestsHandler instance.

delete()
get()
post()
put()
response(resp)

For each respone we check if the response status is ok, otherwise raise an error with the the response’s content. :param resp: The response we got after a request. :return: Return the response if response.ok, otherwise raise error with the response.content.

mist.client.helpers.backend_from_id(client, id)
mist.client.helpers.machine_from_id(backend, id)

mist.client.model module

class mist.client.model.Backend(backend, mist_client)

Bases: object

A backend instance.

Parameters:
  • backend – Dict that is returned from the API, with all the available info.
  • mist_client – The MistClient instance that initiated the creation of this Backend instance.
Returns:

A Backend object.

create_machine(name, key, image_id, location_id, size_id, image_extra='', disk='')

Create a new machine on the given backend

Parameters:
  • name – Name of the machine
  • key – Key Object to associate with the machine
  • image_id – Id of image to be used with the creation
  • location_id – Id of the backend’s location to create the machine
  • size_id – If of the size of the machine
  • image_extra – Needed only by Linode backend
  • disk – Needed only by Linode backend
Returns:

An update list of added machines

delete()

Delete the backend from the list of added backends in mist.io service.

Returns:A list of mist.clients’ updated backends.
disable()

Disable the Backend.

Returns:A list of mist.clients’ updated backends.
enable()

Enable the Backend.

Returns:A list of mist.clients’ updated backends.
images

Available images to be used when creating a new machine.

Returns:A list of all available images.
locations

Available locations to be used when creating a new machine.

Returns:A list of available locations.
machine_from_id(machine_id)
machine_from_ip(machine_ip)
machine_from_name(machine_name)
machines

Property-like function to call the _list_machines function in order to populate self._machines dict

Returns:A list of Machine instances.
rename(new_name)

Rename the backend.

Parameters:new_name – New name for the backend to be renamed to.
Returns:A list of mist.clients’ updated backends.
request(*args, **kwargs)

The main purpose of this is to be a wrapper-like function to pass the api_token and all the other params to the requests that are being made

Returns:An instance of RequestsHandler
search_image(search_term)

Search for a specific image by providing a search term (mainly used with ec2’s community and public images)

Parameters:search_term – Search term to be used when searching for images’s names containing this term.
Returns:A list of all images, whose names contain the given search_term.
search_machine(machine_key)

Choose a machine by providing a machine’s id, name or ip

sizes

Available machine sizes to be used when creating a new machine.

Returns:A list of available machine sizes.
update_machines()

Update added machines’ info and re-populate the self._machines dict.

This one is used whenever a new machine is created, rebooted etc etc or whenever you want to update the list of added machines.

Returns:A list of Machine instances.
class mist.client.model.Key(key, mist_client)

Bases: object

A Key instance

Parameters:
  • key – A dict with all the available info for this key
  • mist_client – The MistClient instance that initiated the creation of this Key instance.
Returns:

A Key instance

associate_to_machine(backend_id, machine_id, host=None, ssh_user=None, ssh_port=22)
delete()

Delete this key from mist.io

Returns:An updated list of added keys
private

Return the private ssh-key

Returns:The private ssh-key as string
public

Return the public ssh-key

Returns:The public ssh-key as string
rename(new_name)

Rename a key

Parameters:new_name – New name for the key (will also serve as the key’s id)
Returns:An updated list of added keys
request(*args, **kwargs)

The main purpose of this is to be a wrapper-like function to pass the api_token and all the other params to the requests that are being made

Returns:An instance of RequestsHandler
set_default()

Set this key as the default key

Returns:An updated list of added keys
class mist.client.model.Machine(machine, backend)

Bases: object

A machine instance

Parameters:
  • machine – Dict with all available info for the machine
  • backend – The Backend instance which initiates the new machine
Returns:

A machine instance

add_metric(metric_id)

Add a metric to a monitored machine

Parameters:metric_id – Metric_id (provided by self.available_metrics)
add_python_plugin(name, python_file, value_type='gauge', unit=None)

Add a custom python plugin to the collectd instance of a monitored plugin

Parameters:
  • python_file – Path of the python file to be added as custom python plugin
  • name – Name of the plugin
  • value_type – Optional. Can be either “gauge” or “derive”
  • unit – Optional. If given the new plugin will be measured according to this unit
associate_key(key_id, host=None, ssh_user=None, ssh_port=22)
available_metrics

List all available metrics that you can add to this machine

Returns:A list of dicts, each of which is a metric that you can add to a monitored machine
destroy()

Destroy machine

disable_monitoring()

Disable monitoring

enable_monitoring()

Enable monitoring

get_stats(start=1409762349, stop=1409762359, step=10)

Get stats of a monitored machine

Parameters:
  • start – Time formatted as integer, from when to fetch stats (default now)
  • stop – Time formatted as integer, until when to fetch stats (default +10 seconds)
  • step – Step to fetch stats (default 10 seconds)
Returns:

A dict of stats

probe(key_id=None, ssh_user=None)

If no parameter is provided, mist.io will try to probe the machine with the default :param key_id: Optional. Give if you explicitly want to probe with this key_id :param ssh_user: Optional. Give if you explicitly want a specific user :returns: A list of data received by the probing (e.g. uptime etc)

reboot()

Reboot machine

remove_metric(metric_id)

Remove a metric from a monitored machine

Parameters:metric_id – Metric_id (provided by self.get_stats() )
request(*args, **kwargs)

The main purpose of this is to be a wrapper-like function to pass the api_token and all the other params to the requests that are being made

Returns:An instance of RequestsHandler
start()

Start a stopped machine

stop()

Stop a running machine

Module contents

class mist.client.MistClient(mist_uri='https://mist.io', email=None, password=None)

Bases: object

The base class that initiates a new client that connects with mist.io service.

Initialize the mist.client. In case email and password are given, it will try to authenticate with mist.io and keep the api_token that is returned to be used with the later requests.

Parameters:
  • mist_uri – By default it is ‘https://mist.io‘. Can be changed if there’s a different installation of mist.io
  • email – Email to authenticate with mist.io. May be left ‘None’ if there’s a standalone installation of mist.io that does not require authentication.
  • password – Password to authenticate with mist.io. May be left ‘None’ if there’s a standalone installation of mist.io that does not require authentication.
add_backend(title, provider, key, secret, tenant_name=None, region=None, apiurl=None, machine_ip=None, machine_key=None, machine_user=None, compute_endpoint=None, machine_port=None)

Add a backend (hint: run supported_providers first in order to see all the available options)

Parameters:
  • title – Title of the backend
  • provider – A provider’s name (must be one of the list of supported_providers)
  • key – According to each provider can be a username, a api_key etc.
  • secret – According to each provider can be a simple password, a api_secret etc.
  • tenant_name – Used if needed for OpenStack backends.
  • region – Necessary only if there is a custom Openstack region.
  • apiurl – APIURL needed by Openstack and HP Cloud.
  • machine_ip – Ip address needed when adding Bare Metal Server.
  • machine_key – Id of ssh key needed when adding Bare Metal Server. The key must have been added first.
  • machine_user – User for Bare Metal Server.
  • compute_endpoint – Needed by some OpenStack installations.
  • machine_port – Used when adding a Bare Metal Server
Returns:

Updates self._backends dict.

add_key(key_name, private)

Add a new key to mist.io

Parameters:
  • key_name – Name of the new key (it will be used as the key’s id as well).
  • private – Private ssh-key in string format (see also generate_key() ).
Returns:

An updated list of added keys.

backend_from_id(backend_id)
backend_from_provider(backend_provider)
backend_from_title(backend_title)
backends

Property-like function to call the _list_backends function in order to populate self._backends dict

Returns:A list of Backend instances.
generate_key()

Ask mist.io to randomly generate a private ssh-key to be used with the creation of a new Key

Returns:A string of a randomly generated ssh private key
keys

Property-like function to call the _list_keys function in order to populate self._keys dict

Returns:A list of Key instances
request(*args, **kwargs)

The main purpose of this is to be a wrapper-like function to pass the api_token and all the other params to the requests that are being made

Returns:An instance of mist.client.helpers.RequestsHandler
search_backend(backend_key)

Choose a backend by providing a backend’s id, title or provider

supported_providers

Request a list of all available providers

Returns:A list of all available providers (e.g. {‘provider’: ‘ec2_ap_northeast’, ‘title’: ‘EC2 AP NORTHEAST’})
update_backends()

Update added backends’ info and re-populate the self._backends dict.

This one is used whenever a new backend is added, renamed etc etc or whenever you want to update the list of added backends.

Returns:A list of Backend instances.
update_keys()

Update added keys’ info and re-populate the self._keys dict.

This one is used whenever a new key is added, renamed etc etc or whenever you want to update the list of added keys.

Returns:A list of Key instances.