Added check for avi SDK version as suggested in review. (#21927)
* Added check for avi SDK version as suggested in review. * Fixed documentation based on review. * Renamed module_utils.avi to module_utils.avi_ansible_utils as import of avi.sdk would fail due to name collisions. Moved the code to check for AVI version into the ansible modules. * Updated the module with note about reason for name change.
This commit is contained in:
parent
2f2e792cae
commit
6df5f89763
7 changed files with 37 additions and 28 deletions
|
@ -27,7 +27,26 @@
|
||||||
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from pkg_resources import parse_version
|
||||||
|
|
||||||
|
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
|
||||||
|
except ImportError:
|
||||||
|
HAS_AVI = False
|
||||||
|
|
||||||
|
|
||||||
def avi_common_argument_spec():
|
def avi_common_argument_spec():
|
|
@ -116,11 +116,11 @@ obj:
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.avi import avi_common_argument_spec, ansible_return
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
|
|
||||||
HAS_AVI = True
|
|
||||||
try:
|
try:
|
||||||
|
from ansible.module_utils.avi_ansible_utils import (
|
||||||
|
avi_common_argument_spec, ansible_return, HAS_AVI)
|
||||||
from avi.sdk.avi_api import ApiSession
|
from avi.sdk.avi_api import ApiSession
|
||||||
from avi.sdk.utils.ansible_utils import avi_obj_cmp, cleanup_absent_fields
|
from avi.sdk.utils.ansible_utils import avi_obj_cmp, cleanup_absent_fields
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
|
|
@ -133,12 +133,10 @@ obj:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.avi import avi_common_argument_spec
|
|
||||||
|
|
||||||
|
|
||||||
HAS_AVI = True
|
|
||||||
try:
|
try:
|
||||||
from avi.sdk.utils.ansible_utils import avi_ansible_api
|
from ansible.module_utils.avi_ansible_utils import (
|
||||||
|
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_AVI = False
|
HAS_AVI = False
|
||||||
|
|
||||||
|
@ -170,7 +168,7 @@ def main():
|
||||||
argument_spec=argument_specs, supports_check_mode=True)
|
argument_spec=argument_specs, supports_check_mode=True)
|
||||||
if not HAS_AVI:
|
if not HAS_AVI:
|
||||||
return module.fail_json(msg=(
|
return module.fail_json(msg=(
|
||||||
'Avi python API SDK (avisdk) is not installed. '
|
'Avi python API SDK (avisdk>=16.3.5.post1) is not installed. '
|
||||||
'For more details visit https://github.com/avinetworks/sdk.'))
|
'For more details visit https://github.com/avinetworks/sdk.'))
|
||||||
return avi_ansible_api(module, 'healthmonitor',
|
return avi_ansible_api(module, 'healthmonitor',
|
||||||
set([]))
|
set([]))
|
||||||
|
|
|
@ -289,12 +289,10 @@ obj:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.avi import avi_common_argument_spec
|
|
||||||
|
|
||||||
|
|
||||||
HAS_AVI = True
|
|
||||||
try:
|
try:
|
||||||
from avi.sdk.utils.ansible_utils import avi_ansible_api
|
from ansible.module_utils.avi_ansible_utils import (
|
||||||
|
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_AVI = False
|
HAS_AVI = False
|
||||||
|
|
||||||
|
@ -362,7 +360,7 @@ def main():
|
||||||
argument_spec=argument_specs, supports_check_mode=True)
|
argument_spec=argument_specs, supports_check_mode=True)
|
||||||
if not HAS_AVI:
|
if not HAS_AVI:
|
||||||
return module.fail_json(msg=(
|
return module.fail_json(msg=(
|
||||||
'Avi python API SDK (avisdk) is not installed. '
|
'Avi python API SDK (avisdk>=16.3.5.post1) is not installed. '
|
||||||
'For more details visit https://github.com/avinetworks/sdk.'))
|
'For more details visit https://github.com/avinetworks/sdk.'))
|
||||||
return avi_ansible_api(module, 'pool',
|
return avi_ansible_api(module, 'pool',
|
||||||
set([]))
|
set([]))
|
||||||
|
|
|
@ -93,7 +93,7 @@ extends_documentation_fragment:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
EXAMPLES = """
|
EXAMPLES = """
|
||||||
- name: Example Adds/Deletes PoolGroup configuration from Avi Controller
|
- name: Example to create PoolGroup object
|
||||||
avi_poolgroup:
|
avi_poolgroup:
|
||||||
controller: 10.10.25.42
|
controller: 10.10.25.42
|
||||||
username: admin
|
username: admin
|
||||||
|
@ -110,12 +110,10 @@ obj:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.avi import avi_common_argument_spec
|
|
||||||
|
|
||||||
|
|
||||||
HAS_AVI = True
|
|
||||||
try:
|
try:
|
||||||
from avi.sdk.utils.ansible_utils import avi_ansible_api
|
from ansible.module_utils.avi_ansible_utils import (
|
||||||
|
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_AVI = False
|
HAS_AVI = False
|
||||||
|
|
||||||
|
@ -143,7 +141,7 @@ def main():
|
||||||
argument_spec=argument_specs, supports_check_mode=True)
|
argument_spec=argument_specs, supports_check_mode=True)
|
||||||
if not HAS_AVI:
|
if not HAS_AVI:
|
||||||
return module.fail_json(msg=(
|
return module.fail_json(msg=(
|
||||||
'Avi python API SDK (avisdk) is not installed. '
|
'Avi python API SDK (avisdk>=16.3.5.post1) is not installed. '
|
||||||
'For more details visit https://github.com/avinetworks/sdk.'))
|
'For more details visit https://github.com/avinetworks/sdk.'))
|
||||||
return avi_ansible_api(module, 'poolgroup',
|
return avi_ansible_api(module, 'poolgroup',
|
||||||
set([]))
|
set([]))
|
||||||
|
|
|
@ -128,12 +128,10 @@ obj:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.avi import avi_common_argument_spec
|
|
||||||
|
|
||||||
|
|
||||||
HAS_AVI = True
|
|
||||||
try:
|
try:
|
||||||
from avi.sdk.utils.ansible_utils import avi_ansible_api
|
from ansible.module_utils.avi_ansible_utils import (
|
||||||
|
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_AVI = False
|
HAS_AVI = False
|
||||||
|
|
||||||
|
@ -164,7 +162,7 @@ def main():
|
||||||
argument_spec=argument_specs, supports_check_mode=True)
|
argument_spec=argument_specs, supports_check_mode=True)
|
||||||
if not HAS_AVI:
|
if not HAS_AVI:
|
||||||
return module.fail_json(msg=(
|
return module.fail_json(msg=(
|
||||||
'Avi python API SDK (avisdk) is not installed. '
|
'Avi python API SDK (avisdk>=16.3.5.post1) is not installed. '
|
||||||
'For more details visit https://github.com/avinetworks/sdk.'))
|
'For more details visit https://github.com/avinetworks/sdk.'))
|
||||||
return avi_ansible_api(module, 'sslkeyandcertificate',
|
return avi_ansible_api(module, 'sslkeyandcertificate',
|
||||||
set(['key']))
|
set(['key']))
|
||||||
|
|
|
@ -353,12 +353,10 @@ obj:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.avi import avi_common_argument_spec
|
|
||||||
|
|
||||||
|
|
||||||
HAS_AVI = True
|
|
||||||
try:
|
try:
|
||||||
from avi.sdk.utils.ansible_utils import avi_ansible_api
|
from ansible.module_utils.avi_ansible_utils import (
|
||||||
|
avi_common_argument_spec, HAS_AVI, avi_ansible_api)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
HAS_AVI = False
|
HAS_AVI = False
|
||||||
|
|
||||||
|
@ -445,7 +443,7 @@ def main():
|
||||||
argument_spec=argument_specs, supports_check_mode=True)
|
argument_spec=argument_specs, supports_check_mode=True)
|
||||||
if not HAS_AVI:
|
if not HAS_AVI:
|
||||||
return module.fail_json(msg=(
|
return module.fail_json(msg=(
|
||||||
'Avi python API SDK (avisdk) is not installed. '
|
'Avi python API SDK (avisdk>=16.3.5.post1) is not installed. '
|
||||||
'For more details visit https://github.com/avinetworks/sdk.'))
|
'For more details visit https://github.com/avinetworks/sdk.'))
|
||||||
return avi_ansible_api(module, 'virtualservice',
|
return avi_ansible_api(module, 'virtualservice',
|
||||||
set([]))
|
set([]))
|
||||||
|
|
Loading…
Reference in a new issue