@@ -95,7 +95,7 @@ def parse_tags(tags_string: str) -> List[Dict[str, str]]:
95
95
def process_row (row : Dict [str , str ], pbar : tqdm , netbox_instance : pynetbox .api ) -> None :
96
96
"""
97
97
Process a single row from the CSV file and update/create IP addresses in Netbox.
98
-
98
+
99
99
Args:
100
100
row (Dict[str, str]): Dictionary representing a single row from the CSV file
101
101
pbar (tqdm): Progress bar instance
@@ -114,12 +114,28 @@ def process_row(row: Dict[str, str], pbar: tqdm, netbox_instance: pynetbox.api)
114
114
tags_list = parse_tags (row ['tags' ])
115
115
logger .debug (f"Parsed tags for { address } : { tags_list } " )
116
116
117
- # Prepare tenant and VRF data
117
+ # Prepare tenant data
118
118
tenant_data = {'name' : row ['tenant' ]} if row ['tenant' ] != 'N/A' else None
119
- vrf_data = {'name' : row ['VRF' ]} if row ['VRF' ] != 'N/A' else None
120
-
121
- # Get existing address
122
- existing_address = netbox_instance .ipam .ip_addresses .get (address = address )
119
+
120
+ # Look up VRF by name
121
+ vrf_data = None
122
+ if row ['VRF' ] != 'N/A' :
123
+ try :
124
+ vrf = netbox_instance .ipam .vrfs .get (name = row ['VRF' ])
125
+ if vrf :
126
+ # Convert VRF object to a dictionary with just the ID
127
+ vrf_data = {'id' : vrf .id }
128
+ logger .debug (f"Found VRF { row ['VRF' ]} with ID { vrf .id } " )
129
+ else :
130
+ logger .warning (f"VRF { row ['VRF' ]} not found in Netbox" )
131
+ except Exception as e :
132
+ logger .error (f"Error looking up VRF { row ['VRF' ]} : { str (e )} " )
133
+
134
+ # Get existing address - use the VRF ID
135
+ existing_address = netbox_instance .ipam .ip_addresses .get (
136
+ address = address ,
137
+ vrf_id = vrf_data ['id' ] if vrf_data else None
138
+ )
123
139
124
140
if existing_address :
125
141
_update_existing_address (
0 commit comments