netdevops / hier_config

Hierarchical Configuration
MIT License
128 stars 24 forks source link

Future config #99

Closed aedwardstx closed 3 years ago

aedwardstx commented 3 years ago

Add a method to predict the running config after a change is applied

This feature is useful in cases where you need to determine what the configuration state will be after a change is applied. Such as:

In [1]: from hier_config import HConfig, Host
   ...:
   ...:
   ...: host = Host("test.dfw1", "ios")
   ...: running_config = HConfig(host)
   ...: running_config.load_from_file("./tests/fixtures/running_config.conf")
   ...: remediation_config = HConfig(host)
   ...: remediation_config.load_from_file("./tests/fixtures/remediation_config_without_tags.conf")
   ...: future_config = running_config.future(remediation_config)
   ...:
   ...: print("\n##### running config")
   ...: for line in running_config.all_children():
   ...:     print(line.cisco_style_text())
   ...:
   ...: print("\n##### remediation config")
   ...: for line in remediation_config.all_children():
   ...:     print(line.cisco_style_text())
   ...:
   ...: print("\n##### future config")
   ...: for line in future_config.all_children():
   ...:     print(line.cisco_style_text())
   ...:

##### running config
hostname aggr-example.rtr
ip access-list extended TEST
  10 permit ip 10.0.0.0 0.0.0.7 any
vlan 2
  name switch_mgmt_10.0.2.0/24
vlan 3
  name switch_mgmt_10.0.4.0/24
interface Vlan2
  descripton switch_10.0.2.0/24
  ip address 10.0.2.1 255.255.255.0
  shutdown
interface Vlan3
  mtu 9000
  description switch_mgmt_10.0.4.0/24
  ip address 10.0.4.1 255.255.0.0
  ip access-group TEST in
  no shutdown

##### remediation config
vlan 3
  name switch_mgmt_10.0.3.0/24
vlan 4
  name switch_mgmt_10.0.4.0/24
interface Vlan2
  mtu 9000
  ip access-group TEST in
  no shutdown
interface Vlan3
  description switch_mgmt_10.0.3.0/24
  ip address 10.0.3.1 255.255.0.0
interface Vlan4
  mtu 9000
  description switch_mgmt_10.0.4.0/24
  ip address 10.0.4.1 255.255.0.0
  ip access-group TEST in
  no shutdown

##### future config
vlan 3
  name switch_mgmt_10.0.3.0/24
vlan 4
  name switch_mgmt_10.0.4.0/24
interface Vlan2
  mtu 9000
  ip access-group TEST in
  descripton switch_10.0.2.0/24
  ip address 10.0.2.1 255.255.255.0
interface Vlan3
  description switch_mgmt_10.0.3.0/24
  ip address 10.0.3.1 255.255.0.0
  mtu 9000
  ip address 10.0.4.1 255.255.0.0
  ip access-group TEST in
  no shutdown
interface Vlan4
  mtu 9000
  description switch_mgmt_10.0.4.0/24
  ip address 10.0.4.1 255.255.0.0
  ip access-group TEST in
  no shutdown
hostname aggr-example.rtr
ip access-list extended TEST
  10 permit ip 10.0.0.0 0.0.0.7 any
vlan 2
  name switch_mgmt_10.0.2.0/24