From bf6948cbaf9fd4e1bf94ced5c3dafa9e9d9a6dd0 Mon Sep 17 00:00:00 2001 From: Sapan Bhatia Date: Thu, 29 Mar 2012 10:52:45 -0400 Subject: [PATCH] Make deletion optional in vif_down --- exec/vif_down | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/exec/vif_down b/exec/vif_down index 8c270eb..fe121c7 100755 --- a/exec/vif_down +++ b/exec/vif_down @@ -10,7 +10,7 @@ import sys import pwd import os import re - +import string if len(sys.argv) != 2: sys.exit(1) @@ -19,9 +19,41 @@ slicename=sys.argv[1] sliceid = pwd.getpwnam(slicename).pw_uid -# Read interface name -vif = sys.stdin.readline().strip() # interface name +arglines = map(string.strip, sys.stdin.readlines()) + +if len(arglines)<1: + print >>sys.stderr, "Insufficient argument lines." + sys.exit(1) + +vif = arglines[0] # interface name + +# Create options list +if len(arglines)>1: + options = arglines[1:] +else: + options = [] + +opt_delete = False + +for optionline in options: + if len(optionline)==0: continue + try: + opt, val = optionline.split('=') + except: + print >>sys.stderr, "Bad option line: \"%s\"" % (optionline) + sys.exit(1) + if opt=="delete": + if val=="0": + opt_delete=False + elif val=="1": + opt_delete=True + else: + print >>sys.stderr, "rp_filter value invalid: \"%s\"" % (val) + sys.exit(1) + else: + print >>sys.stderr, "Unknown option: \"%s\"" % (opt) + sys.exit(1) # Validate interface name if len(vif)>16: @@ -52,4 +84,5 @@ cmd_ifconfig = "/sbin/ifconfig %s down" % (vif) os.system(cmd_ifconfig) # Delete GRE tunnel (if any) -os.system(cmd_gre_del) +if (opt_delete): + os.system(cmd_gre_del) -- 2.43.0