Ejemplo n.º 1
0
def run_turbolift():
    """This is the run section of the application Turbolift."""

    if len(sys.argv) <= 1:
        arguments.get_help()
        raise SystemExit('Give me something to do and I will do it')
    else:
        args = arguments.get_args()
        log = logger.LogSetup(
            debug_logging=args.get('debug', False),
            log_dir=args.get('log_location', '/var/log'),
            log_name=args.get('log_file')
        ).default_logger(enable_stream=args.get('log_streaming'))

        log.debug('set arguments [ %s ]', json.dumps(args, indent=2))

        import turbolift.utils.basic_utils as basic
        args = basic.dict_pop_none(dictionary=args)
        load_constants(args=args)

        try:
            from turbolift import worker
            worker.start_work()
        except KeyboardInterrupt:
            turbo.emergency_kill(reclaim=True)
        finally:
            if args.get('quiet') is not True:
                print('All Done!')
            log.info('Job Finished.')
Ejemplo n.º 2
0
def understand_args(set_args):
    """parse the arguments.

    :return set_args:
    """

    def set_header_args():
        """return base Headers."""

        for htp in ["object_headers", "container_headers", "base_headers"]:
            set_args[htp] = basic.keys2dict(chl=set_args.get(htp))

    sysconfig = set_args.get("system_config")

    if sysconfig is not None:
        config = ConfigParser.SafeConfigParser()
        config.read([sysconfig])
        set_args.update(dict(config.items("Turbolift")))

    # Return all types of headers
    set_header_args()

    if set_args.get("os_region") is not None:
        set_args["os_region"] = set_args["os_region"].upper()

    if set_args.get("os_rax_auth") is not None:
        set_args["os_rax_auth"] = set_args["os_rax_auth"].upper()

    if set_args.get("os_user") is None:
        raise SystemExit("\nNo Username was provided, use [--os-user]\n")

    if not any([set_args.get("os_apikey"), set_args.get("os_password"), set_args.get("os_token")]):
        raise SystemExit("No APIKey or Password was provided," " use [--os-apikey] or [--os-password]")
    else:
        if set_args.get("os_token") and not set_args.get("os_tenant"):
            raise SystemExit("Token auth requires setting the tenant." " use [--os-tenant]")

    if set_args.get("archive") is True:
        set_args["cc"] = 1

    if set_args.get("tsync"):
        import warnings

        set_args["upload"] = True
        set_args["sync"] = True
        set_args["tsync"] = None
        warnings.simplefilter("always")
        msg = (
            'The "tsync" method has been replaced by [upload --sync]'
            ' Please check "upload --help" for more information.'
        )
        warnings.warn(msg, PendingDeprecationWarning)

    if set_args.get("debug") is True:
        set_args["verbose"] = True
        set_args["log_level"] = "debug"
        print("DEFAULT ARGUMENTS : %s\n" % set_args)

    # Parse and return the arguments
    return basic.dict_pop_none(dictionary=set_args)
Ejemplo n.º 3
0
def understand_args(set_args):
    """parse the arguments.

    :param parser:
    :return args:
    """
    def set_header_args():
        """return base Headers.

        :return set_args:
        """

        for htp in ['object_headers', 'container_headers', 'base_headers']:
            set_args[htp] = basic.keys2dict(chl=set_args.get(htp))

    sysconfig = set_args.get('system_config')
    if sysconfig is not None:
        config = ConfigParser.SafeConfigParser()
        config.read([sysconfig])
        set_args.update(dict(config.items("Turbolift")))

    # Return all types of headers
    set_header_args()

    if set_args.get('os_region') is not None:
        set_args['os_region'] = set_args['os_region'].upper()

    if set_args.get('os_rax_auth') is not None:
        set_args['os_rax_auth'] = set_args['os_rax_auth'].upper()

    if set_args.get('os_user') is None:
        raise SystemExit('\nNo Username was provided, use [--os-user]\n')

    if not any([set_args.get('os_apikey'), set_args.get('os_password')]):
        raise SystemExit('No APIKey or Password was provided,'
                         ' use [--os-apikey] or [--os-password]')

    if set_args.get('archive') is True:
        set_args['cc'] = 1

    if set_args.get('tsync'):
        import time
        import warnings
        set_args['upload'] = True
        set_args['sync'] = True
        set_args['tsync'] = None
        warnings.simplefilter("always")
        msg = ('The "tsync" method has been replaced by "upload --sync"'
               ' Please check "upload --help" for more information.')
        warnings.warn(msg, PendingDeprecationWarning)
        time.sleep(1)

    if set_args.get('debug') is True:
        set_args['verbose'] = True
        set_args['log_level'] = 'debug'
        print('DEFAULT ARGUMENTS : %s\n' % set_args)

    # Parse and return the arguments
    return basic.dict_pop_none(dictionary=set_args)
Ejemplo n.º 4
0
def understand_args(set_args):
    """parse the arguments.

    :return set_args:
    """

    def set_header_args():
        """return base Headers."""

        for htp in ['object_headers', 'container_headers', 'base_headers']:
            set_args[htp] = basic.keys2dict(
                chl=set_args.get(htp)
            )

    sysconfig = set_args.get('system_config')

    if sysconfig is not None:
        config = ConfigParser.SafeConfigParser()
        config.read([sysconfig])
        set_args.update(dict(config.items("Turbolift")))

    # Return all types of headers
    set_header_args()

    if set_args.get('os_region') is not None:
        set_args['os_region'] = set_args['os_region'].upper()

    if set_args.get('os_rax_auth') is not None:
        set_args['os_rax_auth'] = set_args['os_rax_auth'].upper()

    if set_args.get('os_user') is None:
        raise SystemExit('\nNo Username was provided, use [--os-user]\n')

    if not any([set_args.get('os_apikey'), set_args.get('os_password')]):
        raise SystemExit('No APIKey or Password was provided,'
                         ' use [--os-apikey] or [--os-password]')

    if set_args.get('archive') is True:
        set_args['cc'] = 1

    if set_args.get('tsync'):
        import warnings
        set_args['upload'] = True
        set_args['sync'] = True
        set_args['tsync'] = None
        warnings.simplefilter("always")
        msg = ('The "tsync" method has been replaced by [upload --sync]'
               ' Please check "upload --help" for more information.')
        warnings.warn(msg, PendingDeprecationWarning)

    if set_args.get('debug') is True:
        set_args['verbose'] = True
        set_args['log_level'] = 'debug'
        print('DEFAULT ARGUMENTS : %s\n' % set_args)

    # Parse and return the arguments
    return basic.dict_pop_none(dictionary=set_args)
Ejemplo n.º 5
0
 def test_dict_pop_none(self):
     dict_with_none = {
         'key': 'value',
         'test': None
     }
     return_dict = basic_utils.dict_pop_none(dictionary=dict_with_none)
     if 'test' in return_dict:
         self.fail(
             'None Value not removed from dictionary'
         )
Ejemplo n.º 6
0
 def test_dict_pop_none(self):
     dict_with_none = {
         'key': 'value',
         'test': None
     }
     return_dict = basic_utils.dict_pop_none(dictionary=dict_with_none)
     if 'test' in return_dict:
         self.fail(
             'None Value not removed from dictionary'
         )