22
22
23
23
from ansible_collections .cisco .dcnm .plugins .module_utils .common .conversion import \
24
24
ConversionUtils
25
+ from ansible_collections .cisco .dcnm .plugins .module_utils .common .properties import \
26
+ Properties
25
27
from ansible_collections .cisco .dcnm .plugins .module_utils .fabric .config_deploy import \
26
28
FabricConfigDeploy
27
29
from ansible_collections .cisco .dcnm .plugins .module_utils .fabric .config_save import \
30
32
FabricTypes
31
33
32
34
35
+ @Properties .add_rest_send
36
+ @Properties .add_results
33
37
class FabricCommon :
34
38
"""
39
+ ### Summary
35
40
Common methods used by the other classes supporting
36
41
the dcnm_fabric module
37
42
38
- Usage (where params is AnsibleModule.params)
43
+ ### Usage
39
44
40
45
class MyClass(FabricCommon):
41
- def __init__(self, params ):
42
- super().__init__(params )
46
+ def __init__(self):
47
+ super().__init__()
43
48
...
44
49
"""
45
50
46
- def __init__ (self , params ):
51
+ def __init__ (self ):
47
52
self .class_name = self .__class__ .__name__
48
- self .params = params
53
+ self .action = None
49
54
50
55
self .log = logging .getLogger (f"dcnm.{ self .class_name } " )
51
56
52
- self .check_mode = self .params .get ("check_mode" , None )
53
- if self .check_mode is None :
54
- msg = f"{ self .class_name } .__init__(): "
55
- msg += "check_mode is required"
56
- raise ValueError (msg )
57
-
58
- self .state = self .params .get ("state" , None )
59
- if self .state is None :
60
- msg = f"{ self .class_name } .__init__(): "
61
- msg += "state is required"
62
- raise ValueError (msg )
63
-
64
57
self .conversion = ConversionUtils ()
65
- self .config_save = FabricConfigSave (params )
66
- self .config_deploy = FabricConfigDeploy (params )
58
+ self .config_save = FabricConfigSave ()
59
+ self .config_deploy = FabricConfigDeploy ()
67
60
self .fabric_types = FabricTypes ()
68
61
69
- msg = "ENTERED FabricCommon(): "
70
- msg += f"check_mode: { self .check_mode } , "
71
- msg += f"state: { self .state } "
62
+ msg = "ENTERED FabricCommon()"
72
63
self .log .debug (msg )
73
64
74
65
# key: fabric_name, value: boolean
@@ -105,19 +96,13 @@ def __init__(self, params):
105
96
self .path = None
106
97
self .verb = None
107
98
108
- self ._init_properties ()
109
- self ._init_key_translations ()
99
+ self ._fabric_details = None
100
+ self ._fabric_summary = None
101
+ self ._fabric_type = "VXLAN_EVPN"
102
+ self ._rest_send = None
103
+ self ._results = None
110
104
111
- def _init_properties (self ) -> None :
112
- """
113
- Initialize the properties dictionary.
114
- """
115
- self ._properties : dict = {}
116
- self ._properties ["fabric_details" ] = None
117
- self ._properties ["fabric_summary" ] = None
118
- self ._properties ["fabric_type" ] = "VXLAN_EVPN"
119
- self ._properties ["rest_send" ] = None
120
- self ._properties ["results" ] = None
105
+ self ._init_key_translations ()
121
106
122
107
def _init_key_translations (self ):
123
108
"""
@@ -166,6 +151,7 @@ def _config_save(self, payload):
166
151
return
167
152
168
153
self .config_save .payload = payload
154
+ # pylint: disable=no-member
169
155
self .config_save .rest_send = self .rest_send
170
156
self .config_save .results = self .results
171
157
try :
@@ -196,6 +182,7 @@ def _config_deploy(self, payload):
196
182
self .config_deploy .fabric_details = self .fabric_details
197
183
self .config_deploy .payload = payload
198
184
self .config_deploy .fabric_summary = self .fabric_summary
185
+ # pylint: disable=no-member
199
186
self .config_deploy .rest_send = self .rest_send
200
187
self .config_deploy .results = self .results
201
188
except TypeError as error :
@@ -240,6 +227,7 @@ def translate_anycast_gw_mac(self, fabric_name, mac_address):
240
227
try :
241
228
mac_address = self .conversion .translate_mac_address (mac_address )
242
229
except ValueError as error :
230
+ # pylint: disable=no-member
243
231
self .results .failed = True
244
232
self .results .changed = False
245
233
self .results .register_task_result ()
@@ -270,6 +258,7 @@ def _fixup_payloads_to_commit(self) -> None:
270
258
self ._fixup_anycast_gw_mac ()
271
259
self ._fixup_bgp_as ()
272
260
except ValueError as error :
261
+ # pylint: disable=no-member
273
262
self .results .failed = True
274
263
self .results .changed = False
275
264
self .results .register_task_result ()
@@ -324,7 +313,7 @@ def _verify_payload(self, payload) -> None:
324
313
- raise ``ValueError`` if the payload is missing mandatory keys
325
314
"""
326
315
method_name = inspect .stack ()[0 ][3 ]
327
- if self .state not in {"merged " , "replaced " }:
316
+ if self .action not in {"fabric_create " , "fabric_replace" , "fabric_update " }:
328
317
return
329
318
msg = f"{ self .class_name } .{ method_name } : "
330
319
msg += f"payload: { payload } "
@@ -393,22 +382,22 @@ def fabric_details(self):
393
382
"""
394
383
An instance of the FabricDetails class.
395
384
"""
396
- return self ._properties [ "fabric_details" ]
385
+ return self ._fabric_details
397
386
398
387
@fabric_details .setter
399
388
def fabric_details (self , value ):
400
- self ._properties [ "fabric_details" ] = value
389
+ self ._fabric_details = value
401
390
402
391
@property
403
392
def fabric_summary (self ):
404
393
"""
405
394
An instance of the FabricSummary class.
406
395
"""
407
- return self ._properties [ "fabric_summary" ]
396
+ return self ._fabric_summary
408
397
409
398
@fabric_summary .setter
410
399
def fabric_summary (self , value ):
411
- self ._properties [ "fabric_summary" ] = value
400
+ self ._fabric_summary = value
412
401
413
402
@property
414
403
def fabric_type (self ):
@@ -419,7 +408,7 @@ def fabric_type(self):
419
408
420
409
See ``FabricTypes().valid_fabric_types`` for valid values
421
410
"""
422
- return self ._properties [ "fabric_type" ]
411
+ return self ._fabric_type
423
412
424
413
@fabric_type .setter
425
414
def fabric_type (self , value ):
@@ -430,26 +419,4 @@ def fabric_type(self, value):
430
419
msg += f"{ self .fabric_types .valid_fabric_types } . "
431
420
msg += f"Got { value } "
432
421
raise ValueError (msg )
433
- self ._properties ["fabric_type" ] = value
434
-
435
- @property
436
- def rest_send (self ):
437
- """
438
- An instance of the RestSend class.
439
- """
440
- return self ._properties ["rest_send" ]
441
-
442
- @rest_send .setter
443
- def rest_send (self , value ):
444
- self ._properties ["rest_send" ] = value
445
-
446
- @property
447
- def results (self ):
448
- """
449
- An instance of the Results class.
450
- """
451
- return self ._properties ["results" ]
452
-
453
- @results .setter
454
- def results (self , value ):
455
- self ._properties ["results" ] = value
422
+ self ._fabric_type = value
0 commit comments