#!/usr/bin/python
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2014, 2015 Cumulus Networks, Inc. All rights reserved.
# Copyright (C) 2014 Metacloud Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.
# 51 Franklin Street, Fifth Floor
# Boston, MA  02110-1301, USA.
""" VXLAN Service Node Daemon.
"""
import sys
import syslog
import traceback

from vxfld.cmd import vxsnd

if __name__ == '__main__':
    try:
        sys.exit(vxsnd.main())
    except SystemExit:
        pass
    except Exception as ex:  # pylint: disable=broad-except
        # pylint: disable=invalid-name
        if isinstance(ex, RuntimeError):
            msg = '%s: Error %s\n' % (vxsnd.NODE_TYPE, ex)
        else:
            msg = '%s: Error %s\n. %s' % (vxsnd.NODE_TYPE, ex,
                                          traceback.format_exc())
        syslog.openlog(logoption=syslog.LOG_PID)
        syslog.syslog(syslog.LOG_ERR, msg)
        sys.stderr.write(msg)
        sys.exit(1)
