netdevops / hier_config

Hierarchical Configuration
MIT License
126 stars 24 forks source link

Inconsistent results for ios interfaces #113

Closed joewesch closed 1 year ago

joewesch commented 1 year ago

I am getting inconsistent results when trying to get hier_config to produce the commands to remove a description:

In this first example it provides both the no description and the no ip address commands:

In [1]: from hier_config import Host

In [2]: host = Host(hostname="Test device", os="ios")

In [3]: host.load_generated_config("interface GigabitEthernet1\n  negotiation auto\n  no mop enabled\n  no mop sysid")

In [4]: host.load_running_config("interface GigabitEthernet1\n  description MANAGEMENT_DO_NOT_CHANGE\n  ip address 10.0.0.15 255.255.255.0\n  negotiation auto\n  no mop enabled\n  no mop sysid")

In [5]: print(host.remediation_config())
interface GigabitEthernet1
  no description MANAGEMENT_DO_NOT_CHANGE
  no ip address 10.0.0.15 255.255.255.0

In [6]:

In this second example, however, it produces nothing:

In [1]: from hier_config import Host

In [2]: host = Host(hostname="Test device", os="ios")

In [3]: host.load_generated_config("interface GigabitEthernet4\n  ip address 10.10.0.17 255.255.255.252\n  negotiation auto\n  no mop enabled\n  no mop sysid")

In [4]: host.load_running_config("interface GigabitEthernet4\n  description backbone-to-vmx3-ge0/0/3\n  ip address 10.10.0.17 255.255.255.252\n  negotiation auto\n  no mop enabled\n  no mop sysid")

In [5]: print(host.remediation_config())

In [6]:

I was able to narrow this down to the fact that it has to remove the ip address from GigabitEthernet1. If I remove the ip address from the generated config for GigabitEthernet4 it provides the expected output:

In [1]: from hier_config import Host

In [2]: host = Host(hostname="Test device", os="ios")

In [3]: host.load_generated_config("interface GigabitEthernet4\n  negotiation auto\n  no mop enabled\n  no mop sysid")

In [4]: host.load_running_config("interface GigabitEthernet4\n  description backbone-to-vmx3-ge0/0/3\n  ip address 10.10.0.17 255.255.255.252\n  negotiation auto\n  no mop enabled\n  no mop sysid")

In [5]: print(host.remediation_config())
interface GigabitEthernet4
  no description backbone-to-vmx3-ge0/0/3
  no ip address 10.10.0.17 255.255.255.252

In [6]: