Skip to content

Commit

Permalink
Updated utils to remove Avi SDK dependency and Avi 18.2.2 version upd…
Browse files Browse the repository at this point in the history
…ate (ansible#54894)

* Updated utils to remove Avi SDK dependency and Avi 18.2.2 version update

* Fixed the python 3.x errors failing for avi_disable_session_cache_as_fact not properly documented

* Updated version added fields for new parameters

* fixed pep8 errors

* made requests import optional

* removed setting requests to None

* Added try catch for the avi helper methods such that any import fails then module fail gracefully. This was needed to pass the requests library not found error

* removed deprecated modules. Also, trying another fix to deal with requests import error

* Fixed python3 errors

* fixed pep8, no-dict-iteritems and import test failures

* added version 2.8 for new field

* some more code cleanup and formatting

* updated the fail message and fixed plint errors

* added workaround for unicode pylint

* fixed the version added for new parameter app_learning_memory_percent and removed unicode_literals import

* Removed check of HAS_AVI for common argument spec

* Updated version added value from 2.8 to 2.9

* Version added value fixes of CI error
  • Loading branch information
chaitanyaavi authored and Qalthos committed May 17, 2019
1 parent 63e33f7 commit b593548
Show file tree
Hide file tree
Showing 72 changed files with 2,906 additions and 980 deletions.
556 changes: 556 additions & 0 deletions lib/ansible/module_utils/network/avi/ansible_utils.py

Large diffs are not rendered by default.

58 changes: 3 additions & 55 deletions lib/ansible/module_utils/network/avi/avi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,59 +32,7 @@
# avi.sdk.

from __future__ import absolute_import
import os
from distutils.version import LooseVersion

HAS_AVI = True
try:
import avi.sdk
sdk_version = getattr(avi.sdk, '__version__', None)
if ((sdk_version is None) or (sdk_version and (LooseVersion(sdk_version) < LooseVersion('17.2.4')))):
# 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():
"""
Returns common arguments for all Avi modules
:return: dict
"""
return dict(
controller=dict(default=os.environ.get('AVI_CONTROLLER', '')),
username=dict(default=os.environ.get('AVI_USERNAME', '')),
password=dict(default=os.environ.get('AVI_PASSWORD', ''), no_log=True),
tenant=dict(default='admin'),
tenant_uuid=dict(default=''),
api_version=dict(default='16.4.4'),
avi_credentials=dict(default=None, no_log=True, type='dict'),
api_context=dict(type='dict'))


def ansible_return(module, rsp, changed, req=None, existing_obj=None,
api_context=None):
"""
Helper function to return the right ansible return based on the error code and
changed status.
:param module: AnsibleModule
:param rsp: ApiResponse from avi_api
:param changed: boolean
:param req: Actual req dictionary used in Avi API
:param existing_obj: Existing Avi resource. Used for allowing caller to do
diff if desired.
:param api_context: Avi API context information like CSRF token, session_id
used. This can be passed to the next API call to avoid re-login.
Returns: specific ansible module exit function
"""
if rsp.status_code > 299:
return module.fail_json(msg='Error %d Msg %s req: %s api_context:%s ' % (
rsp.status_code, rsp.text, req, api_context))
if changed and existing_obj:
return module.exit_json(
changed=changed, obj=rsp.json(), old_obj=existing_obj,
api_context=api_context)
return module.exit_json(changed=changed, obj=rsp.json(),
api_context=api_context)
from ansible.module_utils.network.avi.ansible_utils import (
avi_ansible_api, avi_common_argument_spec, ansible_return,
avi_obj_cmp, cleanup_absent_fields, AviCheckModeResponse, HAS_AVI)
Loading

0 comments on commit b593548

Please sign in to comment.