|
2 | 2 |
|
3 | 3 | Reads router_grid.csv with column headers and applies configurations |
4 | 4 | using the NCM library's patch_configuration_managers method. |
5 | | -Also sets custom1 and custom2 fields when present in CSV. |
| 5 | +Also sets desc, custom1 and custom2 fields when present in CSV. |
6 | 6 |
|
7 | 7 | To use this script: |
8 | 8 | 1. Export router_grid.csv from the Device View in NCM |
9 | 9 | 2. Use NCM's device-level Edit Config screen to build your configuration |
10 | 10 | 3. Copy the pending config output and paste it into the build_config return value |
11 | 11 | 4. Update router_grid.csv to contain the columns that need to be applied to the device level config |
12 | 12 | 5. Update build_config to reference router_grid column headers with row_data.get('column_name') |
13 | | -6. If not included in router_grid.csv, add custom1 and/or custom2 columns to set those feilds |
| 13 | +6. If not included in router_grid.csv, add desc, custom1 and/or custom2 columns to set those fields |
14 | 14 | 7. Update csv_file variable if using a different filename than 'router_grid.csv' |
15 | 15 | 8. Update API keys below with your NCM API credentials |
16 | 16 | """ |
|
24 | 24 |
|
25 | 25 | # Update these API keys with your NCM credentials |
26 | 26 | api_keys: Dict[str, str] = { |
27 | | - "X-CP-API-ID": "5d4b40cd", |
28 | | - "X-CP-API-KEY": "4c1108d8b2da465588bb87bfe0cbbd2c", |
29 | | - "X-ECM-API-ID": "f7f08d19-61fe-49de-b634-f2629164de6b", |
30 | | - "X-ECM-API-KEY": "3f76025848c1dcd66731e4d838d0dd0a7bf27e09" |
| 27 | + "X-CP-API-ID": "", |
| 28 | + "X-CP-API-KEY": "", |
| 29 | + "X-ECM-API-ID": "", |
| 30 | + "X-ECM-API-KEY": "" |
31 | 31 | } |
32 | 32 | n2: ncm.NcmClientv2 = ncm.NcmClientv2(api_keys=api_keys) |
33 | 33 |
|
@@ -179,14 +179,20 @@ def main() -> None: |
179 | 179 | |
180 | 180 | Processes each router in the CSV file by: |
181 | 181 | 1. Applying device configuration using patch_configuration_managers |
182 | | - 2. Setting custom1 field if column exists and has non-empty value |
183 | | - 3. Setting custom2 field if column exists and has non-empty value |
| 182 | + 2. Injecting desc into config[0][system][desc] if column exists and has non-empty value |
| 183 | + 3. Setting custom1 field if column exists and has non-empty value |
| 184 | + 4. Setting custom2 field if column exists and has non-empty value |
184 | 185 | """ |
185 | 186 | rows = load_csv(csv_file) |
186 | 187 |
|
187 | 188 | for router_id, row_data in rows.items(): |
188 | 189 | try: |
189 | 190 | config = {'configuration': build_config(row_data)} |
| 191 | + |
| 192 | + desc_value: Optional[str] = row_data.get('desc') |
| 193 | + if desc_value and desc_value != '': |
| 194 | + config['configuration'][0]['system']['desc'] = desc_value |
| 195 | + |
190 | 196 | n2.patch_configuration_managers( |
191 | 197 | router_id=router_id, config_man_json=config) |
192 | 198 |
|
|
0 commit comments