neutron-l3-agent revision 2944
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# Licensed under the Apache License, Version 2.0 (the "License"); you may
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# not use this file except in compliance with the License. You may obtain
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# a copy of the License at
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# Unless required by applicable law or agreed to in writing, software
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# License for the specific language governing permissions and limitations
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano# under the License.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcanofrom subprocess import CalledProcessError, Popen, PIPE, check_call
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand # verify paths are valid
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand if not os.path.exists(f) or not os.access(f, os.R_OK):
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand print '%s does not exist or is not readable' % f
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # System-wide forwarding (either ipv4 or ipv6 or both) must be enabled
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # before neutron-l3-agent can be started.
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = ["/usr/sbin/ipadm", "show-prop", "-c", "-p", "forwarding",
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to determine if IPv4 forwarding is enabled or not"
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = ["/usr/sbin/ipadm", "show-prop", "-c", "-p", "forwarding",
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to determine if IPv6 forwarding is enabled or not"
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "System-wide IPv4 or IPv6 (or both) forwarding must be " \
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano "enabled before enabling neutron-l3-agent"
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = "/usr/lib/neutron/neutron-l3-agent --config-file %s " \
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # remove IP Filter rules added by neutron-l3-agent
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = ["/usr/bin/pfexec", "/usr/sbin/ipfstat", "-io"]
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to retrieve IP Filter rules"
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # L3 agent IP Filter rules are of the form
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # block in quick on l3i64cbb496_a_0 from ... to pool/15417332
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # capture the IP pool name
10fba81b9d0221b8e47aa1e0b43236413b7d28dfMichel Normand # remove the IP Filter rule
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = ["/usr/bin/pfexec", "/usr/sbin/ipf", "-r", "-f", "-"]
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to remove IP Filter rule %s: %s" % (ipf, err)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # remove IP Pools added by neutron-l3-agent
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano check_call(["/usr/bin/pfexec", "/usr/sbin/ippool", "-R",
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to remove IP Pool %s: %s" % (ippool_name, err)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # first kill the SMF contract
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to kill the SMF contract: %s" % (err)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # remove VNICs associated with L3 agent
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to retrieve IP interface names"
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # L3 agent datalinks are always 15 characters in length. They start
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # with either 'l3i' or 'l3e', end with '_0', and in between they are
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # hexadecimal digits.
99e4008cad9e959b683c6f48411fcf15a92be3b5Michel Normand # first remove the IP
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # next remove the VNIC
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano print "failed to remove datalinks used by L3 agent: %s" % (err)
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # remove IPv4 Filter rules added by neutron-l3-agent
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # remove IPv6 Filter rules added by neutron-l3-agent
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano # remove IP NAT rules added by neutron-l3-agent
d823d5b966f49d975a09a8512d084389d6d7ffc7dlezcano cmd = ["/usr/bin/pfexec", "/usr/sbin/ipnat", "-lR"]
try: