Skip to content

Commit 7c8c453

Browse files
committed
add fail_on_nodata attribute to cmci_get
Signed-off-by: Andrew Twydell <[email protected]>
1 parent dfdcc7e commit 7c8c453

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

plugins/module_utils/cmci.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,8 +418,8 @@ def handle_response(self, response_dict): # type: (Dict) -> None
418418
feedback = errors_node[FEEDBACK]
419419
self.result[FEEDBACK] = read_error_node(feedback)
420420

421-
# Non-OK CPSM responses fail the module
422-
if cpsm_response_code != 1024:
421+
# If CPSM response code not in Valid List, fail the module
422+
if self.get_ok_cpsm_response_codes().count(cpsm_response_code) == 0:
423423
self._fail(
424424
'CMCI request failed with response "{0}" reason "{1}"'
425425
.format(
@@ -436,6 +436,9 @@ def handle_response(self, response_dict): # type: (Dict) -> None
436436
'Could not parse CMCI response: missing node "{0}"'
437437
.format(e.args[0])
438438
)
439+
440+
def get_ok_cpsm_response_codes(self):
441+
return [1024]
439442

440443
def init_url(self): # type: () -> str
441444
t = self._p.get(TYPE).lower()

plugins/modules/cmci_get.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040
- The count value must be an integer; a value of zero is not permitted.
4141
type: int
4242
required: false
43+
fail_on_nodata:
44+
description:
45+
- Specifies whether the module should fail if no data is returned by the
46+
query. If set to true, the module will fail if no data is returned.
47+
- Default behaviour is for the module to fail if no data is returned. When
48+
set to false, the module will return OK, just with no records.
49+
type: bool
50+
required: false
51+
default: true
4352
'''
4453

4554

@@ -87,6 +96,23 @@
8796
value: MYGRP
8897
record_count: 1
8998
99+
- name: pass module even if bundle definition is not found
100+
cmci_get:
101+
cmci_host: 'winmvs2c.hursley.ibm.com'
102+
cmci_port: 10080
103+
cmci_cert: './sec/ansible.pem'
104+
cmci_key: './sec/ansible.key'
105+
context: 'iyk3z0r9'
106+
type: cicsdefinitionbundle
107+
resources:
108+
filter:
109+
name: MYBUNDLE
110+
get_parameters:
111+
- name: csdgroup
112+
value: MYGRP
113+
record_count: 1
114+
fail_on_nodata: "false"
115+
90116
- name: Using complex_filter to combine filter expressions and change operators
91117
cmci_get:
92118
cmci_host: 'winmvs2c.hursley.ibm.com'
@@ -496,6 +522,7 @@
496522

497523

498524
_RECORD_COUNT = 'record_count'
525+
_FAIL_ON_NODATA = 'fail_on_nodata'
499526

500527

501528
class AnsibleCMCIGetModule(AnsibleCMCIModule):
@@ -507,6 +534,10 @@ def init_argument_spec(self): # type: () -> Dict
507534
argument_spec.update({
508535
_RECORD_COUNT: {
509536
'type': 'int'
537+
},
538+
_FAIL_ON_NODATA: {
539+
'type': 'bool',
540+
'default': True
510541
}
511542
})
512543
argument_spec.update(RESOURCES_ARGUMENT)
@@ -522,6 +553,14 @@ def init_url(self): # type: () -> str
522553
url = url + '//' + str(self._p.get(_RECORD_COUNT))
523554

524555
return url
556+
557+
def get_ok_cpsm_response_codes(self):
558+
ok_codes = super(AnsibleCMCIGetModule, self).get_ok_cpsm_response_codes()
559+
560+
if not self._p.get(_FAIL_ON_NODATA):
561+
ok_codes.append(1027)
562+
563+
return ok_codes
525564

526565

527566
def main():

0 commit comments

Comments
 (0)