6029N/A#!/usr/bin/python2.7
6029N/A
6029N/A# Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
6029N/A#
6029N/A# Licensed under the Apache License, Version 2.0 (the "License"); you may
6029N/A# not use this file except in compliance with the License. You may obtain
6029N/A# a copy of the License at
6029N/A#
6029N/A# http://www.apache.org/licenses/LICENSE-2.0
6029N/A#
6029N/A# Unless required by applicable law or agreed to in writing, software
6029N/A# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
6029N/A# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
6029N/A# License for the specific language governing permissions and limitations
6029N/A# under the License.
6029N/A
6029N/Aimport os
7313N/Afrom subprocess import CalledProcessError, check_call
6029N/Aimport sys
6029N/A
6029N/Aimport smf_include
6029N/A
7313N/Afrom neutron.agent.solaris import packetfilter
7313N/A
6029N/A
6029N/Adef start():
6029N/A # verify paths are valid
6029N/A for f in sys.argv[2:4]:
6029N/A if not os.path.exists(f) or not os.access(f, os.R_OK):
6029N/A print '%s does not exist or is not readable' % f
6029N/A return smf_include.SMF_EXIT_ERR_CONFIG
6029N/A
7313N/A # Cleanup any security groups related PF rules
7313N/A pf = packetfilter.PacketFilter('_auto/neutron:ovs:agent')
7313N/A pf.remove_anchor_recursively()
7313N/A
6029N/A cmd = "/usr/bin/pfexec /usr/lib/neutron/neutron-openvswitch-agent " \
6029N/A "--config-file %s --config-file %s" % tuple(sys.argv[2:4])
6029N/A smf_include.smf_subprocess(cmd)
6029N/A
7313N/A
7313N/Adef stop():
7313N/A try:
7313N/A # first kill the SMF contract
7313N/A check_call(["/usr/bin/pkill", "-c", sys.argv[2]])
7313N/A except CalledProcessError as err:
7313N/A print "failed to kill the SMF contract: %s" % err
7313N/A return smf_include.SMF_EXIT_ERR_FATAL
7313N/A
7313N/A # We need to remove the PF rules added under _auto/neutron:ovs:agent
7313N/A # anchor.
7313N/A pf = packetfilter.PacketFilter('_auto/neutron:ovs:agent')
7313N/A pf.remove_anchor_recursively()
7313N/A return smf_include.SMF_EXIT_OK
7313N/A
7313N/A
6029N/Aif __name__ == "__main__":
6029N/A os.putenv("LC_ALL", "C")
6029N/A smf_include.smf_main()