components/openstack/neutron/files/neutron-dhcp-agent
author Girish Moodalbail <Girish.Moodalbail@oracle.COM>
Mon, 08 Dec 2014 15:34:49 -0800
changeset 3524 ad6a9e0880b9
parent 1944 56ac2df1785b
child 3998 5bd484384122
permissions -rw-r--r--
20089330 Horizon reports "Error: Unable to contact Neutron" on large data set 20103259 unable to delete instance, reports "EVS controller: vport in use" 19970607 disabling neutron smf services does not remove services' vports 18091479 unable delete a port that was associated with incomplete zone
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     1
#!/usr/bin/python2.6
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     2
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     3
# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     4
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     5
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     6
#    not use this file except in compliance with the License. You may obtain
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     7
#    a copy of the License at
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     8
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
     9
#         http://www.apache.org/licenses/LICENSE-2.0
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    10
#
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    11
#    Unless required by applicable law or agreed to in writing, software
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    12
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    13
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    14
#    License for the specific language governing permissions and limitations
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    15
#    under the License.
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    16
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    17
import os
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    18
import re
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    19
import sys
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    20
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    21
import smf_include
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    22
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    23
from subprocess import CalledProcessError, Popen, PIPE, check_call
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    24
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    25
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    26
def start():
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    27
    # verify paths are valid
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    28
    for f in sys.argv[2:4]:
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    29
        if not os.path.exists(f) or not os.access(f, os.R_OK):
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    30
            print '%s does not exist or is not readable' % f
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    31
            return smf_include.SMF_EXIT_ERR_CONFIG
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    32
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    33
    cmd = "/usr/lib/neutron/neutron-dhcp-agent --config-file %s " \
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    34
        "--config-file %s" % tuple(sys.argv[2:4])
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    35
    smf_include.smf_subprocess(cmd)
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    36
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    37
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    38
def stop():
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    39
    try:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    40
        # first kill the SMF contract
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    41
        check_call(["/usr/bin/pkill", "-c", sys.argv[2]])
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    42
    except CalledProcessError as err:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    43
        print "failed to kill the SMF contract: %s" % err
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    44
        return smf_include.SMF_EXIT_ERR_FATAL
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    45
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    46
    cmd = ["/usr/sbin/ipadm", "show-if", "-p", "-o", "ifname"]
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    47
    p = Popen(cmd, stdout=PIPE, stderr=PIPE)
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    48
    output, error = p.communicate()
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    49
    if p.returncode != 0:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    50
        print "failed to retrieve IP interface names"
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    51
        return smf_include.SMF_EXIT_ERR_FATAL
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    52
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    53
    ifnames = output.splitlines()
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    54
    # DHCP agent datalinks are always 15 characters in length. They start with
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    55
    # 'evs', end with '_0', and in between they are hexadecimal digits.
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    56
    prog = re.compile('evs[0-9A-Fa-f\_]{10}_0')
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    57
    for ifname in ifnames:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    58
        if not prog.search(ifname):
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    59
            continue
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    60
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    61
        try:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    62
            # first remove the IP
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    63
            check_call(["/usr/bin/pfexec", "/usr/sbin/ipadm", "delete-ip",
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    64
                        ifname])
3524
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    65
            # get the tenant, evs, and vport name for the VNIC
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    66
            cmd = ["/usr/sbin/dladm", "show-vnic", "-po",
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    67
                   "tenant,evs,vport", ifname]
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    68
            p = Popen(cmd, stdout=PIPE, stderr=PIPE)
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    69
            output, error = p.communicate()
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    70
            if p.returncode != 0:
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    71
                print "failed to retrieve Tenant, EVS," \
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    72
                      " and VPort info for a VNIC"
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    73
                return smf_include.SMF_EXIT_ERR_FATAL
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    74
            tenant, evs, vport = output.strip().split(':')
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    75
            # next remove the VNIC
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    76
            check_call(["/usr/bin/pfexec", "/usr/sbin/dladm", "delete-vnic",
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    77
                        ifname])
3524
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    78
            # remove the EVS VPort
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    79
            check_call(["/usr/sbin/evsadm", "remove-vport", "-T", tenant,
ad6a9e0880b9 20089330 Horizon reports "Error: Unable to contact Neutron" on large data set
Girish Moodalbail <Girish.Moodalbail@oracle.COM>
parents: 1944
diff changeset
    80
                        "%s/%s" % (evs, vport)])
1944
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    81
        except CalledProcessError as err:
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    82
            print "failed to remove datalinks used by DHCP agent: %s" % err
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    83
            return smf_include.SMF_EXIT_ERR_FATAL
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    84
    return smf_include.SMF_EXIT_OK
56ac2df1785b PSARC/2014/207 OpenStack Glance Update to Havana
Drew Fisher <drew.fisher@oracle.com>
parents: 1760
diff changeset
    85
1760
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    86
if __name__ == "__main__":
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    87
    os.putenv("LC_ALL", "C")
353323c7bdc1 PSARC/2013/350 OpenStack for Solaris (Umbrella)
Drew Fisher <drew.fisher@oracle.com>
parents:
diff changeset
    88
    smf_include.smf_main()