aeronaut.cloud module

Provides methods and classes to connect and interact with a DiData Cloud Server provider. See connect() for information on how to establish a connection.

aeronaut.cloud.connect(endpoint)[source]

Creates a new connection to a DiData Cloud Server or DiData Cloud Network provider. Multiple calls to connect() can be made to establish connections to multiple providers.

Parameters:endpoint (str) – The endpoint to connect to. For example: api-na.dimensiondata.com
Returns:An authenticated connection to the cloud provider
Return type:CloudConnection

Here is a simple usage example:

from aeronaut.cloud import connect

conn = connect('api-na.dimensiondata.com')
servers = conn.list_servers()

To successfully authenticate against the given endpoint, the function will look for a file in the path ~/.aeronaut with a section name matching the same endpoint. The file must be valid YAML with the following structure:

api-na.dimensiondata.com:
    username: myuser
    password: mypassword

another.endpoint.com:
    username: myotheruser
    password: mypasswordtoo!

Note that this function is really just syntactic sugar that wraps in a single step the act of instantiating a CloudConnection object and calling authenticate() against it. To learn more about the authentication process, see aeronaut.cloud.CloudConnection.authenticate().

Here is a more detailed usage example:

from aeronaut.cloud import connect

conn = connect('api-na.dimensiondata.com')

images = conn.list_base_images()
image = images[0]

networks = conn.list_networks()
network = networks[0]

status = conn.deploy_server(name='My New Server',
                            description='First server deployment',
                            image_id=image.id,
                            start=True,
                            admin_password='32456sdkddd',
                            network_id=network.id)

print status.is_success

All requests such as deploy_server() and list_base_images() are delegated to request classes under the aeronaut.request.cloud package. Whereas the return values are instances of classes under the aeronaut.resource.cloud package. Documentation is currently sparse in both packages so you are required to read the source code to fully understand what the request and resource objects do.

class aeronaut.cloud.CloudConnection(endpoint, api_version='v0.9')[source]

Represents a connection to a DiData Cloud provider

Parameters:
  • endpoint (str) – The endpoint to connect to when authenticate() is called.
  • api_version (str) – Optional. The API version to use. Defaults to v0.9 when not provided. Note that the default may be updated to a later API version in future releases.
add_storage_to_server(server_id, size_gb, disk_speed_id=None, org_id=None)[source]

Creates an additional disk/volume for an existing server

Parameters:
  • server_id (str) – The ID of the server to add storage to.
  • size_gb (int) – The size of the disk in GB.
  • disk_speed_id (str) – Optional. The id of the disk speed to use. This can be obtained via aeronaut.resource.cloud.data_center.DataCenter.hypervisor.disk_speeds(). See the sample usage below for guidance.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Returns:

The status of the operation.

Return type:

aeronaut.resource.cloud.server.AddStorageToServerStatus

Sample usage:

import aeronaut.cloud

conn = aeronaut.cloud.connect('api-na.dimensiondata.com')

filters = [
    ['name', '==', 'myserver01']
]

servers = conn.list_servers(filters=filters)
server = servers[0]

dc = next(dc for dc in conn.list_data_centers() if dc.is_default)
speed = dc.hypervisor.disk_speeds[0]

# The disk_speed_id argument below is optional
result = conn.add_storage_to_server(server_id=server.id,
                                    size_gb=13,
                                    disk_speed_id=speed.id)

print result.is_success
print result.result_detail
authenticate()[source]

Authenticates against the endpoint provided during initialization

To successfully authenticate against the given endpoint, the method will look for a file in the path ~/.aeronaut with a section name matching the same endpoint. The file must be valid YAML with the following structure:

api-na.dimensiondata.com:
    username: myuser
    password: mypassword

another.endpoint.com:
    username: myotheruser
    password: mypasswordtoo!

If the backend server does not return an HTTP status code of 200 or 201, the method will raise aeronaut.cloud.AuthenticationError

clean_failed_server_deployment(server_id, org_id=None)[source]

Removes a failed server deployment from the list of pending deployed servers

Parameters:
  • server_id (str) – The id of the server you wish to remove.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Returns:

The status of the operation

Return type:

aeronaut.resource.cloud.server.CleanFailedServerDeploymentStatus

create_acl_rule(network_id, name, position, action, protocol, type, source_ip=None, source_netmask=None, dest_ip=None, dest_netmask=None, from_port=None, to_port=None, org_id=None)[source]

Creates an ACL Rule

Parameters:
  • network_id (str) – The id of the network where the ACL rule is to be created.
  • name (str) – The name of the ACL rule.
  • position (int) – The position of the ACL rule. Valid range is 100-500 inclusive.
  • action (str) – One of PERMIT or DENY.
  • protocol (str) – One of IP, ICMP, TCP, UDP.
  • type (str) – For inbound rules, provide OUTSIDE_ACL. For outbound rules, provide INSIDE_ACL.
  • source_ip (str) – Optional. IP address of the traffic source.
  • source_netmaks (str) – Optional. Netmask for the source IP.
  • dest_ip (str) – Optional. IP address of the traffic destination.
  • dest_netmask (str) – Optional. for the destination IP.
  • from_port (int) – Optional. Valid range is 1-65535 inclusive
  • to_port (int) – Optional. Valid range is 1-65535 inclusive
  • org_id (str) – Optional. The organization ID that owns the network. Defaults to the current user’s org_id if not provided.
Returns:

The status of the operation

Return type:

aeronaut.resource.cloud.acl.CreateAclRuleStatus

create_network(location, name, org_id=None, description=None)[source]

Creates a network with the given name in the given location

Parameters:
  • location (str) – The data center where the network is to be created.
  • name (str) – The name of the network
  • org_id (str) – Optional. The organization ID that owns the network. Defaults to the current user’s org_id if not provided.
Returns:

The status of the operation

Return type:

aeronaut.resource.cloud.network.CreateNetworkStatus

delete_acl_rule(network_id, rule_id, org_id=None)[source]

Deletes the given rule from the given network

Parameters:
  • network_id (str) – The ID of the network associated with the ACL rule.
  • rule_id (str) – The ID of the ACL rule.
  • org_id (str) – Optional. The organization ID that owns the network. Defaults to the current user’s org_id if not provided.
Returns:

The status of the operation

Return type:

aeronaut.resource.cloud.acl.DeleteAclRuleStatus

delete_server(server_id, org_id=None)[source]

Delete the given server. Note that a Server must be stopped before it can be deleted

Parameters:
  • server_id (str) – The ID of the server to delete.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Returns:

The status of the operation

Return type:

aeronaut.resource.cloud.server.DeleteServerStatus

deploy_server(name, image_id, org_id=None, **kwargs)[source]

Deploys a new server from an existing customer or base image

Parameters:
  • name (str) – Human-friendly name of the server.
  • image_id (str) – ID of the image to use for this server.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided. authenticated user’s account will be used.

Additional arguments are listed in the source code of aeronaut.request.cloud.v0_9.deploy_server.DeployServer

Returns:The status of the operation
Return type:aeronaut.resource.cloud.server.DeployServerStatus

Sample usage:

import aeronaut.cloud

conn = aeronaut.cloud.connect('api-na.dimensiondata.com')

dcs = conn.list_data_centers()
dc = next(dc for dc in dcs if dc.is_default)

images = conn.list_base_images(filters=filters)
image = images[0]

networks = conn.list_networks(location=dc.location)
network = networks[0]

status = conn.deploy_server(name='My new server',
                            description='A new deployment',
                            image_id=image.id,
                            start=True,
                            admin_password='asdfkjhw',
                            network_id=network.id)
print status.is_success

Note how there is no argument for adding disks above. To add one, you need to call add_storage_to_server()

does_image_name_exist(image_name, location, org_id=None)[source]

Returns True if the given image name exists in the data center

Parameters:
  • image_name (str) – The name of the image
  • location (str) – Location where the image is expected to exist. This can be taken from the location property of the DataCenter resource object.
  • org_id (str) – Optional. The organization ID that owns the image. Defaults to the current user’s org_id if not provided.
Returns:

True if the image_name exists. False if otherwise.

Return type:

bool

get_server_image(image_id, org_id=None)[source]

Returns a full description of the indicated server image

Parameters:
  • image_id (str) – The id of the image to retrieve
  • org_id (str) – Optional. The organization ID that owns the image. Defaults to the current user’s org_id if not provided.
Returns:

The image with the given ID

Return type:

aeronaut.resource.cloud.image.Image

list_acl_rules(network_id, org_id=None)[source]

Returns a list of ACL rules

Parameters:
  • network_id (str) – The ID of the network whose ACL rules you want to retrieve.
  • org_id (str) – Optional. The organization ID that owns the network. Defaults to the current user’s org_id if not provided.
Returns:

A list of ACL rules in the given network

Return type:

aeronaut.resource.cloud.acl.AclRuleList

list_base_images(filters=None, page_size=None, page_number=None, sort=None)[source]

Returns a list of base images

Parameters:
  • filters (list) – A list of 3-element lists specifying the filters to apply when retrieving the base images.
  • page_size (int) – The maximum number of items per page
  • page_number (int) – The page number to return
  • sort (list) – A list of strings specifying the order of the list.
Return type:

aeronaut.resource.cloud.image.ImageList

Here is an example usage with the above parameters included:

filters = [
    ["location", "==", "NA5"],
    ["location", "==", "NA3"],
    ["name", "like", "Windows*"]
]

page_size = 5
page_number = 1

sort = [
    "location ASC",
    "name DESC"
]

images = conn.list_base_images(filters=filters,
                               sort=sort,
                               page_size=page_size,
                               page_number=page_number)

print images.page_number, "of", images.total_pages
print images.page_size
print images.total_count
print len(images)
for image in images:
    print image.id, image.name
list_customer_images(org_id=None, filters=None, page_size=None, page_number=None, sort=None)[source]

Returns a list of customer images

Return type:aeronaut.resource.cloud.image.ImageList
list_data_centers(org_id=None, filters=None, page_size=None, page_number=None, sort=None)[source]

Returns a list of data centers

Return type:aeronaut.resource.cloud.data_center.DataCenterList
list_images(base_or_org_id, **kwargs)[source]

Returns a list of base or customer images. While this is available, you are better off calling either list_customer_images() or list_base_images()

Return type:aeronaut.resource.cloud.image.ImageList
list_networks(org_id=None, location=None)[source]

Returns a list of networks

Parameters:
  • org_id (str) – Optional. The organization ID that owns the networks. Defaults to the current user’s org_id if not provided.
  • location (str) – Location where the image is expected to exist. This can be taken from the location property of the DataCenter resource object.
Return type:

aeronaut.resource.cloud.network.NetworkList

list_servers(org_id=None, filters=None, page_size=None, page_number=None, sort=None)[source]

Returns a list of servers

Parameters:org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Return type:aeronaut.resource.cloud.server.ServerList
modify_server(server_id, name=None, description=None, cpu_count=None, memory=None, org_id=None)[source]

Changes the name, description, CPU, or RAM profile of an existing deployed server.

Parameters:
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
  • name (str) – Optional. New name of the server.
  • description (str) – Optional. New description of the server.
  • cpu_count (int) – Optional. New number of virtual CPUs.
  • memory (int) – Optional. New total memory in MB. Value must be a multiple of 1024.
  • server_id (str) – The ID of the server to modify.
Return type:

aeronaut.resource.cloud.server.ModifyServerStatus

poweroff_server(server_id, org_id=None)[source]

Forcefully power off the server

Parameters:
  • server_id (str) – The ID of the server you want to power off.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Return type:

aeronaut.resource.cloud.server.PoweroffServerStatus

reboot_server(server_id, org_id=None)[source]

Gracefully reboot a server

Parameters:
  • server_id (str) – The ID of the server you want to power off.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Return type:

aeronaut.resource.cloud.server.RebootServerStatus

request(req_name, api_version=None, params={}, auth=None)[source]

Sends a request to the provider. This is a low-level method used by all other operations exposed by this class. You do not need to call it directly but it’s here anyway in case you really want to use it.

Parameters:
  • req_name (str) – The name of the request. For a list of available requests, see aeronaut.request.cloud
  • api_version (str) – The API version to use.
  • params (dict) – Parameters to be supplied to the request. This can vary between requests.
  • auth (tuple) – A tuple of two strings, username and password, to use should the server require authentication.

Example:

params = {
    'cpu_count': 2,
    'memory': 2048
}

response = self.request('modify_server',
                        api_version='v0.9',
                        params=params)
print response.status_code

The above call results in the class aeronaut.request.cloud.v0_9.modify_server.ModifyServer being used to send a request to the provider.

  • The version v0_9 is inferred from the api_version argument
  • The class ModifyServer is inferred from the first argument, modify_server
  • What values go into the params argument is determined by whatever the params() method of the request class returns.

Note that this method returns a raw response object, not an object representation of the XML returned by the server.

reset_server(server_id, org_id=None)[source]

Forcefully power cycle the server.

Parameters:
  • server_id (str) – The ID of the server you want to power off.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Return type:

aeronaut.resource.cloud.server.ResetServerStatus

shutdown_server(server_id, org_id=None)[source]

Gracefully stop a server

Parameters:
  • server_id (str) – The ID of the server you want to power off.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Return type:

aeronaut.resource.cloud.server.ShutdownServerStatus

start_server(server_id, org_id=None)[source]

Powers on an existing server

Parameters:
  • server_id (str) – The ID of the server you want to power off.
  • org_id (str) – Optional. The organization ID that owns the server. Defaults to the current user’s org_id if not provided.
Return type:

aeronaut.resource.cloud.server.StartServerStatus

exception aeronaut.cloud.AuthenticationError(response)[source]
exception aeronaut.cloud.NotAuthenticatedError(response)[source]
exception aeronaut.cloud.OperationForbiddenError(status)[source]
exception aeronaut.cloud.UnauthorizedError[source]

Previous topic

Welcome to Aeronaut’s documentation!

Next topic

aeronaut.request.cloud.v0_9 package

This Page