#!/usr/bin/python # Copyright 2016 Red Hat, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import argparse import logging import os import sys from ipalib import api, errors from novajoin import configure_ipa from novajoin.errors import ConfigurationError IPACONF = '/etc/ipa/default.conf' LOGFILE = '/var/log/novajoin-install.log' logging.basicConfig() logger = logging.getLogger() if __name__ == '__main__': if not os.path.exists(IPACONF): sys.exit('Must be enrolled in IPA') api.bootstrap(context='novajoin') api.finalize() try: parser = argparse.ArgumentParser( description='Nova join Install Options' ) parser = configure_ipa.ipa_options(parser) args = vars(parser.parse_args()) configure_ipa.validate_options(args) except ConfigurationError as e: # pylint: disable=broad-except logger.info(str(e)) # emit message to console logger.debug(e, exc_info=1) # add backtrace information to logfile logger.info('Installation aborted.') logger.info('See log file %s for details' % LOGFILE) sys.exit(1) novajoin = configure_ipa.NovajoinRole(user=args.get('user')) if not args.get('no_kinit', False): novajoin.kinit(args.get('principal'), args.get('password')) try: api.Backend.rpcclient.connect() except errors.CCacheError: sys.exit("No Kerberos credentials") novajoin.configure_ipa()