components/openstack/neutron/files/neutron-dhcp-agent
changeset 1944 56ac2df1785b
parent 1760 353323c7bdc1
child 3524 ad6a9e0880b9
child 3619 639868f63ef4
equal deleted inserted replaced
1943:1a27f000029f 1944:56ac2df1785b
    13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    13 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    14 #    License for the specific language governing permissions and limitations
    14 #    License for the specific language governing permissions and limitations
    15 #    under the License.
    15 #    under the License.
    16 
    16 
    17 import os
    17 import os
       
    18 import re
    18 import sys
    19 import sys
    19 
    20 
    20 import smf_include
    21 import smf_include
       
    22 
       
    23 from subprocess import CalledProcessError, Popen, PIPE, check_call
    21 
    24 
    22 
    25 
    23 def start():
    26 def start():
    24     # verify paths are valid
    27     # verify paths are valid
    25     for f in sys.argv[2:4]:
    28     for f in sys.argv[2:4]:
    29 
    32 
    30     cmd = "/usr/lib/neutron/neutron-dhcp-agent --config-file %s " \
    33     cmd = "/usr/lib/neutron/neutron-dhcp-agent --config-file %s " \
    31         "--config-file %s" % tuple(sys.argv[2:4])
    34         "--config-file %s" % tuple(sys.argv[2:4])
    32     smf_include.smf_subprocess(cmd)
    35     smf_include.smf_subprocess(cmd)
    33 
    36 
       
    37 
       
    38 def stop():
       
    39     try:
       
    40         # first kill the SMF contract
       
    41         check_call(["/usr/bin/pkill", "-c", sys.argv[2]])
       
    42     except CalledProcessError as err:
       
    43         print "failed to kill the SMF contract: %s" % err
       
    44         return smf_include.SMF_EXIT_ERR_FATAL
       
    45 
       
    46     cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
       
    47     p = Popen(cmd, stdout=PIPE, stderr=PIPE)
       
    48     output, error = p.communicate()
       
    49     if p.returncode != 0:
       
    50         print "failed to retrieve IP interface names"
       
    51         return smf_include.SMF_EXIT_ERR_FATAL
       
    52 
       
    53     ifnames = output.splitlines()
       
    54     # DHCP agent datalinks are always 15 characters in length. They start with
       
    55     # 'evs', end with '_0', and in between they are hexadecimal digits.
       
    56     prog = re.compile('evs[0-9A-Fa-f\_]{10}_0')
       
    57     for ifname in ifnames:
       
    58         if not prog.search(ifname):
       
    59             continue
       
    60 
       
    61         try:
       
    62             # first remove the IP
       
    63             check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
       
    64                         ifname])
       
    65             # next remove the VNIC
       
    66             check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
       
    67                         ifname])
       
    68         except CalledProcessError as err:
       
    69             print "failed to remove datalinks used by DHCP agent: %s" % err
       
    70             return smf_include.SMF_EXIT_ERR_FATAL
       
    71     return smf_include.SMF_EXIT_OK
       
    72 
    34 if __name__ == "__main__":
    73 if __name__ == "__main__":
    35     os.putenv("LC_ALL", "C")
    74     os.putenv("LC_ALL", "C")
    36     smf_include.smf_main()
    75     smf_include.smf_main()