Example #1
0
def main():
    """Starts the execution of anvil without injecting variables into
    the global namespace. Ensures that logging is setup and that sudo access
    is available and in-use.

    Arguments: N/A
    Returns: 1 for success, 0 for failure and 2 for permission change failure.
    """

    # Do this first so people can see the help message...
    args = opts.parse(load_previous_settings())

    # Configure logging levels
    log_level = logging.INFO
    if args['verbose']:
        log_level = logging.DEBUG
    logging.setupLogging(log_level, tee_filename=args['tee_file'])
    LOG.debug("Log level is: %s" % (logging.getLevelName(log_level)))

    def print_exc(exc):
        if not exc:
            return
        msg = str(exc).strip()
        if not msg:
            return
        if not (msg.endswith(".") or msg.endswith("!")):
            msg = msg + "."
        if msg:
            print(msg)

    def print_traceback():
        traceback = None
        if log_level < logging.INFO:
            # See: http://docs.python.org/library/traceback.html
            # When its not none u get more detailed info about the exception
            traceback = sys.exc_traceback
        tb.print_exception(sys.exc_type,
                           sys.exc_value,
                           traceback,
                           file=sys.stdout)

    try:
        run(args)
        utils.goodbye(True)
        return 0
    except excp.PermException as e:
        print_exc(e)
        print((
            "This program should be running via %s as it performs some root-only commands is it not?"
        ) % (colorizer.quote('sudo', quote_color='red')))
        return 2
    except excp.OptionException as e:
        print_exc(e)
        print("Perhaps you should try %s" %
              (colorizer.quote('--help', quote_color='red')))
        return 1
    except Exception:
        utils.goodbye(False)
        print_traceback()
        return 1
def main():
    """
    Starts the execution of without
    injecting variables into the global namespace. Ensures that
    logging is setup and that sudo access is available and in-use.

    Arguments: N/A
    Returns: 1 for success, 0 for failure and 2 for permission change failure.
    """

    # Do this first so people can see the help message...
    args = opts.parse(load_previous_settings())

    # Configure logging levels
    log_level = logging.INFO
    if args['verbose'] or args['dryrun']:
        log_level = logging.DEBUG
    logging.setupLogging(log_level)
    LOG.debug("Log level is: %s" % (logging.getLevelName(log_level)))

    def print_exc(exc):
        if not exc:
            return
        msg = str(exc).strip()
        if not msg:
            return
        if not (msg.endswith(".") or msg.endswith("!")):
            msg = msg + "."
        if msg:
            print(msg)

    def print_traceback():
        traceback = None
        if log_level < logging.INFO:
            # See: http://docs.python.org/library/traceback.html
            # When its not none u get more detailed info about the exception
            traceback = sys.exc_traceback
        tb.print_exception(sys.exc_type, sys.exc_value,
                           traceback, file=sys.stdout)

    try:
        ensure_perms()
    except excp.PermException as e:
        print_exc(e)
        print(("This program should be running via %s as it performs some root-only commands is it not?")
              % (colorizer.quote('sudo', quote_color='red')))
        return 2

    try:
        run(args)
        utils.goodbye(True)
        return 0
    except excp.OptionException as e:
        print_exc(e)
        print("Perhaps you should try %s" % (colorizer.quote('--help', quote_color='red')))
        return 1
    except Exception:
        utils.goodbye(False)
        print_traceback()
        return 1
Example #3
0
def main():
    parser = OptionParser()
    parser.add_option("-u",
                      '--user',
                      dest='user',
                      help='user to upload the image/s as',
                      metavar='USER')
    parser.add_option("-t",
                      '--tenant',
                      dest='tenant',
                      help='tenant to upload the image/s as',
                      metavar='TENANT')
    parser.add_option("-g",
                      '--glance',
                      dest='glance_uri',
                      help='glance endpoint uri to upload to',
                      metavar='GLANCE')
    parser.add_option("-k",
                      '--keystone',
                      dest='keystone_uri',
                      help='keystone endpoint uri to authenticate with',
                      metavar='KEYSTONE')
    parser.add_option('-i',
                      '--image',
                      dest='images',
                      action='append',
                      help="image archive file or uri to upload to glance")
    (options, args) = parser.parse_args()
    # Why can't i iterate over this, sad...
    if (not options.user or not options.tenant or not options.glance_uri
            or not options.keystone_uri or not options.images):
        parser.error("options are missing, please try -h")
    logging.setupLogging(logging.DEBUG)
    params = {
        'keystone': {
            'admin_tenant': options.tenant,
            'admin_user': options.user,
            'admin_password': get_password(options.user),
            'endpoints': {
                'public': {
                    'uri': options.keystone_uri,
                },
            },
        },
        'glance': {
            'endpoints': {
                'public': {
                    'uri': options.glance_uri,
                },
            },
        },
    }
    img_am = len(options.images)
    uploader = glance.UploadService(**params)
    am_installed = uploader.install(options.images)
    if img_am == am_installed:
        return 0
    else:
        return 1
def main():
    parser = OptionParser()
    parser.add_option("-k", '--keystone', dest='keystone_uri',
                      help='keystone endpoint uri to authenticate with', metavar='KEYSTONE')
    parser.add_option("-f", '--file', dest='file',
                      help='service and endpoint creation file', metavar='FILE')
    (options, args) = parser.parse_args()
    if not options.keystone_uri or not options.file:
        parser.error("options are missing, please try -h")
    logging.setupLogging(logging.DEBUG)
    replace_services_endpoints(get_token(), options)
def main():
    parser = OptionParser()
    parser.add_option("-k",
                      '--keystone',
                      dest='keystone_uri',
                      help='keystone endpoint uri to authenticate with',
                      metavar='KEYSTONE')
    parser.add_option("-f",
                      '--file',
                      dest='file',
                      help='service and endpoint creation file',
                      metavar='FILE')
    (options, args) = parser.parse_args()
    if not options.keystone_uri or not options.file:
        parser.error("options are missing, please try -h")
    logging.setupLogging(logging.DEBUG)
    replace_services_endpoints(get_token(), options)
def main():
    parser = OptionParser()
    parser.add_option("-u", '--user', dest='user',
                      help='user to upload the image/s as', metavar='USER')
    parser.add_option("-t", '--tenant', dest='tenant',
                      help='tenant to upload the image/s as', metavar='TENANT')
    parser.add_option("-g", '--glance', dest='glance_uri',
                      help='glance endpoint uri to upload to', metavar='GLANCE')
    parser.add_option("-k", '--keystone', dest='keystone_uri',
                      help='keystone endpoint uri to authenticate with', metavar='KEYSTONE')
    parser.add_option('-i', '--image', dest='images',
                      action='append', help="image archive file or uri to upload to glance")
    (options, args) = parser.parse_args()
    # Why can't i iterate over this, sad...
    if (not options.user or not options.tenant or not options.glance_uri
        or not options.keystone_uri or not options.images):
        parser.error("options are missing, please try -h")
    logging.setupLogging(logging.DEBUG)
    params = {
        'keystone': {
            'admin_tenant': options.tenant,
            'admin_user': options.user,
            'admin_password': get_password(options.user),
            'endpoints': {
                'public': {
                    'uri': options.keystone_uri,
                },
            },
        },
        'glance': {
            'endpoints': {
                'public': {
                    'uri': options.glance_uri,
                },
            },
        },
    }
    img_am = len(options.images)
    uploader = glance.UploadService(**params)
    am_installed = uploader.install(options.images)
    if img_am == am_installed:
        return 0
    else:
        return 1
Example #7
0
def main():
    """
    Starts the execution of without
    injecting variables into the global namespace. Ensures that
    logging is setup and that sudo access is available and in-use.

    Arguments: N/A
    Returns: 1 for success, 0 for failure
    """

    # Do this first so people can see the help message...
    args = opts.parse(load_previous_settings())

    # Configure logging levels
    log_level = logging.INFO
    if args['verbose'] or args['dryrun']:
        log_level = logging.DEBUG
    logging.setupLogging(log_level)

    LOG.debug("Log level is: %s" % (logging.getLevelName(log_level)))

    def clean_exc(exc):
        msg = str(exc).strip()
        if msg.endswith(".") or msg.endswith("!"):
            return msg
        else:
            return msg + "."

    def traceback_fn():
        traceback = None
        if log_level < logging.INFO:
            # See: http://docs.python.org/library/traceback.html
            # When its not none u get more detailed info about the exception
            traceback = sys.exc_traceback
        tb.print_exception(sys.exc_type,
                           sys.exc_value,
                           traceback,
                           file=sys.stdout)

    try:
        # Drop to usermode
        sh.user_mode(quiet=False)
    except excp.AnvilException as e:
        print(clean_exc(e))
        print("This program should be running via %s, is it not?" %
              (colorizer.quote('sudo', quote_color='red')))
        return 1

    try:
        run(args)
        utils.goodbye(True)
        return 0
    except excp.OptionException as e:
        print(clean_exc(e))
        print("Perhaps you should try %s" %
              (colorizer.quote('--help', quote_color='red')))
        return 1
    except Exception:
        utils.goodbye(False)
        traceback_fn()
        return 1
Example #8
0
 def test_logger_has_two_handlers(self):
     log.setupLogging(log.INFO, tee_filename=self.log_name)
     self.assertEqual(len(self.test_logger.handlers), 2)