Skip to content

Commit d2ec523

Browse files
authored
updated to inject desc into config (#68)
* Updated bulk config to use ncm library Updated bulk config to use ncm library * updated to include support for custom1/2 feilds * updated to inject description into config
1 parent b9121d4 commit d2ec523

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

bulk_config/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# bulk_config.py
22

3-
Bulk configure devices in NCM from router_grid.csv file using column headers. Also sets custom1 and custom2 fields when values are provided in the CSV.
3+
Bulk configure devices in NCM from router_grid.csv file using column headers. Also injects desc into config and sets custom1 and custom2 fields when values are provided in the CSV.
44

55
## Setup
66

7-
1. Install dependencies:
7+
1. Install dependencies from requirements.txt:
88
```bash
99
pip install -r requirements.txt
1010
```
11+
This will install the required NCM library to run the script.
1112

1213
## Usage
1314

@@ -25,7 +26,7 @@ Bulk configure devices in NCM from router_grid.csv file using column headers. Al
2526

2627
## Custom Fields
2728

28-
The script automatically sets custom1 and custom2 fields for each router when these columns are present in the CSV and contain non-empty values. Simply add `custom1` and/or `custom2` columns to your router_grid.csv file.
29+
The script automatically injects desc into the configuration at [0][system][desc] when the desc column is present in the CSV and contains a non-empty value. It also sets custom1 and custom2 fields for each router when these columns are present in the CSV and contain non-empty values. Simply add `desc`, `custom1` and/or `custom2` columns to your router_grid.csv file.
2930

3031
## Example
3132

@@ -34,8 +35,7 @@ For the included router_grid.csv with columns `id`, `name`, `desc`, `asset_id`,
3435
```python
3536
"system": {
3637
"system_id": row_data.get('name', ''),
37-
"asset_id": row_data.get('asset_id', ''),
38-
"desc": row_data.get('desc', '')
38+
"asset_id": row_data.get('asset_id', '')
3939
},
4040
"lan": {
4141
"00000000-0d93-319d-8220-4a1fb0372b51": {

bulk_config/bulk_config.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
33
Reads router_grid.csv with column headers and applies configurations
44
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.
66
77
To use this script:
88
1. Export router_grid.csv from the Device View in NCM
99
2. Use NCM's device-level Edit Config screen to build your configuration
1010
3. Copy the pending config output and paste it into the build_config return value
1111
4. Update router_grid.csv to contain the columns that need to be applied to the device level config
1212
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
1414
7. Update csv_file variable if using a different filename than 'router_grid.csv'
1515
8. Update API keys below with your NCM API credentials
1616
"""
@@ -24,10 +24,10 @@
2424

2525
# Update these API keys with your NCM credentials
2626
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": ""
3131
}
3232
n2: ncm.NcmClientv2 = ncm.NcmClientv2(api_keys=api_keys)
3333

@@ -179,14 +179,20 @@ def main() -> None:
179179
180180
Processes each router in the CSV file by:
181181
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
184185
"""
185186
rows = load_csv(csv_file)
186187

187188
for router_id, row_data in rows.items():
188189
try:
189190
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+
190196
n2.patch_configuration_managers(
191197
router_id=router_id, config_man_json=config)
192198

0 commit comments

Comments
 (0)