2020
2121DOCUMENTATION = """
2222---
23- module: dcnm_child_fabric
23+ module: dcnm_fabric_member
2424short_description: Manage addition and deletion of NDFC fabrics to MSD.
2525version_added: "3.5.0"
2626author: Prabahal (@prabahal)
6363EXAMPLES = """
6464
6565- name: add child fabrics to MSD
66- cisco.dcnm.dcnm_child_fabric :
66+ cisco.dcnm.dcnm_fabric_member :
6767 state: merged
6868 config:
6969 - FABRIC_NAME: MSD_Parent1
7979# Query the child fabrics of a MSD Fabric.
8080
8181- name: Query the child fabrics of MSD fabrics.
82- cisco.dcnm.dcnm_child_fabric :
82+ cisco.dcnm.dcnm_fabric_member :
8383 state: query
8484 config:
8585 - FABRIC_NAME: MSD_Fabric1
123123from ..module_utils .msd .query_child_fab import childFabricQuery
124124from ..module_utils .msd .delete_child_fab import childFabricDelete
125125from ..module_utils .msd .add_child_fab import childFabricAdd
126- from ..module_utils .msd .Fabric_associations import FabricAssociations
126+ from ..module_utils .msd .fabric_associations import FabricAssociations
127127from ..module_utils .fabric .verify_playbook_params import VerifyPlaybookParams
128-
128+ from .. module_utils . network . dcnm . dcnm import validate_list_of_dicts
129129
130130@Properties .add_rest_send
131131class childCommon ():
@@ -151,7 +151,6 @@ def __init__(self, params):
151151 self .results = Results ()
152152 self .results .state = self .state
153153 self .results .check_mode = self .check_mode
154- self ._verify_playbook_params = VerifyPlaybookParams ()
155154 self .conversion = ConversionUtils ()
156155 self .payloads = []
157156 self .want = []
@@ -218,36 +217,54 @@ def verify_child_fabric_is_already_member(self, item) -> bool:
218217 if (self .data [fabric ]['fabricParent' ] == item ["destFabric" ]):
219218 return True
220219 return False
221-
222- def get_want (self ):
223- method_name = inspect .stack ()[0 ][3 ]
220+
221+ def validate_input (self ):
222+ if self .state != "query" :
223+ fab_member_spec = dict (
224+ FABRIC_NAME = dict (required = True , type = "str" ),
225+ CHILD_FABRIC_NAME = dict (required = True , type = "str" ),
226+ DEPLOY = dict (type = "bool" , default = False ),
227+ )
228+ else :
229+ fab_member_spec = dict (
230+ FABRIC_NAME = dict (type = "str" ),
231+ )
232+ fab_mem_info , invalid_params = validate_list_of_dicts (self .config , fab_member_spec , None )
233+ if invalid_params :
234+ mesg = "Invalid parameters in playbook: {0}" .format (
235+ "while processing config "
236+ + "\n " .join (invalid_params )
237+ )
238+ raise ValueError (mesg )
224239 for config in self .config :
225- msg = f"payload: { config } "
226- self .log .debug (msg )
227-
228240 if not isinstance (config , dict ):
229241 msg = f"{ self .class_name } .{ method_name } : "
230- msg += "Playbook configuration for fabrics must be a dict. "
242+ msg += "Playbook configuration for fabric_member must be a dict. "
231243 msg += f"Got type { type (config ).__name__ } , "
232244 msg += f"value { config } ."
233245 raise ValueError (msg )
246+ msd_fabric = config .get ("FABRIC_NAME" , None )
247+ child_fabric = config .get ("CHILD_FABRIC_NAME" , None )
234248 try :
235- msd_fabric = config .get ("FABRIC_NAME" , None )
236- child_fabric = config .get ("CHILD_FABRIC_NAME" , None )
237- deploy = config .get ("DEPLOY" , None )
238- try :
239- self .conversion .validate_fabric_name (msd_fabric )
240- self .conversion .validate_fabric_name (child_fabric )
241- except (TypeError , ValueError ) as error :
242- msg = f"{ self .class_name } : "
243- msg += "Playbook configuration for FABRIC_NAME or CHILD_FABRIC_NAME "
244- msg += "contains an invalid FABRIC_NAME. "
245- # error below already contains a period "." at the end
246- msg += f"Error detail: { error } "
247- msg += f"Bad configuration: { config } ."
248- raise ValueError (msg ) from error
249- except ValueError as error :
250- raise ValueError (f"{ error } " ) from error
249+ self .conversion .validate_fabric_name (msd_fabric )
250+ self .conversion .validate_fabric_name (child_fabric )
251+ except (TypeError , ValueError ) as error :
252+ msg = f"{ self .class_name } : "
253+ msg += "Playbook configuration for FABRIC_NAME or CHILD_FABRIC_NAME "
254+ msg += "contains an invalid FABRIC_NAME. "
255+ # error below already contains a period "." at the end
256+ msg += f"Error detail: { error } "
257+ msg += f"Bad configuration: { config } ."
258+ raise ValueError (msg ) from error
259+
260+ def get_want (self ):
261+ method_name = inspect .stack ()[0 ][3 ]
262+ for config in self .config :
263+ msg = f"{ method_name } payload: { config } "
264+ self .log .debug (msg )
265+ msd_fabric = config .get ("FABRIC_NAME" , None )
266+ child_fabric = config .get ("CHILD_FABRIC_NAME" , None )
267+ deploy = config .get ("DEPLOY" , None )
251268 config_payload = {'destFabric' : msd_fabric , 'sourceFabric' : child_fabric , 'DEPLOY' : deploy }
252269 self .payloads .append (copy .deepcopy (config_payload ))
253270
@@ -315,24 +332,7 @@ def populate_state(self):
315332 msg += f"Expected one of: { ',' .join (valid_states )} ."
316333 raise ValueError (msg )
317334
318- def get_want_query (self ) -> None :
319- """
320- ### Summary
321- - Validate the playbook configs.
322- - Update self.want with the playbook configs.
323-
324- ### Raises
325- - ``ValueError`` if the playbook configs are invalid.
326- """
327- merged_configs = []
328- for config in self .config :
329- merged_configs .append (copy .deepcopy (config ))
330-
331- self .want = []
332- for config in merged_configs :
333- self .want .append (copy .deepcopy (config ))
334-
335- # Keeping this function to check lower NDFC version support. yet to get data
335+ # Keeping this function to check lower NDFC version support. yet to get data from Mike
336336 def get_controller_version (self ):
337337 """
338338 ### Summary
@@ -389,7 +389,8 @@ def commit(self) -> None:
389389
390390 msg = f"ENTERED: { self .class_name } .{ method_name } "
391391 self .log .debug (msg )
392-
392+
393+ self .validate_input ()
393394 self .get_want ()
394395
395396 self .fab_association = FabricAssociations ()
@@ -480,7 +481,9 @@ def commit(self) -> None:
480481
481482 msg = f"ENTERED: { self .class_name } .{ method_name } "
482483 self .log .debug (msg )
483-
484+ self .get_controller_version ()
485+ ### Version validation needs to be added
486+ self .validate_input ()
484487 self .get_want ()
485488
486489 self .add .results = self .results
@@ -582,14 +585,14 @@ def commit(self) -> None:
582585 query the fabrics.
583586 """
584587 self .verify_payload ()
585- self .get_want_query ()
588+ self .get_want ()
586589 fabric_query = childFabricQuery ()
587590 fabric_query .rest_send = self .rest_send
588591 fabric_query .results = self .results
589592
590593 fabric_names_to_query = []
591- for want in self .want :
592- fabric_names_to_query .append (want [ "FABRIC_NAME " ])
594+ for item in self .payloads :
595+ fabric_names_to_query .append (item [ "destFabric " ])
593596 try :
594597 fabric_query .fabric_names = copy .copy (fabric_names_to_query )
595598 except ValueError as error :
0 commit comments