From 61288b14fd0ba996b4d0f228d541fc21517772b0 Mon Sep 17 00:00:00 2001 From: Gaurav Rastogi Date: Wed, 1 Mar 2017 08:16:59 -0800 Subject: [PATCH] =?UTF-8?q?Renamed=20the=20avi=5Fansible=5Futils=20to=20av?= =?UTF-8?q?i.=20Fixed=20the=20import=20error=20and=20clea=E2=80=A6=20(#221?= =?UTF-8?q?12)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Renamed the avi_ansible_utils to avi. Fixed the import error and cleaned up code. * Refactored all new modules to use the new module_utils.avi * Added module_utils.avi to python 2.4 skip list --- .../module_utils/{avi_ansible_utils.py => avi.py} | 6 +++--- .../modules/network/avi/avi_analyticsprofile.py | 12 ++---------- lib/ansible/modules/network/avi/avi_api_session.py | 2 +- .../avi/avi_applicationpersistenceprofile.py | 12 ++---------- .../modules/network/avi/avi_applicationprofile.py | 12 ++---------- .../avi/avi_certificatemanagementprofile.py | 12 ++---------- .../modules/network/avi/avi_healthmonitor.py | 2 +- .../modules/network/avi/avi_networkprofile.py | 12 ++---------- lib/ansible/modules/network/avi/avi_pkiprofile.py | 12 ++---------- lib/ansible/modules/network/avi/avi_pool.py | 2 +- lib/ansible/modules/network/avi/avi_poolgroup.py | 2 +- lib/ansible/modules/network/avi/avi_role.py | 12 ++---------- .../network/avi/avi_sslkeyandcertificate.py | 2 +- lib/ansible/modules/network/avi/avi_sslprofile.py | 12 ++---------- .../modules/network/avi/avi_systemconfiguration.py | 14 +++----------- lib/ansible/modules/network/avi/avi_tenant.py | 12 ++---------- .../modules/network/avi/avi_virtualservice.py | 2 +- test/compile/python2.4-skip.txt | 1 + 18 files changed, 31 insertions(+), 110 deletions(-) rename lib/ansible/module_utils/{avi_ansible_utils.py => avi.py} (95%) diff --git a/lib/ansible/module_utils/avi_ansible_utils.py b/lib/ansible/module_utils/avi.py similarity index 95% rename from lib/ansible/module_utils/avi_ansible_utils.py rename to lib/ansible/module_utils/avi.py index 1bbb3e9c00..4957f4e2be 100644 --- a/lib/ansible/module_utils/avi_ansible_utils.py +++ b/lib/ansible/module_utils/avi.py @@ -29,10 +29,10 @@ # This module initially matched the namespace of network module avi. However, # that causes namespace import error when other modules from avi namespaces -# are imported. In order to avoid the import collisions this was renamed to -# avi_ansible_utils to allow this module to be ceterpiece of all integration -# with external avi modules. +# are imported. Added import of absolute_import to avoid import collisions for +# avi.sdk. +from __future__ import absolute_import import os from pkg_resources import parse_version diff --git a/lib/ansible/modules/network/avi/avi_analyticsprofile.py b/lib/ansible/modules/network/avi/avi_analyticsprofile.py index a65532defd..fb71b9fee0 100644 --- a/lib/ansible/modules/network/avi/avi_analyticsprofile.py +++ b/lib/ansible/modules/network/avi/avi_analyticsprofile.py @@ -389,19 +389,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_api_session.py b/lib/ansible/modules/network/avi/avi_api_session.py index 3024c7eacd..8db0e7303a 100644 --- a/lib/ansible/modules/network/avi/avi_api_session.py +++ b/lib/ansible/modules/network/avi/avi_api_session.py @@ -119,7 +119,7 @@ from ansible.module_utils.basic import AnsibleModule from copy import deepcopy try: - from ansible.module_utils.avi_ansible_utils import ( + from ansible.module_utils.avi import ( avi_common_argument_spec, ansible_return, HAS_AVI) from avi.sdk.avi_api import ApiSession from avi.sdk.utils.ansible_utils import avi_obj_cmp, cleanup_absent_fields diff --git a/lib/ansible/modules/network/avi/avi_applicationpersistenceprofile.py b/lib/ansible/modules/network/avi/avi_applicationpersistenceprofile.py index e892c45107..3a960ab70d 100644 --- a/lib/ansible/modules/network/avi/avi_applicationpersistenceprofile.py +++ b/lib/ansible/modules/network/avi/avi_applicationpersistenceprofile.py @@ -113,19 +113,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_applicationprofile.py b/lib/ansible/modules/network/avi/avi_applicationprofile.py index 9d4d3df8e1..1389c18bee 100644 --- a/lib/ansible/modules/network/avi/avi_applicationprofile.py +++ b/lib/ansible/modules/network/avi/avi_applicationprofile.py @@ -152,19 +152,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_certificatemanagementprofile.py b/lib/ansible/modules/network/avi/avi_certificatemanagementprofile.py index 449fcf19a1..e8df46633a 100644 --- a/lib/ansible/modules/network/avi/avi_certificatemanagementprofile.py +++ b/lib/ansible/modules/network/avi/avi_certificatemanagementprofile.py @@ -83,19 +83,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_healthmonitor.py b/lib/ansible/modules/network/avi/avi_healthmonitor.py index 4327be3a58..ff09985b09 100644 --- a/lib/ansible/modules/network/avi/avi_healthmonitor.py +++ b/lib/ansible/modules/network/avi/avi_healthmonitor.py @@ -135,7 +135,7 @@ obj: from ansible.module_utils.basic import AnsibleModule try: - from ansible.module_utils.avi_ansible_utils import ( + from ansible.module_utils.avi import ( avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_networkprofile.py b/lib/ansible/modules/network/avi/avi_networkprofile.py index 4c40e5bd20..5edceaa294 100644 --- a/lib/ansible/modules/network/avi/avi_networkprofile.py +++ b/lib/ansible/modules/network/avi/avi_networkprofile.py @@ -89,19 +89,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_pkiprofile.py b/lib/ansible/modules/network/avi/avi_pkiprofile.py index 3ef3bec013..7026df886d 100644 --- a/lib/ansible/modules/network/avi/avi_pkiprofile.py +++ b/lib/ansible/modules/network/avi/avi_pkiprofile.py @@ -99,19 +99,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_pool.py b/lib/ansible/modules/network/avi/avi_pool.py index 2116506f9f..e38c4451cf 100644 --- a/lib/ansible/modules/network/avi/avi_pool.py +++ b/lib/ansible/modules/network/avi/avi_pool.py @@ -291,7 +291,7 @@ obj: from ansible.module_utils.basic import AnsibleModule try: - from ansible.module_utils.avi_ansible_utils import ( + from ansible.module_utils.avi import ( avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_poolgroup.py b/lib/ansible/modules/network/avi/avi_poolgroup.py index 48a5b5aa3c..855688aa94 100644 --- a/lib/ansible/modules/network/avi/avi_poolgroup.py +++ b/lib/ansible/modules/network/avi/avi_poolgroup.py @@ -112,7 +112,7 @@ obj: from ansible.module_utils.basic import AnsibleModule try: - from ansible.module_utils.avi_ansible_utils import ( + from ansible.module_utils.avi import ( avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_role.py b/lib/ansible/modules/network/avi/avi_role.py index de56179223..c65e581c79 100644 --- a/lib/ansible/modules/network/avi/avi_role.py +++ b/lib/ansible/modules/network/avi/avi_role.py @@ -79,19 +79,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_sslkeyandcertificate.py b/lib/ansible/modules/network/avi/avi_sslkeyandcertificate.py index 090226c80d..6a311679ec 100644 --- a/lib/ansible/modules/network/avi/avi_sslkeyandcertificate.py +++ b/lib/ansible/modules/network/avi/avi_sslkeyandcertificate.py @@ -130,7 +130,7 @@ obj: from ansible.module_utils.basic import AnsibleModule try: - from ansible.module_utils.avi_ansible_utils import ( + from ansible.module_utils.avi import ( avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_sslprofile.py b/lib/ansible/modules/network/avi/avi_sslprofile.py index dff6db4eda..1ba01dded5 100644 --- a/lib/ansible/modules/network/avi/avi_sslprofile.py +++ b/lib/ansible/modules/network/avi/avi_sslprofile.py @@ -150,19 +150,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_systemconfiguration.py b/lib/ansible/modules/network/avi/avi_systemconfiguration.py index d9e8878655..dfde02fc3b 100644 --- a/lib/ansible/modules/network/avi/avi_systemconfiguration.py +++ b/lib/ansible/modules/network/avi/avi_systemconfiguration.py @@ -106,7 +106,7 @@ extends_documentation_fragment: ''' EXAMPLES = """ -- name: Example Adds/Deletes SystemConfiguration configuration from Avi Controller +- name: Example to create SystemConfiguration object avi_systemconfiguration: controller: 10.10.25.42 username: admin @@ -122,19 +122,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_tenant.py b/lib/ansible/modules/network/avi/avi_tenant.py index 1fa2f7ae51..d5c9cec36e 100644 --- a/lib/ansible/modules/network/avi/avi_tenant.py +++ b/lib/ansible/modules/network/avi/avi_tenant.py @@ -91,19 +91,11 @@ obj: type: dict ''' -from pkg_resources import parse_version from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.avi import avi_common_argument_spec -HAS_AVI = True try: - import avi.sdk - sdk_version = getattr(avi.sdk, '__version__', None) - if ((sdk_version is None) or (sdk_version and - (parse_version(sdk_version) < parse_version('16.3.5.post1')))): - # It allows the __version__ to be '' as that value is used in development builds - raise ImportError - from avi.sdk.utils.ansible_utils import avi_ansible_api + from ansible.module_utils.avi import ( + avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/lib/ansible/modules/network/avi/avi_virtualservice.py b/lib/ansible/modules/network/avi/avi_virtualservice.py index 94b47da84e..f013b1a7c4 100644 --- a/lib/ansible/modules/network/avi/avi_virtualservice.py +++ b/lib/ansible/modules/network/avi/avi_virtualservice.py @@ -355,7 +355,7 @@ obj: from ansible.module_utils.basic import AnsibleModule try: - from ansible.module_utils.avi_ansible_utils import ( + from ansible.module_utils.avi import ( avi_common_argument_spec, HAS_AVI, avi_ansible_api) except ImportError: HAS_AVI = False diff --git a/test/compile/python2.4-skip.txt b/test/compile/python2.4-skip.txt index 7910c72963..753d1ddd7f 100644 --- a/test/compile/python2.4-skip.txt +++ b/test/compile/python2.4-skip.txt @@ -32,6 +32,7 @@ /lib/ansible/modules/web_infrastructure/ansible_tower/ /lib/ansible/module_utils/a10.py /lib/ansible/module_utils/ansible_tower.py +/lib/ansible/module_utils/avi.py /lib/ansible/module_utils/azure_rm_common.py /lib/ansible/module_utils/cloud.py /lib/ansible/module_utils/docker_common.py