IndentationError期望网络自动化的缩进块

时间:2015-11-14 16:51:58

标签: python

设置代码在我的cisco设备中运行命令 - 缓存输出并查询结果,但如果在同一结果中有另一行,则执行它。



peeringip = raw_input("Enter the customer's peering IP : ")
    print
    print
    sitee = raw_input('Enter the Site(/col/ash/')
    site = sitee.upper()
    def cisco(routername,shrninc,showipint,showtunnel,shipprefix):
    	conn = SSH2()
    	conn.connect(routername)
    	conn.login(account1)
    	conn.execute('Terminal Length 0')
    	bgpstatements = shrninc + peeringip
    	print "Router Name: ",routername
    	conn.execute(bgpstatements)
    	showcomoutputbgp = conn.response
    	if 'neighbor' in showcomoutputbgp:
    	  print "============"
    	  print "-------------------"
    	  print "============"
    	  print "-------------------"
    	  print
    	  print "BGP configuration : ",conn.response
    	  print
    	  print "CHECKING PREFIX-LIST"
   	elif 'ROUTE' in showcomoutputbgp:
   		chkprefix = re.search("ROUTE",showcomoutputbgp)
   		prefix_name = chkprefix.group()
   		locate_prefix = shipprefix + prefix_name
   		conn.execute(locate_prefix)
   		print "PREFIX-LIST INFO : "
    	else:
    	print "No BGP neighbor"




Elif没有输出...

2 个答案:

答案 0 :(得分:0)

由于if语句,您需要缩进此部分。此外,您可以添加以前的打印件,而不是所有空白打印件。它使它看起来更整洁,更容易阅读。

def cisco(routername,shrninc,showipint,showtunnel,shipprefix):
    conn = SSH2()
    conn.connect(routername)
    conn.login(account1)
    conn.execute('Terminal Length 0')
    bgpstatements = shrninc + peeringip
    print "Router Name: ",routername
    conn.execute(bgpstatements)
    showcomoutputbgp = conn.response
    if 'neighbor' in showcomoutputbgp:
        print "============"
        print "-------------------"
        print "============"
        print "-------------------\n"
        print "BGP configuration : ",conn.response + "\n"
        print "CHECKING PREFIX-LIST"
    elif 'prefix-list' in showcomoutputbgp:
        chkprefix = re.search(r'(prefix-list)',showcomoutputbgp)
        prefix_name = chkprefix.group()
        locate_prefix = shipprefix + prefix_name
        conn.execute(locate_prefix)
        print "PREFIX-LIST INFO : ",conn.response + "\n" 
    else:
        print "No BGP neighbor"" 

答案 1 :(得分:0)

def cisco(routername,shrninc,showipint,showtunnel,shipprefix):
	conn = SSH2()
	conn.connect(routername)
	conn.login(account1)
	conn.execute('Terminal Length 0')
	bgpstatements = shrninc + peeringip
	print "Router Name: ",routername
	conn.execute(bgpstatements)
	showcomoutputbgp = conn.response
	if 'neighbor' in showcomoutputbgp:
		print "============"
		print "-------------------"
		print "============"
		print "-------------------"
		print
		print "BGP configuration : ",conn.response
		print
		print "CHECKING PREFIX-LIST"
	elif 'prefix-list' in showcomoutputbgp:
		chkprefix = re.search(r'(prefix-list)',showcomoutputbgp)
		prefix_name = chkprefix.group()
		locate_prefix = shipprefix + prefix_name
		conn.execute(locate_prefix)
		print "PREFIX-LIST INFO : ",conn.response
		print 
	else:
		print "No BGP neighbor"