neutron-l3-agent revision 5403
b614993b942a5222f6d88ae5e9974334484d74f2nd# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
b614993b942a5222f6d88ae5e9974334484d74f2nd# Licensed under the Apache License, Version 2.0 (the "License"); you may
b614993b942a5222f6d88ae5e9974334484d74f2nd# not use this file except in compliance with the License. You may obtain
b614993b942a5222f6d88ae5e9974334484d74f2nd# a copy of the License at
b614993b942a5222f6d88ae5e9974334484d74f2nd# Unless required by applicable law or agreed to in writing, software
b614993b942a5222f6d88ae5e9974334484d74f2nd# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
b614993b942a5222f6d88ae5e9974334484d74f2nd# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
b614993b942a5222f6d88ae5e9974334484d74f2nd# License for the specific language governing permissions and limitations
b614993b942a5222f6d88ae5e9974334484d74f2nd# under the License.
b614993b942a5222f6d88ae5e9974334484d74f2ndfrom subprocess import CalledProcessError, Popen, PIPE, check_call
b614993b942a5222f6d88ae5e9974334484d74f2ndfrom neutron_vpnaas.services.vpn.device_drivers.solaris_ipsec import \
b614993b942a5222f6d88ae5e9974334484d74f2ndfrom neutron_vpnaas.services.vpn.device_drivers.solaris_ipsec import \
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = ["/usr/sbin/ipadm", "show-prop", "-p", "hostmodel",
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to retrieve hostmodel ipadm property"
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = ["/usr/sbin/ipadm", "set-prop", "-t", "-p", "hostmodel=%s" % value,
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to set ipadm hostmodel property to %s" % value
b614993b942a5222f6d88ae5e9974334484d74f2nd # verify paths are valid
b614993b942a5222f6d88ae5e9974334484d74f2nd print '%s does not exist or is not readable' % f
b614993b942a5222f6d88ae5e9974334484d74f2nd # System-wide forwarding (either ipv4 or ipv6 or both) must be enabled
b614993b942a5222f6d88ae5e9974334484d74f2nd # before neutron-l3-agent can be started.
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = ["/usr/sbin/ipadm", "show-prop", "-c", "-p", "forwarding",
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to determine if IPv4 forwarding is enabled or not"
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = ["/usr/sbin/ipadm", "show-prop", "-c", "-p", "forwarding",
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to determine if IPv6 forwarding is enabled or not"
b614993b942a5222f6d88ae5e9974334484d74f2nd print "System-wide IPv4 or IPv6 (or both) forwarding must be " \
b614993b942a5222f6d88ae5e9974334484d74f2nd "enabled before enabling neutron-l3-agent"
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = "/usr/lib/neutron/neutron-l3-agent --config-file %s " \
b614993b942a5222f6d88ae5e9974334484d74f2nd "--config-file %s --config-file %s" % tuple(sys.argv[2:5])
b614993b942a5222f6d88ae5e9974334484d74f2nd # The VPNaaS shutdown should unplumb all IP tunnels it created. But
b614993b942a5222f6d88ae5e9974334484d74f2nd # be paranoid and check for lingering tunnels created by OpenStack
b614993b942a5222f6d88ae5e9974334484d74f2nd # that may have been left behind if the OpenStack device driver exits
b614993b942a5222f6d88ae5e9974334484d74f2nd # unexpectedly. OpenStack VPN configuration is created when the service
b614993b942a5222f6d88ae5e9974334484d74f2nd # starts. Errors will occur if old IP tunnels still exist.
b614993b942a5222f6d88ae5e9974334484d74f2nd print "Error: Found existing IP tunnel interface(s)."
b614993b942a5222f6d88ae5e9974334484d74f2nd print "Use ipadm(1M) and dladm(1M) to remove it/them."
b614993b942a5222f6d88ae5e9974334484d74f2nd print "Then use svcadm(1M) to clear the service."
b614993b942a5222f6d88ae5e9974334484d74f2nd print "Use the following commands to remove:"
b614993b942a5222f6d88ae5e9974334484d74f2nd print "\t# ipadm delete-ip %s; dladm delete-iptun %s" % (ifn, ifn)
b614993b942a5222f6d88ae5e9974334484d74f2nd # set the hostmodel property if necessary
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove IP Filter rules added by neutron-l3-agent
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to retrieve IP Filter rules"
b614993b942a5222f6d88ae5e9974334484d74f2nd # L3 agent IP Filter rules are of the form
b614993b942a5222f6d88ae5e9974334484d74f2nd # block in quick on l3i64cbb496_a_0 from ... to pool/15417332
b614993b942a5222f6d88ae5e9974334484d74f2nd # capture the IP pool name
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove the IP Filter rule
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = ["/usr/bin/pfexec", "/usr/sbin/ipf", "-r", "-f", "-"]
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to remove IP Filter rule %s: %s" % (ipf, err)
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove IP Pools added by neutron-l3-agent
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to remove IP Pool %s: %s" % (ippool_name, err)
b614993b942a5222f6d88ae5e9974334484d74f2nd # first kill the SMF contract
b614993b942a5222f6d88ae5e9974334484d74f2nd # We need to first remove the IP filter rules and then remove
b614993b942a5222f6d88ae5e9974334484d74f2nd # the IP interfaces on which the rules were applied.
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove IPv4 Filter rules added by neutron-l3-agent
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove IPv6 Filter rules added by neutron-l3-agent
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove IP NAT rules added by neutron-l3-agent
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to retrieve IP NAT rules"
b614993b942a5222f6d88ae5e9974334484d74f2nd # L3 agent IP NAT rules are of the form
b614993b942a5222f6d88ae5e9974334484d74f2nd # bimap l3e64ccc496_a_0 .... OR
b614993b942a5222f6d88ae5e9974334484d74f2nd # rdr l3iedf345cc96_a_0 ....
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove the IP NAT rule
b614993b942a5222f6d88ae5e9974334484d74f2nd check_call(["/usr/bin/pfexec", "/usr/sbin/ipnat", "-r", "-f", "-"],
b614993b942a5222f6d88ae5e9974334484d74f2nd print "failed to remove IP NAT rule %s: %s" % (ipnat_rule, err)
b614993b942a5222f6d88ae5e9974334484d74f2nd # remove VNICs associated with L3 agent
b614993b942a5222f6d88ae5e9974334484d74f2nd cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
try:
ifname])
ifname])