Giter Site home page Giter Site logo

dyn-python's Introduction

Dyn API Python SDK

Downloads Latest Version Supported Python versions License

This library provides an easily scriptable approach to accessing all of the features provided by your Traffic Management (TM) or Message Management (MM) services.

Requires Python 2.6 or higher, or the "simplejson" package.

For full documentation and examples see the dyn module on Read The Docs.

Installation

To install the dyn SDK, simply:

$ pip install dyn

Documentation

Documentation is available on Read The Docs.

Contribute

  1. Check for open issues or open a new issue to start a discussion around a feature idea or a bug.
  2. For bug reports especially it's encouraged for you to include a code snippet highlighting the bug.
  3. For feature requests it's encouraged for you to include sample code highlighting a use case for the new feature.
  4. Fork the repository on GitHub to start making your changes to the master branch (or branch off of it).
  5. Send a pull request and bug the maintainer until it gets merged and published. :)

dyn-python's People

Contributors

ahma avatar anothrnick avatar apathor avatar bhopps-dyn avatar chrisargyle avatar dbrian56 avatar dyn-tolson avatar ethanlarochelle avatar grantholly avatar intgr avatar marchowes avatar mcanning avatar moogar0880 avatar northover avatar rshortdyn avatar sarahbx avatar siijmdqeaipr avatar steenzout avatar stonetools avatar sunnygleason avatar whisk3y avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dyn-python's Issues

setup.py breaks due to '@' character in the license

From my .pip.log

Downloading from URL https://pypi.python.org/packages/9c/54/8e8a7502a24b51e3f851c6fe9aac0e159b74c1f368cd9604ea1b0ce02775/dyn-1.7.1.tar.gz#md5=695c0858f38efc1d874ea30d30a5fa13 (from https://pypi.python.org/simple/dyn/)
Running setup.py (path:/private/var/folders/rl/6hy9qkbs7ssd4zy88xs7pm_4391my2/T/pycharm-packaging0.tmp/dyn/setup.py) egg_info for package dyn
Traceback (most recent call last):
File "", line 17, in
File "/private/var/folders/rl/6hy9qkbs7ssd4zy88xs7pm_4391my2/T/pycharm-packaging0.tmp/dyn/setup.py", line 9, in
license_file = f.read()
File "/Users/jamwu/Development/virtualenv/envy/bin/../lib/python3.4/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 49: ordinal not in range(128)
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/private/var/folders/rl/6hy9qkbs7ssd4zy88xs7pm_4391my2/T/pycharm-packaging0.tmp/dyn/setup.py", line 9, in

license_file = f.read()

File "/Users/jamwu/Development/virtualenv/envy/bin/../lib/python3.4/encodings/ascii.py", line 26, in decode

return codecs.ascii_decode(input, self.errors)[0]

UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 49: ordinal not in range(128)

Not compatible with python 3.10?

Hi everyone,

every time I try to from dyn.tm.zones import Zone using python 3.10 I get an error that Iterabe is no longer available in collections.

Is the dyn-python api not compatible with python3? Or am I doing it wrong?

Thankful for any help,
Tobias

Constructor for PermissionsGroup called improperly for declaration

Here you can see a call to get_permissions_groups() makes a subsequent call internal to the module that passes group_name and keyword args to PermissionsGroup.init() in a manner incompatible with the declaration:

  File "/Users/eric.brunson/myproject/dyn.py", line 26, in get_data
    for group in get_permissions_groups():
  File "/Users/eric.brunson/src/github.com/dyn-python/dyn/tm/accounts.py", line 95, in get_permissions_groups
    groups.append(PermissionsGroup(None, api=False, **group))
TypeError: __init__() got multiple values for argument 'group_name'

This patch works around it. I initially changed to call signature, but that could break 3rd party code so went with this:

$ git diff
diff --git a/dyn/tm/accounts.py b/dyn/tm/accounts.py
index 64b1772..9c5ab0f 100644
--- a/dyn/tm/accounts.py
+++ b/dyn/tm/accounts.py
@@ -92,7 +92,12 @@ def get_permissions_groups(search=None):
     response = DynectSession.get_session().execute(uri, 'GET', api_args)
     groups = []
     for group in response['data']:
-        groups.append(PermissionsGroup(None, api=False, **group))
+        if 'group_name' in group:
+            group_name = group.pop('group_name')
+        else:
+            group_name = None
+        groups.append(PermissionsGroup(group_name, api=False, **group))
     if search is not None:
         original = groups
         groups = []

Throws Value error when trying to send a simple message v1.6.3

Traceback:

File "/usr/local/lib/python2.7/dist-packages/dyn/mm/message.py", line 22, in send_message
EMail(from_field, to, subject, cc, body, html, replyto, xheaders).send()
File "/usr/local/lib/python2.7/dist-packages/dyn/mm/message.py", line 85, in send
MMSession.get_session().execute(self.uri, 'POST', api_args)
File "/usr/local/lib/python2.7/dist-packages/dyn/core.py", line 313, in execute
self.logger.debug(msg.format(uri, method, clean_args(json.loads(args))))
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Not All Error Response Msgs Have the Key 'ERR_CD'

Stacktrace:

dynect_session = DynectSession(customer, username, password)
File \"/usr/local/lib/python2.7/dist-packages/dyn/core.py\", line 51, in __call__\n    cur_thread: super(_Singleton, cls).__call__(*args, **kwargs)
File \"/usr/local/lib/python2.7/dist-packages/dyn/tm/session.py\", line 57, in __init__
self.authenticate()\n  File \"/usr/local/lib/python2.7/dist-packages/dyn/tm/session.py\", line 176, in authenticate   
response = self.execute('/Session/', 'POST', api_args)
File \"/usr/local/lib/python2.7/dist-packages/dyn/core.py\", line 399, in execute    
return self._handle_response(response, uri, method, raw_args, final)
File \"/usr/local/lib/python2.7/dist-packages/dyn/core.py\", line 313, in _handle_response
retry = self._retry(ret_val['msgs'], final)
File \"/usr/local/lib/python2.7/dist-packages/dyn/core.py\", line 252, in _retry    
throttled = any(throttle_err == err['ERR_CD'] for err in msgs)  
File \"/usr/local/lib/python2.7/dist-packages/dyn/core.py\", line 252, in <genexpr>
throttled = any(throttle_err == err['ERR_CD'] for err in msgs)
KeyError: 'ERR_CD'"

It would seem not all error response messages have the key 'ERR_CD'.

This library no longer works on python 2.7

dyn==1.8.1 with python 2.7

from dyn.tm.zones import *
from dyn.tm.errors import DynectAuthError

   print(DynectSession(
       'organization', 'user','xxxxx'))

Will raise dyn.tm.errors.DynectAuthError

Traceback (most recent call last):
File "libdynect.py", line 379, in
'organization', 'user','xxxxx'))
File "/usr/local/lib/python2.7/site-packages/dyn/core.py", line 51, in call
cur_thread: super(_Singleton, cls).call(*args, **kwargs)
File "/usr/local/lib/python2.7/site-packages/dyn/tm/session.py", line 57, in init
self.authenticate()
File "/usr/local/lib/python2.7/site-packages/dyn/tm/session.py", line 178, in authenticate
raise DynectAuthError('Unable to access the API host')
dyn.tm.errors.DynectAuthError: Unable to access the API host

Crypto error when encoding password: TypeError: Object type <class 'str'> cannot be passed to C code

Hello,

On my Mac development machine, I'm receiving a crypto error encoding the password when I try to create a DynectSession. This works fine on our production Linux boxes.

Here's how I'm creating a DynectSession with customer name, username, and password (all strings),

dynect_session = DynectSession(
        "customer_name",
        "username",
        "password",
    )

Here's the traceback:

  File "env/lib/python3.6/site-packages/dyn/core.py", line 51, in __call__
    cur_thread: super(_Singleton, cls).__call__(*args, **kwargs)
  File "env/lib/python3.6/site-packages/dyn/tm/session.py", line 54, in __init__
    self.password = self.__cipher.encrypt(password)
  File "env/lib/python3.6/site-packages/dyn/encrypt.py", line 63, in encrypt
    return base64.b64encode(iv + cipher.encrypt(raw))
  File "env/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 177, in encrypt
    c_uint8_ptr(plaintext),
  File "env/lib/python3.6/site-packages/Crypto/Util/_raw_api.py", line 134, in c_uint8_ptr
    raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code

Library versions

dyn==1.8.1
cryptography==2.4.2
cffi==1.11.5

toctree contains reference to nonexisting document u'mm/index'

Hello,

while trying to build the documentation I'm getting the following error:

dyn-python/docs/dyn.rst:6: WARNING: toctree contains reference to nonexisting document u'mm/index'

it seems there are some files missing from the repo.

here is the command I'm using:

sphinx-build -W -b html -d {envtmpdir}/docs . {envtmpdir}/html
# envtmpdir you can ignore

the same problem will happen for this file as well: tm/index

cheers!

missing documentation on how to update TD services

Hi

Im trying to update an existing ruleset in one of my TD services.
once I initialize the ruleset using the DSFRuleset class, Im able to add and remove response pools from it

How do I change criteria parameters? I want to move countries from one ruleset to another and to be able to create new rulesets and add them to an existing service

Thanks

Latest version has Syntax Error in core.py on Python 2.6

When I import from dyn.tm.session, I get a syntax error:

Traceback (most recent call last):
  File "dyn-python-test.py", line 1, in <module>
    from dyn.tm.session import DynectSession
  File "/usr/local/lib/python2.6/site-packages/dyn/tm/session.py", line 8, in <module>
    from ..core import SessionEngine
  File "/usr/local/lib/python2.6/site-packages/dyn/core.py", line 23
    return {x: dict_obj[x] for x in dict_obj if dict_obj[x] is not None and
                             ^
SyntaxError: invalid syntax

I am using Python 2.6.5:

$ python --version
Python 2.6.5

and dyn-python-1.1.0

It looks like dict comprehension is a Python 2.7 feature:
https://www.python.org/dev/peps/pep-0274/

However, the documentation says:
"Requires Python 2.6 or higher, or the "simplejson" package."

I suspect that a simple fix would be to change that line to this:

return dict((x, dict_obj[x]) for x in dict_obj if dict_obj[x] is not None and
        not hasattr(dict_obj[x], '__call__'))

However, after doing that it looks like there are other places that are also not Python 2.6 compatible.

So, it might be best to just update the docs to let everyone know that it is not compatible with Python 2.6.

Function change_ip throws error if the zone does not have any A records

If you have a zone that does not actually contain any A records this function will fail.

my_zones = get_all_zones()

oldIP = ['10.1.2.3', '10.1.2.4']
newIP = ['10.1.2.6', '10.1.2.8']

for zone in my_zones:
    if (zone.name != 'problem zone'):
        changedRecords = change_ip(zone, oldIP, newIP, v6=False, publish=True)

The utility fails with this error:

Traceback (most recent call last):
File "C:/Users/blahblah/PycharmProjects/DynReader/DynModifier.py", line 26, in
changedRecords = change_ip(zone, oldIP, newIP, v6=False, publish=True)
File "C:\Users\blahblah\PycharmProjects\DynReader\venv\lib\site-packages\dyn\tm\tools.py", line 30, in change_ip
records = records['aaaa_records'] if v6 else records['a_records']
KeyError: 'a_records'

RTTM/GSLB - Region pool limitations

Need to improve how RegionPoolEntries work, namely having them accept zone, fqdn etc.

Also, _post is unused for RTTM and GSLB. this should be changed, but relies on accurate zone, fqdn setters. Probably a very low priority.

GSLB "get_all_gslb" just repeats parent zone name

When trying to list all GSLBs in a zone, the 'get_all_gslb' function just repeats the parent zone name for N instances of GSLB under the zone.

To reproduce:
my_zone = Zone('mydomain.com') all_gslb = my_zone.get_all_gslb() print(all_gslb)

Will just print
[<GSLB>: mydomain.com., <GSLB>: mydomain.com., <GSLB>: mydomain.com., <GSLB>: mydomain.com., <GSLB>: mydomain.com., <GSLB>: mydomain.com., <GSLB>: mydomain.com., <GSLB>: mydomain.com.]

In dyn/zones.py, offending section removes the returned zone and fqdn:

def get_all_gslb(self): """Retrieve a list of all :class:GSLB services associated with this :class:Zone`

    :return: A :class:`List` of :class:`GSLB` Services
    """
    uri = '/GSLB/{}/'.format(self._name)
    api_args = {'detail': 'Y'}
    response = DynectSession.get_session().execute(uri, 'GET', api_args)
    gslbs = []
    for gslb_svc in response['data']:
        del gslb_svc['zone']
        del gslb_svc['fqdn']
        gslbs.append(GSLB(self._name, self._fqdn, api=False, **gslb_svc))
    return gslbs`

I'll see if I can restructure that to return intended results, but a lot of the functions seem to be copy-pastad and I'd like to fix all of them, too

Publish call for traffic director

Calls to traffic director resources create changesets, but do not actually publish them to put those changes into effect. A call should be added to the top level service to allow all pending changesets to be committed.

Import of DSFRecord fails

The import of DSFRecord fails:

from dyn.tm.services.dsf import DSFRecord, DSFRecordSet, DSFFailoverChain,
DSFResponsePool, DSFRuleset, DSFMonitor, TrafficDirector

I reinstalled module with pip and then from clone.
reinstalled python 2.7 and installed again

still can't import it

DSFNotifier Object Throws Exception when to_json()

Error bumped out when I did notifier.to_json():

In [32]: all_notifiers[0].to_json()
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-32-3f295e19ee74> in <module>
----> 1 all_notifiers[0].to_json()

~/.pyenv/versions/3.6.2/lib/python3.6/site-packages/dyn/tm/services/dsf.py in to_json(self)
   3533         if self._recipients:
   3534             json_blob['recipients'] = [recipient['recipient'] for recipient in
-> 3535                                        self._recipients]
   3536         if self._services:
   3537             json_blob['dsf_services'] = [dsf['service_id'] for dsf in

~/.pyenv/versions/3.6.2/lib/python3.6/site-packages/dyn/tm/services/dsf.py in <listcomp>(.0)
   3532             json_blob['label'] = self._label
   3533         if self._recipients:
-> 3534             json_blob['recipients'] = [recipient['recipient'] for recipient in
   3535                                        self._recipients]
   3536         if self._services:

Turns out it's already a list.

In [52]: x._recipients
Out[52]: ['somebody']

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.