3. Quickstart¶
Eager to get started? This page gives a good introduction on how to get started with managing your dyn services with this module. This assumes you already have the dyn module installed. If you do not, head over to the Installation section for information on installing the package.
First, make sure that dyn is installed
Second, it’s important to understand that this library handles interacting with both your Traffic Management (TM) and Message Management (MM) services. For both TM and MM you will need to create Session objects which handle interacting with the API, processing API responses, and creating the various objects described in the API section.
So, with that in mind, let’s get started with some simple examples.
3.1. Authentication¶
The first step you’ll need to take every time you use either of these libraries, is creating an API Session. These session objects are what, internally, manage interacting with the API.
So, to create a TM DynectSession, we begin by importing the tm.session module:
>>> from dyn.tm.session import DynectSession
Now we simply create an instance of a DynectSession by using our Dynect login credentials:
>>> my_session = DynectSession(customer, username, password)
Now we have a DynectSession object called my_session. We will be
able to use this to access all of the resources that you have access to.
Similarly for MM, we import and create an MMSession from the mm.session
module:
>>> from dyn.mm.session import MMSession
Now we create an instance of that this session by providing it an API Key:
>>> mm_session = MMSession(my_api_key)
This object will now grant us 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
u'blocked'
>>> jsmith.unblock()
>>> jsmith.status
u'active'
>>> jsmith.get_permissions_report()
['ZoneAdd', 'ZoneDelete', 'Login']
>>> jsmith.add_permission('ZoneGet')
>>> jsmith.get_permissions_report()
['ZoneAdd', 'ZoneDelete', 'Login', 'ZoneGet']
We 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 our current session we can create a new zone:
>>> from dyn.tm.zones import Zone
>>> my_zone = Zone('mysite.com', 'myemail@email.com')
We can also access our previously created zones:
>>> my_old_zone = Zone('example.com')
Using these Zone objects we can then perform any manipulations one
might normally perform on a zone. Such as, adding a record:
>>> a_rec = my_zone.add_record('node', 'A', '127.0.0.1')
>>> a_rec.ip
u'127.0.0.1'
>>> a_rec.fqdn
u'node.mysite.com.'
>>> a_rec.get_all_records()
{'a_records': [127.0.0.1], 'aaaa_records': [], ...}
3.4. TM Services¶
Now let’s try adding a DynamicDNS service to our zone:
>>> ddns = my_zone.add_service(service_type='DDNS', record_type='A',
... address='127.0.0.1')
>>> ddns.zone
u'mysite.com'
>>> ddns.active
u'Y'
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 a status of incomplete (ie
the requested job has not yet completed) the wrapper will poll until either the
job has copmleted or the polling times out. In such an unlikely 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 were to pass an invalid argument to one of the provided MM objects, a
DynInvalidArgumentError exception is raised.
The DynInvalidArgumentError should not be confused with
the EmailInvalidArgumentError that is raised if a
required field is not provided. This is an unlikely exception to get raised
because the error would likely first be raised as a
DynInvalidArgumentError. However, it is still a possible
situation.
Finally, the EmailObjectError will be raised if you
attempt to create an object that already exists on the Dyn Email System.
All MM exceptions inherit from EmailError
Ready for more? Check out the API Documentation section, the full TM API Documentation or the MM API Documentation.