neutron-l3-agent revision 2583
2521N/A#!/usr/bin/python2.6
2521N/A
2521N/A# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
2521N/A#
2521N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
2521N/A# not use this file except in compliance with the License. You may obtain
2521N/A# a copy of the License at
2521N/A#
2521N/A# http://www.apache.org/licenses/LICENSE-2.0
2521N/A#
2521N/A# Unless required by applicable law or agreed to in writing, software
2521N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
2521N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
2521N/A# License for the specific language governing permissions and limitations
2521N/A# under the License.
2521N/A
2521N/Aimport os
2521N/Aimport sys
2521N/A
2521N/Aimport smf_include
2521N/A
2583N/Afrom subprocess import Popen, PIPE
2583N/A
2521N/A
2521N/Adef start():
2521N/A # verify paths are valid
2521N/A for f in sys.argv[2:4]:
2521N/A if not os.path.exists(f) or not os.access(f, os.R_OK):
2521N/A print '%s does not exist or is not readable' % f
2521N/A return smf_include.SMF_EXIT_ERR_CONFIG
2521N/A
2583N/A # System-wide forwarding (either ipv4 or ipv6 or both) must be enabled
2583N/A # before neutron-l3-agent can be started.
2583N/A cmd = ["/usr/sbin/ipadm", "show-prop", "-c", "-p", "forwarding",
2583N/A "-o", "current", "ipv4"]
2583N/A p = Popen(cmd, stdout=PIPE, stderr=PIPE)
2583N/A output, error = p.communicate()
2583N/A if p.returncode != 0:
2583N/A print "failed to determine if IPv4 forwarding is enabled or not"
2583N/A return smf_include.SMF_EXIT_ERR_FATAL
2583N/A v4fwding = "on" in output
2583N/A
2583N/A cmd = ["/usr/sbin/ipadm", "show-prop", "-c", "-p", "forwarding",
2583N/A "-o", "current", "ipv6"]
2583N/A p = Popen(cmd, stdout=PIPE, stderr=PIPE)
2583N/A output, error = p.communicate()
2583N/A if p.returncode != 0:
2583N/A print "failed to determine if IPv6 forwarding is enabled or not"
2583N/A return smf_include.SMF_EXIT_ERR_FATAL
2583N/A v6fwding = "on" in output
2583N/A
2583N/A if not any((v4fwding, v6fwding)):
2583N/A print "System-wide IPv4 or IPv6 (or both) forwarding must be enabled " \
2583N/A "before enabling %s" % os.getenv("SMF_FMRI")
2583N/A return smf_include.SMF_EXIT_ERR_CONFIG
2583N/A
2521N/A cmd = "/usr/lib/neutron/neutron-l3-agent --config-file %s " \
2521N/A "--config-file %s" % tuple(sys.argv[2:4])
2521N/A smf_include.smf_subprocess(cmd)
2521N/A
2521N/Aif __name__ == "__main__":
2521N/A os.putenv("LC_ALL", "C")
2521N/A smf_include.smf_main()