Skip to content

Commit 795ed4b

Browse files
Merge pull request #96 from Tom-Latham/feedback
CMCI Feedback Support
2 parents 793f4bd + 30e6279 commit 795ed4b

File tree

32 files changed

+2353
-139
lines changed

32 files changed

+2353
-139
lines changed

plugins/module_utils/cmci.py

Lines changed: 57 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@
4444
COMPLEX_FILTER = 'complex_filter'
4545
SCHEME = 'scheme'
4646
INSECURE = 'insecure'
47+
FEEDBACK = 'feedback'
4748
TIMEOUT = 'timeout'
48-
4949
GET_PARAMETERS = 'get_parameters'
5050

5151

@@ -152,6 +152,50 @@ def is_alphanumeric(value):
152152
return re.match('^([A-Za-z0-9]{1,100})$', value, flags=0)
153153

154154

155+
def read_node(node): # type: (OrderedDict) -> List[OrderedDict]
156+
# Reads a record node that can contain multiple lists of attributes
157+
result = [
158+
OrderedDict(
159+
[get_attribute(k, v)
160+
for k, v in n.items()]
161+
) for n in node
162+
]
163+
return result
164+
165+
166+
def read_error_node(node): # type: (OrderedDict) -> List[OrderedDict]
167+
# Reads an error node than can contain multiple lists of attributes that themselves contain
168+
# multiple lists of attributes
169+
result = [
170+
OrderedDict(
171+
# Feedback nodes can contain error types with further information
172+
[get_attribute(k, v) if k[0] == '@'
173+
else read_error_detail(k, v)
174+
for k, v in n.items()]
175+
) for n in node
176+
]
177+
return result
178+
179+
180+
def read_error_detail(key, value): # type: (List[str, OrderedDict]) -> Tuple[str, List[OrderedDict]]
181+
# Xmltodict parses inner error types as Dicts when there is only one item in it even though it may well be a list
182+
# if multiple results were returned. If we find a dict here, wrap it in a list so we can account for only one result or many
183+
# being returned
184+
if not isinstance(value, list):
185+
value = [value]
186+
return key, \
187+
[
188+
OrderedDict(
189+
[(k[1:], v) for k, v in error.items()]
190+
) for error in value
191+
]
192+
193+
194+
def get_attribute(k, v):
195+
#Return key, value pair stripping @ from the attributes key
196+
return (k[1:], v)
197+
198+
155199
class AnsibleCMCIModule(object):
156200

157201
def __init__(self, method):
@@ -364,12 +408,13 @@ def handle_response(self, response_dict): # type: (Dict) -> None
364408
records_node = response_node['records']
365409
resource_type = self._p[TYPE].lower()
366410
if resource_type in records_node:
367-
records = records_node[resource_type]
368-
# Copy records in result, stripping @ from attributes
369-
self.result['records'] = [
370-
{k[1:]: v for k, v in record.items()}
371-
for record in records
372-
]
411+
self.result['records'] = read_node(records_node[resource_type])
412+
413+
if 'errors' in response_node:
414+
errors_node = response_node['errors']
415+
if FEEDBACK in errors_node:
416+
feedback = errors_node[FEEDBACK]
417+
self.result[FEEDBACK] = read_error_node(feedback)
373418

374419
# Non-OK CPSM responses fail the module
375420
if cpsm_response_code != 1024:
@@ -534,7 +579,10 @@ def _do_request(self): # type: () -> Dict
534579
process_namespaces=True,
535580
namespaces=namespaces,
536581
# Make sure we always return a list for the resource node
537-
force_list=(self._p.get(TYPE).lower(),)
582+
force_list=(
583+
self._p.get(TYPE).lower(),
584+
FEEDBACK
585+
)
538586
)
539587

540588
return r
@@ -674,7 +722,7 @@ def _get_complex_filter(self, i, path):
674722
if not is_alphanumeric(attribute):
675723
self._fail(
676724
"Filter attribute with value {0} was not valid. Valid characters are A-Z a-z 0-9."
677-
.format(attribute)
725+
.format(attribute)
678726
)
679727

680728
value = escape_quotes(value)
@@ -685,7 +733,6 @@ def _get_complex_filter(self, i, path):
685733
else:
686734
return attribute + operator + '\'' + value + '\''
687735

688-
689736
def _convert_filter_operator(self, operator, path):
690737
if operator in ['<', 'LT']:
691738
return '<'

plugins/modules/cmci_action.py

Lines changed: 233 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,239 @@
244244
description: The URL used for the request.
245245
returned: success
246246
type: str
247+
feedback:
248+
description: Diagnostic data from FEEDBACK records associated with the request
249+
returned: cmci error
250+
type: list
251+
elements: dict
252+
contains:
253+
action:
254+
description: The name of the action that has failed.
255+
returned: cmci error
256+
type: str
257+
attribute1:
258+
description: The name of one of up to six attributes associated with the error.
259+
returned: cmci error
260+
type: str
261+
attribute2:
262+
description: The name of one of up to six attributes associated with the error.
263+
returned: cmci error
264+
type: str
265+
attribute3:
266+
description: The name of one of up to six attributes associated with the error.
267+
returned: cmci error
268+
type: str
269+
attribute4:
270+
description: The name of one of up to six attributes associated with the error.
271+
returned: cmci error
272+
type: str
273+
attribute5:
274+
description: The name of one of up to six attributes associated with the error.
275+
returned: cmci error
276+
type: str
277+
attribute6:
278+
description: The name of one of up to six attributes associated with the error.
279+
returned: cmci error
280+
type: str
281+
eibfn:
282+
description: The function code associated with the request.
283+
returned: cmci error
284+
type: str
285+
eibfn_alt:
286+
description: The name of the function associated with the request.
287+
returned: cmci error
288+
type: str
289+
errorcode:
290+
description: The CICSPlex® SM error code associated with the resource.
291+
returned: cmci error
292+
type: str
293+
eyu_cicsname:
294+
description: The name of the CICS region or CICSplex associated with the error.
295+
returned: cmci error
296+
type: str
297+
keydata:
298+
description: A string of data that identifies the instance of a resource associated with the error.
299+
returned: cmci error
300+
type: str
301+
resp:
302+
description: The CICS RESP code or the CICSPlex SM API EYUDA response code as a numeric value.
303+
returned: cmci error
304+
type: str
305+
resp2:
306+
description: The CICS RESP2 code or the CICSPlex SM API EYUDA reason code as a numeric value.
307+
returned: cmci error
308+
type: str
309+
resp_alt:
310+
description: >
311+
The text equivalent for the resp value. For example, the text equivalent of a resp value of 16 is INVREQ.
312+
returned: cmci error
313+
type: str
314+
installerror:
315+
description: >
316+
Contains diagnostic data from a BINSTERR record associated with a CICS® management client interface PUT install request.
317+
returned: cmci error
318+
type: list
319+
elements: dict
320+
contains:
321+
eibfn:
322+
description: The function code associated with the request.
323+
returned: cmci error
324+
type: str
325+
eyu_cicsname:
326+
description: The name of the CICS region or CICSplex associated with the installation error.
327+
returned: cmci error
328+
type: str
329+
cresp1:
330+
description: The CICS RESP code or the CICSPlex® SM API EYUDA response code as a numeric value.
331+
returned: cmci error
332+
type: str
333+
cresp2:
334+
description: The CICS RESP2 code or the CICSPlex SM API EYUDA reason code as a numeric value.
335+
returned: cmci error
336+
type: str
337+
errorcode:
338+
description: The CICSPlex SM error code associated with the resource.
339+
returned: cmci error
340+
type: str
341+
ressname:
342+
description: The name of the resource associated with the error.
343+
returned: cmci error
344+
type: str
345+
resver:
346+
description: The version number of the resource associated with the error.
347+
returned: cmci error
348+
type: str
349+
inconsistentscope:
350+
description: >
351+
Contains diagnostic data from a BINCONSC record associated with a CICS® management client interface PUT request.
352+
returned: cmci error
353+
type: list
354+
elements: dict
355+
contains:
356+
eibfn:
357+
description: The function code associated with the request.
358+
returned: cmci error
359+
type: str
360+
eyu_cicsname:
361+
description: The name of the CICS region or CICSplex associated with the installation error.
362+
returned: cmci error
363+
type: str
364+
erroroperation:
365+
description: A numeric value that identifies the operation being performed when the error occurred.
366+
returned: cmci error
367+
type: str
368+
errorcode:
369+
description: The CICSPlex® SM error code associated with the resource.
370+
returned: cmci error
371+
type: str
372+
targetassignment:
373+
description: The assignment for the target scope.
374+
returned: cmci error
375+
type: str
376+
targetdescription:
377+
description: The resource description for the target scope.
378+
returned: cmci error
379+
type: str
380+
relatedassignment:
381+
description: The resource assignment for the related scope.
382+
returned: cmci error
383+
type: str
384+
relateddescription:
385+
description: The resource description for the related scope.
386+
returned: cmci error
387+
type: str
388+
relatedscope:
389+
description: The name of the related scope.
390+
returned: cmci error
391+
type: str
392+
inconsistentset:
393+
description: >
394+
Contains diagnostic data from a BINCONRS record associated with a CICS® management client interface PUT request.
395+
returned: cmci error
396+
type: list
397+
elements: dict
398+
contains:
399+
candidatename:
400+
description: The name of the candidate resource.
401+
returned: cmci error
402+
type: str
403+
candidateversion:
404+
description: The version number of the candidate resource.
405+
returned: cmci error
406+
type: str
407+
candidategroup:
408+
description: The resource group of the candidate resource.
409+
returned: cmci error
410+
type: str
411+
candidateassignment:
412+
description: The assignment of the candidate resource.
413+
returned: cmci error
414+
type: str
415+
candidatedescription:
416+
description: The description of the candidate resource.
417+
returned: cmci error
418+
type: str
419+
candidateusage:
420+
description: The assignment usage of the candidate resource.
421+
returned: cmci error
422+
type: str
423+
candidatesystemgroup:
424+
description: The system group of the candidate resource.
425+
returned: cmci error
426+
type: str
427+
candidatetype:
428+
description: The system type of the candidate resource.
429+
returned: cmci error
430+
type: str
431+
candidateoverride:
432+
description: The assignment override of the candidate resource.
433+
returned: cmci error
434+
type: str
435+
eyu_cicsname:
436+
description: The name of the CICS region associated with the installation error.
437+
returned: cmci error
438+
type: str
439+
erroroperation:
440+
description: >
441+
A numeric value that identifies that the operation being performed when the error occurred
442+
returned: cmci error
443+
type: str
444+
existingname:
445+
description: The name of the existing resource.
446+
returned: cmci error
447+
type: str
448+
existingversion:
449+
description: The version number of the existing resource.
450+
returned: cmci error
451+
type: str
452+
existinggroup:
453+
description: The resource group of the existing resource.
454+
returned: cmci error
455+
type: str
456+
existingassignment:
457+
description: The assignment of the existing resource.
458+
returned: cmci error
459+
type: str
460+
existingdescription:
461+
description: The description of the existing resource.
462+
returned: cmci error
463+
type: str
464+
existingusage:
465+
description: The assignment usage of the existing resource.
466+
returned: cmci error
467+
type: str
468+
existingsystemgroup:
469+
description: The system group of the existing resource.
470+
returned: cmci error
471+
type: str
472+
existingtype:
473+
description: The system type of the existing resource.
474+
returned: cmci error
475+
type: str
476+
existingoverride:
477+
description: The assignment override of the existing resource.
478+
returned: cmci error
479+
type: str
247480
"""
248481

249482

0 commit comments

Comments
 (0)