11#!/usr/bin/python
22#
3- # Copyright (c) 2020-2023 Cisco and/or its affiliates.
3+ # Copyright (c) 2020-2025 Cisco and/or its affiliates.
44#
55# Licensed under the Apache License, Version 2.0 (the "License");
66# you may not use this file except in compliance with the License.
@@ -605,6 +605,7 @@ def find_dict_in_list_by_key_value(search: list, key: str, value: str):
605605 def diff_for_attach_deploy (self , want_a , have_a , replace = False ):
606606
607607 attach_list = []
608+ atch_tor_ports = []
608609
609610 if not want_a :
610611 return attach_list
@@ -628,7 +629,6 @@ def diff_for_attach_deploy(self, want_a, have_a, replace=False):
628629 if have .get ("torports" ):
629630 for tor_h in have ["torports" ]:
630631 if tor_w ["switch" ] == tor_h ["switch" ]:
631- atch_tor_ports = []
632632 torports_present = True
633633 h_tor_ports = tor_h ["torPorts" ].split ("," ) if tor_h ["torPorts" ] else []
634634 w_tor_ports = tor_w ["torPorts" ].split ("," ) if tor_w ["torPorts" ] else []
@@ -668,9 +668,10 @@ def diff_for_attach_deploy(self, want_a, have_a, replace=False):
668668 else :
669669 # Dont update torports_configured to True.
670670 # If at all there is any other config change, this attach to will be appended attach_list there
671+ torconfig_list = []
671672 for tor_h in have .get ("torports" ):
672- torconfig = tor_h ["switch" ] + "(" + tor_h ["torPorts" ] + ")"
673- want .update ({"torPorts" : torconfig })
673+ torconfig_list . append ( tor_h ["switch" ] + "(" + tor_h ["torPorts" ] + ")" )
674+ want .update ({"torPorts" : " " . join ( torconfig_list ) })
674675
675676 del have ["torports" ]
676677
@@ -750,9 +751,10 @@ def diff_for_attach_deploy(self, want_a, have_a, replace=False):
750751 continue
751752 del want ["isAttached" ]
752753 if want .get ("torports" ):
754+ torconfig_list = []
753755 for tor_w in want ["torports" ]:
754- torconfig = tor_w ["switch" ] + "(" + tor_w ["torPorts" ] + ")"
755- want .update ({"torPorts" : torconfig })
756+ torconfig_list . append ( tor_w ["switch" ] + "(" + tor_w ["torPorts" ] + ")" )
757+ want .update ({"torPorts" : " " . join ( torconfig_list ) })
756758 del want ["torports" ]
757759 want .update ({"deployment" : True })
758760 attach_list .append (want )
@@ -774,9 +776,10 @@ def diff_for_attach_deploy(self, want_a, have_a, replace=False):
774776 if not found :
775777 if bool (want ["isAttached" ]):
776778 if want .get ("torports" ):
779+ torconfig_list = []
777780 for tor_w in want ["torports" ]:
778- torconfig = tor_w ["switch" ] + "(" + tor_w ["torPorts" ] + ")"
779- want .update ({"torPorts" : torconfig })
781+ torconfig_list . append ( tor_w ["switch" ] + "(" + tor_w ["torPorts" ] + ")" )
782+ want .update ({"torPorts" : " " . join ( torconfig_list ) })
780783 del want ["torports" ]
781784 del want ["isAttached" ]
782785 want ["deployment" ] = True
@@ -848,11 +851,11 @@ def update_attach_params(self, attach, net_name, deploy):
848851 attach .update ({"freeformConfig" : "" })
849852 attach .update ({"is_deploy" : deploy })
850853 if attach .get ("tor_ports" ):
851- torports = {}
852854 if role .lower () != "leaf" :
853855 msg = "tor_ports for Networks cannot be attached to switch {0} with role {1}" .format (attach ["ip_address" ], role )
854856 self .module .fail_json (msg = msg )
855857 for tor in attach .get ("tor_ports" ):
858+ torports = {}
856859 torports .update ({"switch" : self .inventory_data [tor ["ip_address" ]].get ("logicalName" )})
857860 torports .update ({"torPorts" : "," .join (tor ["ports" ])})
858861 torlist .append (torports )
@@ -2062,9 +2065,10 @@ def get_diff_merge(self, replace=False):
20622065 # Saftey check
20632066 if attach .get ("isAttached" ):
20642067 if attach .get ("torports" ):
2068+ torconfig_list = []
20652069 for tor_w in attach ["torports" ]:
2066- torconfig = tor_w ["switch" ] + "(" + tor_w ["torPorts" ] + ")"
2067- attach .update ({"torPorts" : torconfig })
2070+ torconfig_list . append ( tor_w ["switch" ] + "(" + tor_w ["torPorts" ] + ")" )
2071+ attach .update ({"torPorts" : " " . join ( torconfig_list ) })
20682072 del attach ["torports" ]
20692073 del attach ["isAttached" ]
20702074 atch_list .append (attach )
0 commit comments