Skip to content

Commit

Permalink
Merge pull request #117 from cisco-en-programmability/develop
Browse files Browse the repository at this point in the history
Develop - 6.7.5
  • Loading branch information
DbarrantesE authored Sep 25, 2023
2 parents d1d6e1f + f8d86a3 commit 4b77674
Show file tree
Hide file tree
Showing 16 changed files with 643 additions and 341 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The following table shows the supported versions.
| 2.2.2.3 | 3.3.1 | 2.3.3 |
| 2.2.3.3 | 6.4.0 | 2.4.11 |
| 2.3.3.0 | 6.6.4 | 2.5.5 |
| 2.3.5.3 | 6.7.4 | 2.6.0 |
| 2.3.5.3 | 6.7.5 | 2.6.0 |

If your Ansible collection is older please consider updating it first.

Expand Down
11 changes: 10 additions & 1 deletion changelogs/changelog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -703,4 +703,13 @@ releases:
changes:
release_summary: Updated sanity test.
minor_changes:
- Updated test/sanity and remove unnecessary
- Updated test/sanity and remove unnecessary
6.7.5:
release_date: "2023-09-25"
changes:
release_summary: Updated different function names.
bugfixes:
- Updated from get_permissions_ap_i to get_permissions_api
- Updated from get_roles_ap_i to get_roles_api
- Updated from get_users_ap_i to get_users_api
- Updated from get_external_authentication_servers_ap_i to get_external_authentication_servers_api
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
namespace: cisco
name: dnac
version: 6.7.4
version: 6.7.5
readme: README.md
authors:
- Rafael Campos <[email protected]>
Expand Down
18 changes: 18 additions & 0 deletions playbooks/user_info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- hosts: dnac_servers
vars_files:
- credentials.yml
gather_facts: false
connection: local
tasks:
- name: Get all User
cisco.dnac.user_info:
dnac_host: "{{dnac_host}}"
dnac_username: "{{dnac_username}}"
dnac_password: "{{dnac_password}}"
dnac_verify: "{{dnac_verify}}"
dnac_port: "{{dnac_port}}"
dnac_version: "{{dnac_version}}"
dnac_debug: "{{dnac_debug}}"
#headers: "{{my_headers | from_json}}"
invokeSource: string
register: result
4 changes: 2 additions & 2 deletions plugins/action/role_permissions_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def run(self, tmp=None, task_vars=None):
dnac = DNACSDK(params=self._task.args)

response = dnac.exec(
family="userand_roles",
function='get_permissions_ap_i',
family="user_and_roles",
function='get_permissions_api',
params=self.get_object(self._task.args),
)
self._result.update(dict(dnac_response=response))
Expand Down
4 changes: 2 additions & 2 deletions plugins/action/roles_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ def run(self, tmp=None, task_vars=None):
dnac = DNACSDK(params=self._task.args)

response = dnac.exec(
family="userand_roles",
function='get_roles_ap_i',
family="user_and_roles",
function='get_roles_api',
params=self.get_object(self._task.args),
)
self._result.update(dict(dnac_response=response))
Expand Down
12 changes: 6 additions & 6 deletions plugins/action/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ def get_object_by_name(self, name):
# NOTE: Does not have a get by name method, using get all
try:
items = self.dnac.exec(
family="userand_roles",
function="get_users_ap_i",
family="user_and_roles",
function="get_users_api",
params=self.get_all_params(name=name),
)
if isinstance(items, dict):
Expand Down Expand Up @@ -148,8 +148,8 @@ def requires_update(self, current_obj):

def create(self):
result = self.dnac.exec(
family="userand_roles",
function="add_user_ap_i",
family="user_and_roles",
function="add_user_api",
params=self.create_params(),
op_modifies=True,
)
Expand All @@ -160,8 +160,8 @@ def update(self):
name = self.new_object.get("name")
result = None
result = self.dnac.exec(
family="userand_roles",
function="update_user_ap_i",
family="user_and_roles",
function="update_user_api",
params=self.update_all_params(),
op_modifies=True,
)
Expand Down
4 changes: 2 additions & 2 deletions plugins/action/user_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def run(self, tmp=None, task_vars=None):
dnac = DNACSDK(params=self._task.args)

response = dnac.exec(
family="userand_roles",
function='get_users_ap_i',
family="user_and_roles",
function='get_users_api',
params=self.get_object(self._task.args),
)
self._result.update(dict(dnac_response=response))
Expand Down
4 changes: 2 additions & 2 deletions plugins/action/users_external_servers_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ def run(self, tmp=None, task_vars=None):
dnac = DNACSDK(params=self._task.args)

response = dnac.exec(
family="userand_roles",
function='get_external_authentication_servers_ap_i',
family="user_and_roles",
function='get_external_authentication_servers_api',
params=self.get_object(self._task.args),
)
self._result.update(dict(dnac_response=response))
Expand Down
80 changes: 78 additions & 2 deletions plugins/module_utils/dnac.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,89 @@
else:
LOGGING_IN_STANDARD = True
import os.path
import copy
import datetime
import inspect


def log(msg):
class DnacBase:
"""Class contains members which can be reused for all intent modules"""
def __init__(self, module):
self.module = module
self.params = module.params
self.config = copy.deepcopy(module.params.get("config"))
self.have_create = {}
self.want_create = {}
self.validated_config = []
self.msg = ""
self.status = "success"
dnac_params = self.get_dnac_params(self.params)
self.dnac = DNACSDK(params=dnac_params)
self.dnac_apply = {'exec': self.dnac._exec}
self.get_diff_state_apply = {'merged': self.get_diff_merged,
'deleted': self.get_diff_deleted}
self.dnac_log = dnac_params.get("dnac_log")
self.log(str(dnac_params))
self.supported_states = ["merged", "deleted"]
self.result = {"changed": False, "diff": [], "response": [], "warnings": []}

def log(self, message, frameIncrement=0):
"""Log messages into dnac.log file"""

if self.dnac_log:
message = "Module: " + self.__class__.__name__ + ", " + message
log(message, (1 + frameIncrement))

def check_return_status(self):
"""API to check the return status value and exit/fail the module"""

self.log("status: {0}, msg:{1}".format(self.status, self.msg), frameIncrement=1)
if "failed" in self.status:
self.module.fail_json(msg=self.msg, response=[])
elif "exited" in self.status:
self.module.exit_json(**self.result)
elif "invalid" in self.status:
self.module.fail_json(msg=self.msg, response=[])

def get_dnac_params(self, params):
"""Store the DNAC parameters from the playbook"""

dnac_params = {"dnac_host": params.get("dnac_host"),
"dnac_port": params.get("dnac_port"),
"dnac_username": params.get("dnac_username"),
"dnac_password": params.get("dnac_password"),
"dnac_verify": params.get("dnac_verify"),
"dnac_debug": params.get("dnac_debug"),
"dnac_log": params.get("dnac_log")
}
return dnac_params

def get_task_details(self, task_id):
"""Check if the task performed is sucessfull or not"""

result = None
response = self.dnac_apply['exec'](
family="task",
function="get_task_by_id",
params={"task_id": task_id},
)

self.log(str(response))
if isinstance(response, dict):
result = response.get("response")

return result

def reset_values(self):
"""Reset all neccessary attributes to default values"""

self.have_create.clear()
self.want_create.clear()


def log(msg, frameIncrement=0):
with open('dnac.log', 'a') as of:
callerframerecord = inspect.stack()[1]
callerframerecord = inspect.stack()[1 + frameIncrement]
frame = callerframerecord[0]
info = inspect.getframeinfo(frame)
d = datetime.datetime.now().replace(microsecond=0).isoformat()
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/role_permissions_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
link: https://developer.cisco.com/docs/dna-center/#!get-permissions-api
notes:
- SDK Method used are
userand_roles.UserandRoles.get_permissions_ap_i,
user_and_roles.UserandRoles.get_permissions_ap_i,
- Paths used are
get /dna/system/api/v1/role/permissions,
Expand Down
2 changes: 1 addition & 1 deletion plugins/modules/roles_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
link: https://developer.cisco.com/docs/dna-center/#!get-roles-api
notes:
- SDK Method used are
userand_roles.UserandRoles.get_roles_ap_i,
user_and_roles.UserandRoles.get_roles_ap_i,
- Paths used are
get /dna/system/api/v1/roles,
Expand Down
Loading

0 comments on commit 4b77674

Please sign in to comment.