sos.upload.targets — Targets Interface

class sos.upload.targets.UploadTarget(parser=None, args=None, cmdline=None)[source]

Bases: object

This class is designed to upload files to a distribution defined location. These files can be either sos reports, sos collections, or other kind of files like: vmcores, application cores, logs, etc.

arg_defaults = {'case_id': '', 'low_priority': False, 'profiles': [], 'upload_directory': None, 'upload_file': '', 'upload_method': 'auto', 'upload_no_ssl_verify': False, 'upload_pass': None, 'upload_protocol': 'auto', 'upload_s3_access_key': None, 'upload_s3_bucket': None, 'upload_s3_endpoint': None, 'upload_s3_object_prefix': None, 'upload_s3_region': None, 'upload_s3_secret_key': None, 'upload_target': None, 'upload_url': None, 'upload_user': None}
check_distribution()[source]

This should be overridden by upload targets

This is called by sos upload on each target type that exists, and is meant to return True when the upload target matches a criteria that indicates that is the local upload target that should be used.

Only the first upload target to determine a match is selected

desc = '\n            Upload a file (can be an sos report, a must-gather, or others) to\n             a distribution defined remote location\n            '
get_commons()[source]
get_target_id()[source]
get_upload_https_auth(user=None, password=None)[source]

Formats the user/password credentials using basic auth

Parameters:
  • user (str) – The username for upload

  • password (str) – Password for user to use for upload

Returns:

The user/password auth suitable for use in requests calls

Return type:

requests.auth.HTTPBasicAuth()

get_upload_password()[source]

Helper function to determine if we should use the target default upload password or one provided by the user

A user provided password, either via option or the ‘SOSUPLOADPASSWORD’ environment variable will have precendent over any target value

Returns:

The password to use for upload

Return type:

str

get_upload_s3_access_key()[source]

Helper function to determine if we should use the target default upload access key or one provided by the user

Returns:

The access_key to use for upload

Return type:

str

get_upload_s3_bucket()[source]

Helper function to determine if we should use the target default upload bucket or one provided by the user

Returns:

The S3 bucket to use for upload

Return type:

str

get_upload_s3_endpoint()[source]

Helper function to determine if we should use the target default upload endpoint or one provided by the user

Returns:

The S3 Endpoint to use for upload

Return type:

str

get_upload_s3_object_prefix()[source]

Helper function to determine if we should use the target default upload object prefix or one provided by the user

Returns:

The S3 object prefix to use for upload

Return type:

str

get_upload_s3_region()[source]

Helper function to determine if we should use the target default upload region or one provided by the user

Returns:

The S3 region to use for upload

Return type:

str

get_upload_s3_secret_key()[source]

Helper function to determine if we should use the target default upload secret key or one provided by the user

Returns:

The S3 secret key to use for upload

Return type:

str

get_upload_url()[source]

Helper function to determine if we should use the target default upload url or one provided by the user

Returns:

The URL to use for upload

Return type:

str

get_upload_url_string()[source]

Used by upload targets to potentially change the string used to report upload location from the URL to a more human-friendly string

get_upload_user()[source]

Helper function to determine if we should use the target default upload user or one provided by the user

Returns:

The username to use for upload

Return type:

str

classmethod name()[source]

Returns the upload target’s name as a string.

pre_work(hook_commons)[source]
prompt_for_upload_password()[source]

Should be overridden by targets to determine if a password needs to be provided for upload or not

prompt_for_upload_s3_access_key()[source]

Should be overridden by targets to determine if an access key needs to be provided for upload or not

prompt_for_upload_s3_bucket()[source]

Should be overridden by targets to determine if a bucket needs to be provided for upload or not

prompt_for_upload_s3_endpoint()[source]

Should be overridden by targets to determine if an endpoint needs to be provided for upload or not

prompt_for_upload_s3_secret_key()[source]

Should be overridden by targets to determine if a secret key needs to be provided for upload or not

prompt_for_upload_user()[source]

Should be overridden by targets to determine if a user needs to be provided or not

set_commons(commons)[source]

Set common host data for the Upload targets to reference

upload_archive(archive)[source]

Entry point for sos attempts to upload the generated archive to a target or user specified location.

Currently there is support for HTTPS, SFTP, and FTP. HTTPS uploads are preferred for target-defined defaults.

Targets that need to override uploading methods should override the respective upload_https(), upload_sftp(), and/or upload_ftp() methods and should NOT override this method.

Parameters:

archive (str) – The archive filepath to use for upload

In order to enable this for a target, that target needs to implement the following:

Required Class Attrs

_upload_url:

The default location to use. Note these MUST include protocol header

_upload_user:

Default username, if any else None

_upload_password:

Default password, if any else None

The following Class Attrs may optionally be overidden by the Target

_upload_directory:

Default FTP server directory, if any

The following methods may be overridden by Target as needed

prompt_for_upload_user()

Determines if sos should prompt for a username or not.

get_upload_user()

Determines if the default or a different username should be used

get_upload_https_auth()

Format authentication data for HTTPS uploads

get_upload_url_string()

Print a more human-friendly string than vendor URLs

upload_ftp(url=None, directory=None, user=None, password=None)[source]

Attempts to upload the archive to either the target defined or user provided FTP location.

Parameters:
  • url (str) – The URL to upload to

  • directory (str or None) – The directory on the FTP server to write to

  • user (str) – The user to authenticate with

  • password (str) – The password to use for user

Returns:

True if upload is successful

Return type:

bool

Raises:

Exception if upload in unsuccessful

upload_https()[source]

Attempts to upload the archive to an HTTPS location.

Returns:

True if upload is successful

Return type:

bool

Raises:

Exception if upload was unsuccessful

upload_password = None
upload_s3(endpoint=None, region=None, bucket=None, prefix=None, access_key=None, secret_key=None)[source]

Attempts to upload the archive to an S3 bucket.

Parameters:
  • endpoint (str) – The S3 endpoint to upload to

  • region (str) – The S3 region to upload to

  • bucket (str) – The name of the S3 bucket to upload to

  • prefix (str) – The prefix for the S3 object/key

  • access_key (str) – The access key for the S3 bucket

  • secret_key (str) – The secret key for the S3 bucket

Returns:

True if upload is successful

Return type:

bool

Raises:

Exception if upload is unsuccessful

upload_s3_access_key = None
upload_s3_bucket = None
upload_s3_endpoint = None
upload_s3_object_prefix = None
upload_s3_region = None
upload_s3_secret_key = None
upload_sftp(user=None, password=None)[source]

Attempts to upload the archive to an SFTP location.

Due to the lack of well maintained, secure, and generally widespread python libraries for SFTP, sos will shell-out to the system’s local ssh installation in order to handle these uploads.

Do not override this method with one that uses python-paramiko, as the upstream sos team will reject any PR that includes that dependency.

upload_target = None
upload_target_id = 'generic'
upload_target_name = 'Generic Upload'
upload_url = None
upload_user = None