3. Quickstart

Eager to get started? This guide will help you get started managing your Dyn services using this module.

If you have not already, Install the Dyn module before proceeding further.

It is also important to understand that this library handles interacting with both Traffic Management (TM) and Message Management (MM) services. For both TM and MM, you will need to create Session objects to handle API interactions, processing API responses, and creating the various objects described in the TM and MM API documentation sections.

Here are some simple examples to get you started.

3.1. Authentication

API sessions will need to be created each time you use either of these libraries. These session objects internally manage interaction with the API.

To create a TM DynectSession, begin by importing the tm.session module:

>>> from dyn.tm.session import DynectSession

Now create an instance of a DynectSession by using our Dyn login credentials:

>>> my_session = DynectSession(customer, username, password)

Now you have a DynectSession object called my_session. You will be able to use this to access your available resources.

For MM, you can import and create an MMSession from the mm.session module:

>>> from dyn.mm.session import MMSession

Now create an instance of this session by providing it an API Key:

>>> mm_session = MMSession(my_api_key)

This object will now grant you access to the features provided by the Email API.

3.2. Managing Your TM Accounts

The new wrapper allows you easy access to managing all of the elements within your account, such as new Users objects:

>>> from dyn.tm.accounts import User
>>> jsmith = User('jsmith')
>>> jsmith.status
>>> jsmith.unblock()
>>> jsmith.status
>>> jsmith.get_permissions_report()
['ZoneAdd', 'ZoneDelete', 'Login']
>>> jsmith.add_permission('ZoneGet')
>>> jsmith.get_permissions_report()
['ZoneAdd', 'ZoneDelete', 'Login', 'ZoneGet']

You can also create new PermissionGroups that can later be applied to User objects

>>> from dyn.tm.accounts import PermissionsGroup
>>> sample = PermissionsGroup('Sample', 'Sample permission Group')
>>> sample.add_permissions('DSFAdd')
>>> sample.add_permissions('DSFGet')
>>> sample.add_permissions('DSFDelete')
>>> sample.add_zone('mysite.com')

3.3. Using your Zones

Using your current session you can create a new zone:

>>> from dyn.tm.zones import Zone
>>> my_zone = Zone('mysite.com', 'myemail@email.com')

You can also access your previously created zones:

>>> my_old_zone = Zone('example.com')

Using these Zone objects you can begin to manipulate your zones, such as, adding a record:

>>> a_rec = my_zone.add_record('node', 'A', '')
>>> a_rec.ip
>>> a_rec.fqdn
>>> a_rec.get_all_records()
{'a_records': [], 'aaaa_records': [], ...}

3.4. TM Services

Try adding a DynamicDNS service to your zone:

>>> ddns = my_zone.add_service(service_type='DDNS', record_type='A',
...                            address='')
>>> ddns.zone
>>> ddns.active

3.5. TM Errors and Exceptions

In the event of an authentication problem, dyn.tm will raise a DynectAuthError exception.

In the event an error in an API Creation is encountered, dyn.tm will raise a DynectCreateError exception with additional information about why the POST failed.

In the event an error in an API Update is encountered, dyn.tm will raise a DynectUpdateError exception with additional information about why the PUT failed.

In the event an error in an API Get is encountered, dyn.tm will raise a DynectGetError exception with additional information about why the GET failed.

In the event an error in an API Deletion is encountered, dyn.tm will raise a DynectDeleteError exception with additional information about why the DELETE failed.

In the event an error in an API request returns with an incomplete status (i.e. the requested job has not yet completed) the wrapper will poll until either the job has completed or the polling times out. In such an event, dyn.tm will raise a DynectQueryTimeout exception

All exceptions that dyn.tm explicitly raises inherit from dyn.tm.errors.DynectError.

3.6. MM Errors and Exceptions

In the event that an invalid API Key is provided to your MMSession an EmailKeyError exception will be raised.

If you passed an invalid argument to one of the provided MM objects, a DynInvalidArgumentError exception is raised.

The DynInvalidArgumentError should not be confused with the EmailInvalidArgumentError. The latter is raised if a required field is not provided. This is an unlikely exception to be raised as the error would likely be raised as DynInvalidArgumentError. However, it is still a possible scenario.

The EmailObjectError will be raised if you attempt to create an object that already exists on the Dyn MM system.

All MM exceptions inherit from EmailError

Ready for more? Check out the TM and MM module documentation sections, the full TM API Documentation or the MM API Documentation.