components/openstack/neutron/files/neutron-l3-agent
branchs11u2-sru
changeset 3364 25975ce9e810
parent 3198 46289f36c1ca
child 3998 5bd484384122
equal deleted inserted replaced
3363:fc202c871763 3364:25975ce9e810
    79     ippool_names = []
    79     ippool_names = []
    80     for ipf in ipfilters:
    80     for ipf in ipfilters:
    81         if not prog.search(ipf):
    81         if not prog.search(ipf):
    82             continue
    82             continue
    83         # capture the IP pool name
    83         # capture the IP pool name
    84         ippool_names.append(ipf.split('pool/')[1])
    84         if 'pool/' in ipf:
       
    85             ippool_names.append(ipf.split('pool/')[1])
    85 
    86 
    86         try:
    87         try:
    87             # remove the IP Filter rule
    88             # remove the IP Filter rule
    88             p = Popen(["echo", ipf], stdout=PIPE)
    89             p = Popen(["echo", ipf], stdout=PIPE)
    89             cmd = ["/usr/bin/pfexec", "/usr/sbin/ipf", "-r", "-f", "-"]
    90             cmd = ["/usr/bin/pfexec", "/usr/sbin/ipf", "-r", "-f", "-"]
   110         # first kill the SMF contract
   111         # first kill the SMF contract
   111         check_call(["/usr/bin/pkill", "-c", sys.argv[2]])
   112         check_call(["/usr/bin/pkill", "-c", sys.argv[2]])
   112     except CalledProcessError as err:
   113     except CalledProcessError as err:
   113         print "failed to kill the SMF contract: %s" % (err)
   114         print "failed to kill the SMF contract: %s" % (err)
   114         return smf_include.SMF_EXIT_ERR_FATAL
   115         return smf_include.SMF_EXIT_ERR_FATAL
   115     # remove VNICs associated with L3 agent
       
   116     cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
       
   117     p = Popen(cmd, stdout=PIPE, stderr=PIPE)
       
   118     output, error = p.communicate()
       
   119     if p.returncode != 0:
       
   120         print "failed to retrieve IP interface names"
       
   121         return smf_include.SMF_EXIT_ERR_CONFIG
       
   122 
   116 
   123     ifnames = output.splitlines()
   117     # We need to first remove the IP filter rules and then remove
   124     # L3 agent datalinks are always 15 characters in length. They start
   118     # the IP interfaces on which the rules were applied.
   125     # with either 'l3i' or 'l3e', end with '_0', and in between they are
       
   126     # hexadecimal digits.
       
   127     prog = re.compile('l3[ie][0-9A-Fa-f\_]{10}_0')
       
   128     for ifname in ifnames:
       
   129         if not prog.search(ifname):
       
   130             continue
       
   131         try:
       
   132             # first remove the IP
       
   133             check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
       
   134                         ifname])
       
   135             # next remove the VNIC
       
   136             check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
       
   137                         ifname])
       
   138         except CalledProcessError as err:
       
   139             print "failed to remove datalinks used by L3 agent: %s" % (err)
       
   140             return smf_include.SMF_EXIT_ERR_FATAL
       
   141 
   119 
   142     # remove IPv4 Filter rules added by neutron-l3-agent
   120     # remove IPv4 Filter rules added by neutron-l3-agent
   143     rv = remove_ipfilter_rules(4)
   121     rv = remove_ipfilter_rules(4)
   144     if rv != smf_include.SMF_EXIT_OK:
   122     if rv != smf_include.SMF_EXIT_OK:
   145         return rv
   123         return rv
   171                        stdin=p.stdout)
   149                        stdin=p.stdout)
   172         except CalledProcessError as err:
   150         except CalledProcessError as err:
   173             print "failed to remove IP NAT rule %s: %s" % (ipnat_rule, err)
   151             print "failed to remove IP NAT rule %s: %s" % (ipnat_rule, err)
   174             return smf_include.SMF_EXIT_ERR_FATAL
   152             return smf_include.SMF_EXIT_ERR_FATAL
   175 
   153 
       
   154     # remove VNICs associated with L3 agent
       
   155     cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
       
   156     p = Popen(cmd, stdout=PIPE, stderr=PIPE)
       
   157     output, error = p.communicate()
       
   158     if p.returncode != 0:
       
   159         print "failed to retrieve IP interface names"
       
   160         return smf_include.SMF_EXIT_ERR_CONFIG
       
   161 
       
   162     ifnames = output.splitlines()
       
   163     # L3 agent datalinks are always 15 characters in length. They start
       
   164     # with either 'l3i' or 'l3e', end with '_0', and in between they are
       
   165     # hexadecimal digits.
       
   166     prog = re.compile('l3[ie][0-9A-Fa-f\_]{10}_0')
       
   167     for ifname in ifnames:
       
   168         if not prog.search(ifname):
       
   169             continue
       
   170         try:
       
   171             # first remove the IP
       
   172             check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
       
   173                         ifname])
       
   174             # next remove the VNIC
       
   175             check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
       
   176                         ifname])
       
   177         except CalledProcessError as err:
       
   178             print "failed to remove datalinks used by L3 agent: %s" % (err)
       
   179             return smf_include.SMF_EXIT_ERR_FATAL
       
   180 
   176     return smf_include.SMF_EXIT_OK
   181     return smf_include.SMF_EXIT_OK
   177 
   182 
   178 if __name__ == "__main__":
   183 if __name__ == "__main__":
   179     os.putenv("LC_ALL", "C")
   184     os.putenv("LC_ALL", "C")
   180     smf_include.smf_main()
   185     smf_include.smf_main()