Skip to content

Commit

Permalink
Merge pull request #65 from CenturyLinkCloud/feature/python3
Browse files Browse the repository at this point in the history
Prepare for python3 compatibility
  • Loading branch information
Mark Ramach authored Oct 14, 2016
2 parents dce1744 + 15dd3b3 commit 75c0b5f
Show file tree
Hide file tree
Showing 29 changed files with 84 additions and 115 deletions.
32 changes: 7 additions & 25 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
ansible==2.0.2.0
args==0.1.0
cffi==1.6.0
clc-sdk==2.44
clint==0.5.1
coverage==4.0.3
cryptography==1.3.1
enum34==1.1.4
funcsigs==1.0.2
idna==2.1
ipaddress==1.0.16
Jinja2==2.8
MarkupSafe==0.23
mock==2.0.0
nose==1.3.7
paramiko==2.0.0
pbr==1.9.1
prettytable==0.7.2
pyasn1==0.1.9
PyBuilder==0.10.63
pycparser==2.14
pycrypto==2.6.1
PyYAML==3.11
requests==2.10.0
six==1.10.0
wheel==0.24.0
xmlrunner==1.7.7
future
mock
nose
PyBuilder
requests>=2.7
setuptools
wheel
7 changes: 4 additions & 3 deletions src/main/python/clc_ansible_module/clc_aa_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@

__version__ = '${version}'

from builtins import object
from distutils.version import LooseVersion

try:
Expand All @@ -165,7 +166,7 @@
CLC_FOUND = True


class ClcAntiAffinityPolicy:
class ClcAntiAffinityPolicy(object):

clc = clc_sdk
module = None
Expand Down Expand Up @@ -278,7 +279,7 @@ def _create_policy(self, p):
return self.clc.v2.AntiAffinity.Create(
name=p['name'],
location=p['location'])
except CLCException, ex:
except CLCException as ex:
self.module.fail_json(msg='Failed to create anti affinity policy : {0}. {1}'.format(
p['name'], ex.response_text
))
Expand All @@ -292,7 +293,7 @@ def _delete_policy(self, p):
try:
policy = self.policy_dict[p['name']]
policy.Delete()
except CLCException, ex:
except CLCException as ex:
self.module.fail_json(msg='Failed to delete anti affinity policy : {0}. {1}'.format(
p['name'], ex.response_text
))
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_alert_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@

__version__ = '${version}'

from builtins import object, str
from distutils.version import LooseVersion

try:
Expand All @@ -208,7 +209,7 @@
CLC_FOUND = True


class ClcAlertPolicy:
class ClcAlertPolicy(object):

clc = clc_sdk
module = None
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_blueprint_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@

__version__ = '${version}'

from builtins import object
from distutils.version import LooseVersion

try:
Expand All @@ -129,7 +130,7 @@
CLC_FOUND = True


class ClcBlueprintPackage:
class ClcBlueprintPackage(object):

clc = clc_sdk
module = None
Expand Down
9 changes: 6 additions & 3 deletions src/main/python/clc_ansible_module/clc_firewall_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,11 @@

__version__ = '${version}'

import urlparse
from future import standard_library
standard_library.install_aliases()
import urllib.parse
from time import sleep
from builtins import object, str
from distutils.version import LooseVersion

try:
Expand All @@ -207,7 +210,7 @@
CLC_FOUND = True


class ClcFirewallPolicy:
class ClcFirewallPolicy(object):

clc = None

Expand Down Expand Up @@ -306,7 +309,7 @@ def _get_policy_id_from_response(response):
:return: policy_id: firewall policy id from creation call
"""
url = response.get('links')[0]['href']
path = urlparse.urlparse(url).path
path = urllib.parse.urlparse(url).path
path_list = os.path.split(path)
policy_id = path_list[-1]
return policy_id
Expand Down
5 changes: 3 additions & 2 deletions src/main/python/clc_ansible_module/clc_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@

__version__ = '${version}'

from builtins import object, str
from distutils.version import LooseVersion

try:
Expand Down Expand Up @@ -374,7 +375,7 @@ def _delete_group(self, group_name):
group, parent = self.group_dict.get(group_name)
try:
response = group.Delete()
except CLCException, ex:
except CLCException as ex:
self.module.fail_json(msg='Failed to delete group :{0}. {1}'.format(
group_name, ex.response_text
))
Expand Down Expand Up @@ -435,7 +436,7 @@ def _create_group(self, group, parent, description):
(parent, grandparent) = self.group_dict[parent]
try:
response = parent.Create(name=group, description=description)
except CLCException, ex:
except CLCException as ex:
self.module.fail_json(msg='Failed to create group :{0}. {1}'.format(
group, ex.response_text))
return response
Expand Down
4 changes: 3 additions & 1 deletion src/main/python/clc_ansible_module/clc_group_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@

__version__ = '${version}'

from builtins import object

try:
import requests
except ImportError:
Expand All @@ -200,7 +202,7 @@
REQUESTS_FOUND = True


class ClcGroupFact:
class ClcGroupFact(object):

def __init__(self, module):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_loadbalancer.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
__version__ = '${version}'

from time import sleep
from builtins import object, str
from distutils.version import LooseVersion

try:
Expand All @@ -248,7 +249,7 @@
CLC_FOUND = True


class ClcLoadBalancer:
class ClcLoadBalancer(object):

clc = None

Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_loadbalancer_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@

__version__ = '{version}'

from builtins import object, str
from distutils.version import LooseVersion

try:
Expand All @@ -170,7 +171,7 @@
CLC_FOUND = True


class ClcLoadbalancerFact:
class ClcLoadbalancerFact(object):

def __init__(self, module):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_modify_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,7 @@

__version__ = '${version}'

from builtins import object, str
from distutils.version import LooseVersion

try:
Expand All @@ -382,7 +383,7 @@
CLC_FOUND = True


class ClcModifyServer:
class ClcModifyServer(object):
clc = clc_sdk

def __init__(self, module):
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@

__version__ = '${version}'

from builtins import object
from distutils.version import LooseVersion

try:
Expand All @@ -184,7 +185,7 @@
CLC_FOUND = True


class ClcNetwork:
class ClcNetwork(object):

clc = clc_sdk
module = None
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_network_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@

__version__ = '{version}'

from builtins import object
from distutils.version import LooseVersion

try:
Expand All @@ -139,7 +140,7 @@
CLC_FOUND = True


class ClcNetworkFact:
class ClcNetworkFact(object):

def __init__(self, module):
"""
Expand Down
5 changes: 3 additions & 2 deletions src/main/python/clc_ansible_module/clc_publicip.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@

__version__ = '${version}'

from builtins import object
from distutils.version import LooseVersion

try:
Expand Down Expand Up @@ -272,7 +273,7 @@ def _add_publicip_to_server(self, server, ports_to_expose, source_restrictions=N
result = None
try:
result = server.PublicIPs().Add(ports=ports_to_expose, source_restrictions=source_restrictions)
except CLCException, ex:
except CLCException as ex:
self.module.fail_json(msg='Failed to add public ip to the server : {0}. {1}'.format(
server.id, ex.response_text
))
Expand Down Expand Up @@ -309,7 +310,7 @@ def _remove_publicip_from_server(self, server):
try:
for ip_address in server.PublicIPs().public_ips:
result = ip_address.Delete()
except CLCException, ex:
except CLCException as ex:
self.module.fail_json(msg='Failed to remove public ip from the server : {0}. {1}'.format(
server.id, ex.response_text
))
Expand Down
5 changes: 3 additions & 2 deletions src/main/python/clc_ansible_module/clc_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@
__version__ = '${version}'

from time import sleep
from builtins import object, range, str
from distutils.version import LooseVersion

try:
Expand All @@ -538,7 +539,7 @@
CLC_FOUND = True


class ClcServer:
class ClcServer(object):
clc = clc_sdk

def __init__(self, module):
Expand Down Expand Up @@ -634,7 +635,7 @@ def process_request(self):
group = ClcServer._find_group(module=self.module, datacenter=datacenter, lookup_group=p.get('group'))
servers = group.Servers().Servers()
group = group.data
group['servers'] = map(lambda s: s.id, servers)
group['servers'] = [s.id for s in servers]

self.module.exit_json(
changed=changed,
Expand Down
4 changes: 3 additions & 1 deletion src/main/python/clc_ansible_module/clc_server_fact.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@

__version__ = '${version}'

from builtins import object

try:
import requests
except ImportError:
Expand All @@ -249,7 +251,7 @@
REQUESTS_FOUND = True


class ClcServerFact:
class ClcServerFact(object):

def __init__(self, module):
"""
Expand Down
3 changes: 2 additions & 1 deletion src/main/python/clc_ansible_module/clc_server_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@

__version__ = '${version}'

from builtins import object
from distutils.version import LooseVersion

try:
Expand All @@ -148,7 +149,7 @@
CLC_FOUND = True


class ClcSnapshot:
class ClcSnapshot(object):

clc = clc_sdk
module = None
Expand Down
1 change: 1 addition & 0 deletions src/main/python/clc_inv.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from multiprocessing import Pool
import itertools
import json
from builtins import str
import clc
from clc import CLCException, APIFailedResponse

Expand Down
9 changes: 3 additions & 6 deletions src/unittest/python/test_clc_aa_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,7 @@ def test_set_clc_credentials_w_no_creds(self):

def test_clc_module_not_found(self):
# Setup Mock Import Function
import __builtin__ as builtins
real_import = builtins.__import__
real_import = __import__
def mock_import(name, *args):
if name == 'clc': raise ImportError
return real_import(name, *args)
Expand All @@ -186,8 +185,7 @@ def mock_import(name, *args):

def test_requests_invalid_version(self):
# Setup Mock Import Function
import __builtin__ as builtins
real_import = builtins.__import__
real_import = __import__
def mock_import(name, *args):
if name == 'requests':
args[0]['requests'].__version__ = '2.4.0'
Expand All @@ -202,8 +200,7 @@ def mock_import(name, *args):

def test_requests_module_not_found(self):
# Setup Mock Import Function
import __builtin__ as builtins
real_import = builtins.__import__
real_import = __import__
def mock_import(name, *args):
if name == 'requests':
args[0]['requests'].__version__ = '2.7.0'
Expand Down
Loading

0 comments on commit 75c0b5f

Please sign in to comment.