#!/usr/bin/env python2.7
# -*- mode: python -*-
# Copyright 2012-2015 Canonical Ltd.  This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).

"""Import boot resources into MAAS cluster controller."""

from __future__ import (
    absolute_import,
    print_function,
    unicode_literals,
    )

str = None

__metaclass__ = type

import logging
from provisioningserver.import_images.boot_resources import (
    maaslog,
    main_with_services,
    make_arg_parser,
    NoConfigFile,
    )

logger = logging.getLogger(__name__)

if __name__ == "__main__":
    parser = make_arg_parser(__doc__)
    args = parser.parse_args()
    try:
        main_with_services(args)
    except NoConfigFile:
        maaslog.error("Config file %s not found." % args.config_file)
        raise SystemExit(1)
    except Exception:
        # logger.exception() will log the error message, followed by the
        # exception's stack trace. Using it here rather than allowing
        # the exception to kill the process unhandled means we can be
        # sure about where the exception ends up, rather than it
        # potentially vanishing.
        logger.exception("Unhandled exception; unable to continue.")
        raise SystemExit(2)
