@@ -509,6 +509,7 @@ def __init__(self, module):
509
509
self .node_migration = False
510
510
self .nd_prefix = "/appcenter/cisco/ndfc/api/v1/lan-fabric"
511
511
self .switch_snos = []
512
+ self .diff_input_format = []
512
513
513
514
self .result = dict (changed = False , diff = [], response = [])
514
515
@@ -1811,6 +1812,120 @@ def failure(self, resp):
1811
1812
1812
1813
self .module .fail_json (msg = res )
1813
1814
1815
+ def format_diff (self ):
1816
+ """
1817
+ Format the diff for inventory operations
1818
+ """
1819
+ diff = []
1820
+ create_list = []
1821
+ preprovision_list = []
1822
+ bootstrap_list = []
1823
+ rma_list = []
1824
+ delete_list = []
1825
+
1826
+ # Add created switches to the diff
1827
+ for create in self .diff_create :
1828
+ if create .get ("switches" ) and len (create ["switches" ]) > 0 :
1829
+ switch = create ["switches" ][0 ]
1830
+ item = {
1831
+ "ip_address" : switch .get ("ipaddr" ),
1832
+ "serial_number" : switch .get ("serialNumber" ),
1833
+ "role" : create .get ("role" ),
1834
+ "platform" : switch .get ("platform" ),
1835
+ "version" : switch .get ("version" ),
1836
+ "hostname" : switch .get ("sysName" ),
1837
+ "preserve_config" : create .get ("preserveConfig" , False )
1838
+ }
1839
+ create_list .append (item )
1840
+
1841
+ if create_list :
1842
+ create_item = {
1843
+ "action" : "create" ,
1844
+ "switches" : create_list
1845
+ }
1846
+ diff .append (create_item )
1847
+
1848
+ # Add POAP switches to the diff
1849
+ for poap in self .want_create_poap :
1850
+ item = {
1851
+ "ip_address" : poap .get ("ipAddress" ),
1852
+ "role" : poap .get ("role" ),
1853
+ "hostname" : poap .get ("hostname" ),
1854
+ "platform" : poap .get ("model" ),
1855
+ "version" : poap .get ("version" )
1856
+ }
1857
+ if poap .get ("serialNumber" ):
1858
+ item ["serial_number" ] = poap .get ("serialNumber" )
1859
+ bootstrap_list .append (item )
1860
+ if poap .get ("preprovisionSerial" ):
1861
+ item ["preprovision_serial" ] = poap .get ("preprovisionSerial" )
1862
+ preprovision_list .append (item )
1863
+
1864
+ if bootstrap_list :
1865
+ diff .append ({
1866
+ "action" : "bootstrap" ,
1867
+ "bootstrap_switches" : bootstrap_list
1868
+ })
1869
+ if preprovision_list :
1870
+ diff .append ({
1871
+ "action" : "preprovision" ,
1872
+ "preprovision_switches" : preprovision_list
1873
+ })
1874
+
1875
+ # Add RMA switches to the diff
1876
+ for rma in self .want_create_rma :
1877
+ item = {
1878
+ "ip_address" : rma .get ("ipAddress" ),
1879
+ "old_serial" : rma .get ("oldSerialNumber" ),
1880
+ "new_serial" : rma .get ("newSerialNumber" ),
1881
+ "platform" : rma .get ("model" ),
1882
+ "version" : rma .get ("version" )
1883
+ }
1884
+ rma_list .append (item )
1885
+
1886
+ if rma_list :
1887
+ diff .append ({
1888
+ "action" : "rma" ,
1889
+ "rma_switches" : rma_list
1890
+ })
1891
+
1892
+ # Add deleted switches to the diff
1893
+ for serial in self .diff_delete :
1894
+ ip_address = None
1895
+ hostname = None
1896
+ for have_c in self .have_create :
1897
+ if have_c ["switches" ][0 ]["serialNumber" ] == serial :
1898
+ ip_address = have_c ["switches" ][0 ]["ipaddr" ]
1899
+ hostname = have_c ["switches" ][0 ]["sysName" ]
1900
+ role = have_c ["switches" ][0 ]["role" ]
1901
+ platform = have_c ["switches" ][0 ]["platform" ]
1902
+ version = have_c ["switches" ][0 ]["version" ]
1903
+ break
1904
+
1905
+ item = {
1906
+ "serial_number" : serial
1907
+ }
1908
+ if ip_address :
1909
+ item ["ip_address" ] = ip_address
1910
+ if hostname :
1911
+ item ["hostname" ] = hostname
1912
+ if role :
1913
+ item ["role" ] = role
1914
+ if platform :
1915
+ item ["platform" ] = platform
1916
+ if version :
1917
+ item ["version" ] = version
1918
+
1919
+ delete_list .append (item )
1920
+
1921
+ if delete_list :
1922
+ diff .append ({
1923
+ "action" : "delete" ,
1924
+ "switches" : delete_list
1925
+ })
1926
+
1927
+ self .diff_input_format = diff
1928
+
1814
1929
1815
1930
def main ():
1816
1931
"""main entry point for module execution"""
@@ -1943,6 +2058,8 @@ def main():
1943
2058
if module .params ["deploy" ]:
1944
2059
dcnm_inv .config_deploy ()
1945
2060
2061
+ dcnm_inv .format_diff ()
2062
+ dcnm_inv .result ["diff" ] = dcnm_inv .diff_input_format
1946
2063
module .exit_json (** dcnm_inv .result )
1947
2064
1948
2065
0 commit comments