Repository: napalm-automation/napalm

Issue:
IOS get_network_instances fails 'KeyError' when deleting item from interfaces
### Description of Issue/Question

Issue with ios driver for getting VRFs. On Cat3850 running Fuji 16.9.x code, when performing the `get_network_instances` line 3431 (deleting items from interfaces from network instances nested dict) returns an error: `line 3431, in get_network_instances
    del instances["default"]["interfaces"]["interface"][item]
KeyError: 'LI18/2'` 

Suggestion is to set conditional statement:
```
 if item in instances["default"]["interfaces"]["interface"]:
     del instances["default"]["interfaces"]["interface"][item]
```
*Note*: Please check https://guides.github.com/features/mastering-markdown/
to see how to properly format your request.

### Did you follow the steps from https://github.com/napalm-automation/napalm#faq
(Place an ``x`` between the square brackets where applicable)

- [] Yes
- [X] No


### Setup

### napalm version
(Paste verbatim output from `pip freeze | grep napalm` between quotes below)

```
napalm==3.2.0
nornir-napalm==0.1.1
```

### Network operating system version
(Paste verbatim output from `show version` - or equivalent - between quotes below)

```
Switch Ports Model              SW Version        SW Image              Mode   
------ ----- -----              ----------        ----------            ----   
*    1 62    WS-C3850-12X48U    16.9.4            CAT3K_CAA-UNIVERSALK9 INSTALL
     2 62    WS-C3850-12X48U    16.9.4            CAT3K_CAA-UNIVERSALK9 INSTALL
     3 62    WS-C3850-12X48U    16.9.4            CAT3K_CAA-UNIVERSALK9 INSTALL
```

### Steps to Reproduce the Issue

### Error Traceback
(Paste the complete traceback of the exception between quotes below)

```
2021-03-03 09:36:49,204 - nornir.core.task -    ERROR -      start() - Host 'SANITIZED': task 'napalm_get' failed with traceback:
Traceback (most recent call last):
  File "/Users/SANITIZED/Documents/Private/python_projects/Network_Automation/lib/python3.9/site-packages/nornir/core/task.py", line 98, in start
    r = self.task(self, **self.params)
  File "/Users/SANITIZED/Documents/Private/python_projects/Network_Automation/lib/python3.9/site-packages/nornir_napalm/plugins/tasks/napalm_get.py", line 44, in napalm_get
    result[g] = method(**options)
  File "/Users/SANITIZED/Documents/Private/python_projects/Network_Automation/lib/python3.9/site-packages/napalm/ios/ios.py", line 3431, in get_network_instances
    del instances["default"]["interfaces"]["interface"][item]
KeyError: 'LI18/2'

```



Discussion:
what is this issue waiting for? I can make the PR if that's what's missing
Yep, a PR would do it @DavidVentura, cheers!

Resolving patch:
diff --git a/napalm/ios/ios.py b/napalm/ios/ios.py
--- a/napalm/ios/ios.py
+++ b/napalm/ios/ios.py
@@ -3442,7 +3442,8 @@ def get_network_instances(self, name=""):
 
             # remove interfaces in the VRF from the default VRF
             for item in interfaces:
-                del instances["default"]["interfaces"]["interface"][item]
+                if item in instances["default"]["interfaces"]["interface"]:
+                    del instances["default"]["interfaces"]["interface"][item]
 
             instances[vrf_name] = {
                 "name": vrf_name,


Test patch: