def put_files(self, action_id, files, upload_contents=1):
        """Inserts a set of files into the repo, as a result of a scheduled
        action"""
        log_debug(4)
        missing_files = []
        files_too_large = []
        failed_due_to_quota = []

        max_file_size = self.get_maximum_file_size()

        for file in files:
            try:
                params = self._make_file_info(file,
                                              local_path=None,
                                              load_contents=upload_contents)
            except cfg_exceptions.RepositoryLocalFileError:
                missing_files.append(file)
                continue

            if upload_contents and (params['size'] > max_file_size):
                files_too_large.append(file)
                continue

            try:
                self.rpc_call('config.client.upload_file', self.system_id,
                              action_id, params)
            except xmlrpclib.Fault:
                e = sys.exc_info()[1]
                fault_code, fault_string = e.faultCode, e.faultString
                # deal with particular faults
                if fault_code == -4003:
                    # File too large
                    files_too_large.append(file)
                elif fault_code == -4014:
                    # Ran out of org quota space
                    failed_due_to_quota.append(file)
                else:
                    raise_with_tb(
                        cfg_exceptions.RepositoryFilePushError(
                            fault_code, fault_string),
                        sys.exc_info()[2])
            except Exception:
                traceback.print_exc()
                raise

        result = {}
        # If there are files too large to be pushed, result will have a key
        # `file_too_large'
        if len(files_too_large) > 0:
            result['files_too_large'] = files_too_large

        if len(failed_due_to_quota) > 0:
            result['failed_due_to_quota'] = failed_due_to_quota

        if len(missing_files) > 0:
            result['missing_files'] = missing_files

        return result
Beispiel #2
0
    def put_file(self,
                 config_channel,
                 repopath,
                 localfile=None,
                 is_first_revision=None,
                 old_revision=None,
                 delim_start=None,
                 delim_end=None,
                 selinux_ctx=None):
        """
        Insert a given file into the repo, overwriting if necessary.
        localfile defaults to the repopath
        """
        log_debug(4)

        params = self._make_file_info(repopath,
                                      localfile,
                                      delim_start=delim_start,
                                      delim_end=delim_end)

        max_file_size = self.get_maximum_file_size()

        if params['size'] > max_file_size:
            error_msg = "%s too large (%s bytes, %s bytes max allowed)"
            raise cfg_exceptions.ConfigFileTooLargeError(
                error_msg % (localfile, params['size'], max_file_size))

        if selinux_ctx is not None:
            params.update({
                'selinux_ctx': selinux_ctx,
            })

        params.update({
            'session': self.session,
            'config_channel': config_channel,
        })
        if is_first_revision:
            params['is_first_revision'] = 1
        elif old_revision:
            params['old_revision'] = int(old_revision)

        try:
            result = self.rpc_call('config.management.put_file', params)

        except xmlrpclib.Fault:
            e = sys.exc_info()[1]
            fault_code, fault_string = e.faultCode, e.faultString

            if is_first_revision and fault_code == -4013:
                raise_with_tb(
                    cfg_exceptions.RepositoryFileExistsError(fault_string),
                    sys.exc_info()[2])

            if old_revision and fault_code == -4012:
                raise_with_tb(
                    cfg_exceptions.RepositoryFileVersionMismatchError(
                        fault_string),
                    sys.exc_info()[2])

            if fault_code == -4003:
                raise_with_tb(
                    cfg_exceptions.ConfigFileTooLargeError(fault_string),
                    sys.exc_info()[2])

            if fault_code == -4014:
                raise_with_tb(cfg_exceptions.QuotaExceeded(fault_string),
                              sys.exc_info()[2])

            raise_with_tb(
                cfg_exceptions.RepositoryFilePushError(fault_code,
                                                       fault_string),
                sys.exc_info()[2])

        return result