Extreme Switch 설정 변경 확인

익스트림 스위치 프롬프트의 맨 앞 * 표시는 설정 변경된 내용이 있음을 표시해 준다.
그렇다면 어떤 내용이 변경되었는지는 어떻게 확인 할 수 있을까? 시스코 스위치의 show archive config differences 같은 명령어는 발견(?)하지 못했다. 다만, python스크립트를 사용하면 확인 가능하다.

스크립트 이름은 conf_diff.py 이며, 그 내용은 https://github.com/extremenetworks/ExtremeScripting/blob/master/EXOS/Python/conf_diff/conf_diff.py 에서 확인 할 수 있다.
익스트림 스위치에서 파이썬 스크립트는 load script [script_name] 명령어를 사용하여 실행 할 수 있다.

아래 예는 5-10번 포트를 vlan wolf에 할당한 후에 설정을 저장하지 않았음을 보여준다.

* EXOS-VM.20 # load script conf_diff.py
Comparing configurations, please wait...

If line starts with '+', the command has been added since last save.
If line starts with '-', the command was present in the last save, and has been deleted.

Config changes:
+ configure vlan wolf add ports 5-10 untagged
Note that this script has cleared the CLI dirty bit. The configuration has not been saved.

이제 변경된 설정을 저장한다.

* EXOS-VM.21 # save
The configuration file primary.cfg already exists.
Do you want to save configuration to primary.cfg and overwrite it? (y/N) Yes
Saving configuration primary.cfg  on master .. done!
Configuration saved to primary.cfg successfully.

설정 저장 후 스크립트를 실행해 보면 변경된 내용이 없음을 볼 수 있다.

EXOS-VM.22 # load script conf_diff.py
Comparing configurations, please wait...

If line starts with '+', the command has been added since last save.
If line starts with '-', the command was present in the last save, and has been deleted.

Config changes:
Note that this script has cleared the CLI dirty bit. The configuration has not been saved.

스크립트가 존재하는지는 ls 명령으로 확인 할 수 있으며, GNS3 EXOS에는 스크립트가 포함되어 있다. 스크립트가 없다면, vi 편집기로 아래 내용을 편집하여 저장하면 사용할 수 있다.
conf_diff.py 화일의 내용은 아래와 같디.

from exsh import clicmd
from difflib import Differ
from time import time


def main():

    print "Comparing configurations, please wait..."

    #create unique names for temp files

    t_stamp = str(time())

    saved_name = '/usr/local/cfg/saved_{0}.temp'.format(t_stamp[:-3])
    running_name = '/usr/local/cfg/running_{0}.temp'.format(t_stamp[:-3])
    temp_config = 'temp_{0}'.format(t_stamp[:-3])

    saved_file = open(saved_name, 'w')
    running_file = open(running_name, 'w')


    # find the selected config file
    output = clicmd('show switch | include "Config Selected"', True).split()
    selected_config = output[2]
    selected_config = selected_config[:-4]

    # save the running config to a temp file, 
    # then convert both config files from XML to human-readable format

    clicmd("save config {0}".format(temp_config))
    saved_file.write(clicmd("debug cfgmgr show configuration file {0}".format(selected_config), True))
    running_file.write(clicmd("debug cfgmgr show configuration file {0}".format(temp_config), True))

    # set the selected config back, since the save config changed it
    clicmd("use config {0}".format(selected_config), False)

    # close the files, and reopen them for reading
    saved_file.close()
    running_file.close()

    saved_file = open(saved_name, 'r')
    running_file = open(running_name, 'r')

    # diff the two configs


    d = Differ()

    diff = list(d.compare(saved_file.readlines(), running_file.readlines()))

    # print the results of the diff
    print " "
    print "If line starts with \'+\', the command has been added since last save."
    print "If line starts with \'-\', the command was present in the last save, and has been deleted."
    print " "
    print "Config changes:"

    for line in diff:
        if line.startswith('+ ') or line.startswith('- '):
            print line[:-1]

    print "Note that this script has cleared the CLI dirty bit. The configuration has not been saved."
    
    # clean up
    saved_file.close()
    running_file.close()

    # remove files that were opened
    clicmd("rm {0}".format(saved_name))
    clicmd("rm {0}".format(running_name))
    clicmd("rm {0}.cfg".format(temp_config))

if __name__ == '__main__':
    try:
        main()
    except SystemExit:
        # catch SystemExit to prevent EXOS shell from exiting to login prompt
	pass

답글 남기기

Your email address will not be published.