Skip to content

Commit 70a9910

Browse files
Merge branch 'main' into new_resources
2 parents 30672fb + 8a5392d commit 70a9910

File tree

4 files changed

+55
-36
lines changed

4 files changed

+55
-36
lines changed

Makefile

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,18 @@
11
fmt:
22
autoflake plugins/modules/*.py
33
autoflake plugins/module_utils/*.py
4-
autoflake tools/module_generator.py
54
autoflake --recursive tests/
65

76
black plugins/modules/*.py
87
black plugins/module_utils/*.py
9-
black tools/module_generator.py
108
black tests/
119

1210
isort plugins/modules/*.py
1311
isort plugins/module_utils/*.py
14-
isort tools/module_generator.py
1512
isort tests/
1613

1714
yamlfmt .
1815

19-
fmt_tools:
20-
# ignore if file not found
21-
-autoflake tools/generated_modules/*.py
22-
-autoflake tools/module_generator.py
23-
-autoflake tools/nitro_resource_map.py
24-
25-
-black tools/generated_modules/*.py
26-
-black tools/module_generator.py
27-
-black tools/nitro_resource_map.py
28-
29-
-isort tools/generated_modules/*.py
30-
-isort tools/module_generator.py
31-
-isort tools/nitro_resource_map.py
32-
33-
generate_modules:
34-
python3 tools/module_generator.py
35-
3616
install:
3717
ansible-galaxy collection install . --force
3818

galaxy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ readme: README.md
1414
# @nicks:irc/im.site#channel'
1515
authors:
1616
- Sumanth Lingappa <sumanth.lingappa@cloud.com>
17+
- Shiva Shankar Vaddepally <shivashankar.vaddepally@cloud.com>
1718
### OPTIONAL but strongly recommended
1819
# A short summary description of the collection
1920
description: Ansible Collection Modules for NetScaler ADC

plugins/module_utils/common.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ def get_resource(client, resource_name, resource_id=None, resource_module_params
7272
id=resource_id,
7373
filter=get_args,
7474
)
75+
elif resource_name == "server":
76+
if "ipaddress" in get_args:
77+
get_args.pop("ipaddress")
78+
if "domain" in get_args:
79+
get_args.pop("domain")
80+
status_code, response_body = client.get(
81+
resource=resource_name,
82+
id=resource_id,
83+
args=get_args,
84+
)
7585
else:
7686
status_code, response_body = client.get(
7787
resource=resource_name,

plugins/module_utils/module_executor.py

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,9 @@ def is_resource_identical(self):
361361
if not self.module_result["diff_list"]:
362362
del self.module_result["diff_list"]
363363
if immutable_resource_module_params != []:
364-
msg = (
365-
"Cannot change value for the following non-updateable attributes %s"
366-
% immutable_resource_module_params
367-
)
368-
self.return_failure(msg)
364+
return (False, immutable_resource_module_params)
369365

370-
return False if diff_list else True
366+
return (False, None) if diff_list else (True, None)
371367

372368
@trace
373369
def create_or_update(self):
@@ -430,8 +426,13 @@ def create_or_update(self):
430426
self.resource_module_params["sitename"] = sitename
431427

432428
else:
433-
# Update only if resource is not identical (idempotent)
434-
if self.is_resource_identical():
429+
# Update process will go through 2 iterations of is_resource_identical
430+
# 1. First iteration will check if the resource is identical. If not, it will give the list of non-updatable attributes that exists
431+
# in the user playbook. If non-updatable attributes are present, it will remove them from the module_params and update the resource
432+
# 2. Second iteration will check if the resource is identical. If not, it will update the resource after ignoring the
433+
# non-updatable resources
434+
is_identical, immutable_keys_list = self.is_resource_identical()
435+
if is_identical:
435436
log(
436437
"INFO: Resource `%s:%s` exists and is identical. No change required."
437438
% (
@@ -451,19 +452,46 @@ def create_or_update(self):
451452
ok, err = create_resource(
452453
self.client, self.resource_name, self.resource_module_params
453454
)
454-
else:
455+
456+
elif immutable_keys_list is None:
457+
self.module_result["changed"] = True
455458
log(
456-
"INFO: Resource %s:%s exists. Will be UPDATED."
457-
% (
458-
self.resource_name,
459-
self.resource_id,
460-
)
459+
"INFO: Resource %s:%s exists and is different. Will be UPDATED."
460+
% (self.resource_name, self.resource_id)
461461
)
462462
ok, err = update_resource(
463463
self.client, self.resource_name, self.resource_module_params
464464
)
465-
if not ok:
466-
self.return_failure(err)
465+
if not ok:
466+
self.return_failure(err)
467+
else:
468+
for key in immutable_keys_list:
469+
self.resource_module_params.pop(key)
470+
471+
is_identical, temp_immutable_list = self.is_resource_identical()
472+
# temp_immutable_list is a dummy as '_' is not allowed in lint.
473+
if is_identical:
474+
msg = (
475+
f"Resource {self.resource_name}/{self.resource_id} not updated because user is trying to "
476+
f"update following non-updatable keys: {immutable_keys_list}"
477+
)
478+
self.module.warn(msg)
479+
log(msg)
480+
self.module_result["changed"] = False
481+
self.module.exit_json(**self.module_result)
482+
else:
483+
self.module_result["changed"] = True
484+
msg = (
485+
f"Resource {self.resource_name}/{self.resource_id} is updated after ignoring following "
486+
f"non-updatable keys: {immutable_keys_list}"
487+
)
488+
self.module.warn(msg)
489+
log(msg)
490+
ok, err = update_resource(
491+
self.client, self.resource_name, self.resource_module_params
492+
)
493+
if not ok:
494+
self.return_failure(err)
467495

468496
@trace
469497
def enable_or_disable(self, desired_state):

0 commit comments

Comments
 (0)