示例#1
0
    def _resp_exception(self, resp):
        """If we encounter an exception in our upload.

        we will look at how we can attempt to resolve the exception.

        :param resp:
        """

        message = [
            'Url: [ %s ] Reason: [ %s ] Request: [ %s ] Status Code: [ %s ]. ',
            resp.url, resp.reason, resp.request, resp.status_code
        ]

        # Check to make sure we have all the bits needed
        if not hasattr(resp, 'status_code'):
            message[0] += 'No Status to check. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp is None:
            message[0] += 'No response information. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 401:
            message[0] += (
                'Turbolift experienced an Authentication issue. Turbolift'
                ' will retry...')
            self.job_args.update(auth.authenticate(self.job_args))
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 404:
            message[0] += 'Item not found.'
            LOG.debug(*message)
        elif resp.status_code == 409:
            message[0] += ('Request Conflict. Turbolift is abandoning this...')
        elif resp.status_code == 413:
            return_headers = resp.headers
            retry_after = return_headers.get('retry_after', 10)
            cloud_utils.stupid_hack(wait=retry_after)
            message[0] += ('The System encountered an API limitation and will'
                           ' continue in [ %s ] Seconds' % retry_after)
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 502:
            message[0] += (
                'Failure making Connection. Turbolift will retry...')
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 503:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'SWIFT-API FAILURE'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 504:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'Gateway Failure.'
            raise exceptions.SystemProblem(message)
        elif resp.status_code >= 300:
            message[0] += 'General exception.'
            raise exceptions.SystemProblem(message)
        else:
            LOG.debug(*message)
示例#2
0
    def run_manager(self, job_override=None):
        """The run manager.

        The run manager is responsible for loading the plugin required based on
        what the user has inputted using the parsed_command value as found in
        the job_args dict. If the user provides a *job_override* the method
        will attempt to import the module and class as provided by the user.

        Before the method attempts to run any job the run manager will first
        authenticate to the the cloud provider.

        :param job_override: ``str`` DOT notation for import with Colin used to
                                     separate the class used for the job.
        """

        for arg_name, arg_value in self.job_args.items():
            if arg_name.endswith('_headers'):
                if isinstance(arg_value, list):
                    self.job_args[arg_name] = self._list_headers(
                        headers=arg_value)
                elif not arg_name:
                    self.job_args[arg_name] = self._str_headers(
                        header=arg_value)
                else:
                    self.job_args[arg_name] = dict()

        # Set base header for the user-agent
        self.job_args['base_headers']['User-Agent'] = 'turbolift'

        LOG.info('Authenticating')
        indicator_options = {'run': self.job_args.get('run_indicator', True)}
        with indicator.Spinner(**indicator_options):
            LOG.debug('Authenticate against the Service API')
            self.job_args.update(auth.authenticate(job_args=self.job_args))

        if job_override:
            action = self._get_method(method=job_override)
        else:
            parsed_command = self.job_args.get('parsed_command')
            if not parsed_command:
                raise exceptions.NoCommandProvided(
                    'Please provide a command. Basic commands are: %s',
                    list(self.job_map.keys()))
            else:
                action = self._get_method(method=self.job_map[parsed_command])

        run = action(job_args=self.job_args)
        run.start()
示例#3
0
    def run_manager(self, job_override=None):
        """The run manager.

        The run manager is responsible for loading the plugin required based on
        what the user has inputted using the parsed_command value as found in
        the job_args dict. If the user provides a *job_override* the method
        will attempt to import the module and class as provided by the user.

        Before the method attempts to run any job the run manager will first
        authenticate to the the cloud provider.

        :param job_override: ``str`` DOT notation for import with Colin used to
                                     separate the class used for the job.
        """

        for arg_name, arg_value in self.job_args.items():
            if arg_name.endswith("_headers"):
                if isinstance(arg_value, list):
                    self.job_args[arg_name] = self._list_headers(headers=arg_value)
                elif not arg_name:
                    self.job_args[arg_name] = self._str_headers(header=arg_value)
                else:
                    self.job_args[arg_name] = dict()

        # Set base header for the user-agent
        self.job_args["base_headers"]["User-Agent"] = "turbolift"

        LOG.info("Authenticating")
        indicator_options = {"run": self.job_args.get("run_indicator", True)}
        with indicator.Spinner(**indicator_options):
            LOG.debug("Authenticate against the Service API")
            self.job_args.update(auth.authenticate(job_args=self.job_args))

        if job_override:
            action = self._get_method(method=job_override)
        else:
            parsed_command = self.job_args.get("parsed_command")
            if not parsed_command:
                raise exceptions.NoCommandProvided(
                    "Please provide a command. Basic commands are: %s", list(self.job_map.keys())
                )
            else:
                action = self._get_method(method=self.job_map[parsed_command])

        run = action(job_args=self.job_args)
        run.start()
示例#4
0
    def _target_auth(self):
        self.target_args['container'] = self.job_args['target_container']
        self.target_args['os_region'] = self.job_args['target_region']

        # Set the target auth url
        target_auth_url = self.job_args.get('target_auth_url')
        if target_auth_url:
            self.target_args['os_auth_url'] = target_auth_url

        # Set the target user
        target_user = self.job_args.get('target_user')
        if target_user:
            self.target_args['os_user'] = target_user

        # Set the target password
        target_password = self.job_args.get('target_password')
        if target_password:
            self.target_args['os_password'] = target_password

        # Set the target apikey
        target_apikey = self.job_args.get('target_apikey')
        if target_apikey:
            self.target_args['os_apikey'] = target_apikey

        # Disable any active auth plugins, This is done because all information
        #  that may be needed from the plugin is already loaded.
        auth_plugin_list = turbolift.auth_plugins(
            auth_plugins=self.job_args.get('auth_plugins')
        )
        for item in auth_plugin_list.keys():
            self.target_args[item] = None

        # Authenticate to the target region
        LOG.info('Authenticating against the target')
        self.target_args.update(
            auth.authenticate(
                job_args=self.target_args
            )
        )
示例#5
0

# Load our Logger
from turbolift.logger import logger

log_method = logger.load_in(log_level="info", log_file="turbolift_library", log_location=HOME)


# Load our constants
turbolift.load_constants(log_method, args)


# Authenticate against the swift API
from turbolift.authentication import auth

authentication = auth.authenticate()


# Package up the Payload
import turbolift.utils.http_utils as http

payload = http.prep_payload(auth=auth, container=args.get("container"), source=args.get("source"), args=args)


# Load all of our available cloud actions
from turbolift.clouderator import actions

cf_actions = actions.CloudActions(payload=payload)


# Create a Container if it does not already exist
示例#6
0
    'error_retry': 5,  # Number of failure retries
    'quiet': True  # Make the application not print stdout
}

# Load our Logger
from turbolift.logger import logger
log_method = logger.load_in(log_level='info',
                            log_file='turbolift_library',
                            log_location=HOME)

# Load our constants
turbolift.load_constants(log_method, args)

# Authenticate against the swift API
from turbolift.authentication import auth
authentication = auth.authenticate()

# Package up the Payload
import turbolift.utils.http_utils as http
payload = http.prep_payload(auth=auth,
                            container=args.get('container'),
                            source=args.get('source'),
                            args=args)

# Load all of our available cloud actions
from turbolift.clouderator import actions
cf_actions = actions.CloudActions(payload=payload)

# Create a Container if it does not already exist
# =============================================================================
kwargs = {
示例#7
0
    def _resp_exception(self, resp):
        """If we encounter an exception in our upload.

        we will look at how we can attempt to resolve the exception.

        :param resp:
        """

        message = [
            'Url: [ %s ] Reason: [ %s ] Request: [ %s ] Status Code: [ %s ]. ',
            resp.url,
            resp.reason,
            resp.request,
            resp.status_code
        ]

        # Check to make sure we have all the bits needed
        if not hasattr(resp, 'status_code'):
            message[0] += 'No Status to check. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp is None:
            message[0] += 'No response information. Turbolift will retry...'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 401:
            message[0] += (
                'Turbolift experienced an Authentication issue. Turbolift'
                ' will retry...'
            )
            self.job_args.update(auth.authenticate(self.job_args))
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 404:
            message[0] += 'Item not found.'
            LOG.debug(*message)
        elif resp.status_code == 409:
            message[0] += (
                'Request Conflict. Turbolift is abandoning this...'
            )
        elif resp.status_code == 413:
            return_headers = resp.headers
            retry_after = return_headers.get('retry_after', 10)
            cloud_utils.stupid_hack(wait=retry_after)
            message[0] += (
                'The System encountered an API limitation and will'
                ' continue in [ %s ] Seconds' % retry_after
            )
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 502:
            message[0] += (
                'Failure making Connection. Turbolift will retry...'
            )
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 503:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'SWIFT-API FAILURE'
            raise exceptions.SystemProblem(message)
        elif resp.status_code == 504:
            cloud_utils.stupid_hack(wait=10)
            message[0] += 'Gateway Failure.'
            raise exceptions.SystemProblem(message)
        elif resp.status_code >= 300:
            message[0] += 'General exception.'
            raise exceptions.SystemProblem(message)
        else:
            LOG.debug(*message)