This solution involves multiple elements.

  1. Trigger Event

The trigger event involves the switch leveraging Embedded Event Manager (EMM) to monitor the CLI for changes. In this particular scenario, EEM is looking for match criteria "copy running-config startup-config." After EEM detects the command, it will invoke a Python script from guest shell called autoconfig.py which is stored in the local switch storage (bootflash)

Here is a sample EEM configuration:

event manager applet gitpush 
event cli match "copy running-config startup-config" 
action 2 cli copy running bootflash:/autoconfig/running.latest 
action 3 cli guestshell run /home/guestshell/autoconfig.py 
action 4 event-default 
  1. LXC Container / Guest Shell

The guest shell is used to host the Python Script and is where the git client is going to be running

  n9k-sw-1# guestshell 
  [guestshell@guestshell ~]$   
  1. Installing Git client

The git client is available as open source package, and can be downloaded directly onto the device through Yum within the guest shell. The git client will allow changes to be pushed first into a local repository, and then pushed to a central configuration store. Y install can be used to grab the git client software:

  guestshell:~$ sudo chvrf management yum install git 

NOTE: In the above sample the management context (VRF - Virtual Routing and Forwarding) is used for connectivity.

  1. Python script

A python script which is triggered directly from the Embedded Event Manager (EEM) will be used to save the configuration change, and use the git APIs to push the changes to the Central Repository.

The script is saved as autoconfig.py which matches the name that was triggered from the Embedded Event Manager (EMM) above. It will take the saved file and schedule it to be committed through the calls to git. Finally a git push is called to push the changes to an external repository. Notice above that vrf management is also used within the script for external connectivity.

The python script for this use case looks like the following:

 #!/usr/bin/python 
  
  import os
  import subprocess
  from subprocess import call
  
  f = open("autoouptput.txt","w") #opens file with name of "test.txt"
  os.chdir("/home/guestshell/autoconfig")
  
  call(["mv", "/bootflash/autoconfig/running.latest", "/home/guestshell/autoconfig/n9k-sw-1/running"])
  call(["git", "add", "n9k-sw-1/running"])
  call(["git", "commit", "-m", "Configuration change"])
  p = subprocess.Popen(['chvrf', 'management', 'git', 'push'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  out, err = p.communicate()
  f.write(out)
  f.write(err)
  f.close  
  1. Git repository

A central git repository is needed to store the checked-in data. This could be an in-house git repository, or a cloud-based community repository such as GitHub.

  1. Verification

When the end user enters a configuration save from the CLI, the central repository store will be updated.

Incremental Configuration on Open NX-OS Switch Archived on Git

Incremental Configuration on Open NX-OS Switch Archived on Git