• File: add_attachment.pyc
  • Full Path: /home3/farmfre2/public_html/ALFA_DATA/alfasymlink/root/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyc
  • Date Modified: 03/28/2024 3:28 PM
  • File size: 21.23 KB
  • MIME-type: text/x-bytecode.python
  • Charset: 8 bit

fc@soddlmZmZddlmZmZmZmZmZm	Z	m
Z
ddlmZddlm
Z
ddlmZmZddlmZddlmZmZmZddlmZdd	ljjZdd	ljjZdd	ljjZdd	l Z dd	l!Z!dd	l"Z"dd	l#Z#dd	l$Z$d
Z%dZ%e#j&dZ'ej(Z)d
efdYZ*d	S(i(tOptiont
SUPPRESS_HELP(tRequestErrortConnectionErrortS3UploadFailedErrortMetadataExceptiontDontWaitForCompletiontSftpUploadWarningst	SftpError(tEmptyValueError(t_(tPlugintObjectDisplayOption(t
AddComment(t	apihelpertcommontconfighelper(tLaunchHelperNs%Keith Robertson <kroberts@redhat.com>s&Spenser Shumaker <sshumake@redhat.com>s*redhat_support_tool.plugins.add_attachmentt
AddAttachmentcBseZdZdZdZdZdZeZ	eZ
ejZ
edZedZedZedZdZdZdZdZd	Zd
ZdZdZd
ZdZRS(t
addattachmentcCs
tdS(s
        The usage statement that will be printed by OptionParser.

        Example:
            - %prog -c CASENUMBER [options] <comment text here>
        Important: %prog is a OptionParser built-in.  Use it!
        s+%prog -c CASENUMBER [options] /path/to/file(R
(tcls((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt	get_usage5s	cCstd|jS(s
        The description statement that will be printed by OptionParser.

        Example:
            - 'Use the '%s' command to add a comment to a case.'             % cls.plugin_name
        s4Use the '%s' command to add an attachment to a case.(R
tplugin_name(R((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytget_desc@s		cCs&td|j|j|j|jfS(s
        The epilog string that will be printed by OptionParser.  Usually
        used to print an example of how to use the program.

        Example:
         Examples:
          - %s -c 12345678 Lorem ipsum dolor sit amet, consectetur adipisicing
          - %s -c 12345678
        sExamples:
- %s -c 12345678 /var/log/messages
- %s -c 12345678 -d 'The log file containing the error' /var/log/messages
- %s -c 12345678 
- %s -c 12345678 -g(R
R(R((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt
get_epilogLs	csW|jddtdtdtdtdfd}fd}fd}fd	}t}tjtjjd
drtd}ntd
ddddtddt	tddddd|ddddd|tdddddtddtdd dd!dtd"dt	td#d$dd%ddd|dtd&td'd(dd)ddd|dtd*td+d,dd-ddd|dtd.td/d0dd1dddt	dtd2td3d4dd5dddt	dtd6td7d8dd9dddt	dtd:g
S(;sO
        Subclasses that need command line options should override this method
        and return an array of optparse.Option(s) to be used by the
        OptionParser.

        Example:
         return [Option("-f", "--file", action="store",
                        dest="filename", help='Some file'),
                 Option("-c", "--case",
                        action="store", dest="casenumber",
                        help='A case')]

         Would produce the following:
         Command (? for help): help mycommand

         Usage: mycommand [options]

         Use the 'mycommand' command to find a knowledge base solution by ID
         Options:
           -h, --help  show this help message and exit
           -f, --file  Some file
           -c, --case  A case
         Example:
          - mycommand -c 12345 -f abc.txt

        is>ERROR: can't use -s/--split and -x/--no-split options togethersSERROR: the optional argument to -s/--split must be an integer between 1 and %d (MB)s=ERROR: can't use -s/--split and -f/--use-ftp options togethersIERROR: Red Hat Secure FTP does not support uploading private attachments.csV|jjr GHtn|jjtkrFGHtnt|j_dS(N(tvaluestsplitt	ExceptiontpublictFalsetTruetuseftp(toptiontopt_strtvaluetparser(terrmsg3terrmsg4(sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytset_useftp_callbackscs6|jjdk	r&GHtnt|j_dS(s
            Callback function for -x/--no-split option
            - Report error if the -s/--split option has already been seen
            N(RRtNoneRRtnosplit(R R!R"R#(terrmsg1(sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytcheck_nosplit_callbackscs|jjdk	r&GHtn|jjrFGHtng}d}x|jD]|}|d dkrt|dkrPn|d dkrt|dkr||rPn||r|j|nPq_W|s}neyt|d}Wn"t	k
r&GHtnX|ks?|dkrSGHtn|jt|4t
|j_|dd|j_dS(	sB
            Callback function for -s/--split option
            - Report error if the -x/--no-split option has already been seen
            The -s/--split option can take 0 or 1 arguments
            - With 0 args - use the default max_split_size
            - With 1 arg  - the argument sets the split size
            cSs+yt|tSWntk
r&tSXdS(N(tfloatRt
ValueErrorR(targ((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt	floatables


is--it-iiN(
RR(R'RRtrargstlentappendtintR,RRt	splitsize(R R!R"R#R.R-R4(R)terrmsg2R$tmax_split_size_mb(sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytset_split_size_callbacks:	"/	
cstj|}|jjr;|tkr;GHtn|dkrttd|||f}|GHt|n||j_dS(s
            Callback function for the public option that converts the string
            into an equivalent boolean value
            sVERROR: Unexpected argument to %s: %s
Valid values are true or false (default: %s true)N(	Rtstr_to_boolRRRRR'R
R(R R!R"R#trettmsg(R%(sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytpublic_opt_callbacksR tponiessTrue or False.  Use this to toggle a public or private attachment (default=True). Example: -p false. Red Hat Secure FTP does not support uploading private attachments.s-cs--casenumbertdestt
casenumberthelpsBThe case number from which the comment should be added. (required)tdefaults-ps--publicRttypetstringtactiontcallbacks-rs--fromopencasetfromopencaset
store_trues-ds
--descriptiontdescriptionsA description for the attachment. The Red Hat Support Tool will generate a default description for the attachment if none is provided that contains the name of the file and the RPM package to which it belongs if available. For Red Hat Secure FTP, this will be ignored. (optional)s-xs
--no-splitR(ssDo not attempt to split uploaded files, upload may fail as a result if an alternative destination is not available.s-ss--splitRsThe uploaded attachment file will be intentionally split.  An optional size parameter (in MB) can be supplied and the attachment will be split into 'size' (MB) chunks.  Default/Maximum chunk size: %d (MB)s-fs	--use-ftpRs5Upload attachment to the case via Red Hat Secure FTP s-os--obfuscatet	obfuscates}Obfuscate the attachment by running it through soscleaner to clean hostnames and IP addresses (requires root user privileges)s-gs
--generatesostgeneratesossIGenerate sosreport and upload to the case (requires root user privileges)s-zs
--no-compresst
nocompresssEIf the attachment file is uncompressed, don't compress it for upload.(
tmax_split_sizeR
RRR8Rtget_config_helpertgetRR(RR&R*R7R;tpublic_opt_help((R)R5R$R%R6sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytget_options_sV


4!
cCsA|jr=tjj|jr=tjtjj|jndS(N(tcompressed_attachmenttostpathtexiststshutiltrmtreetdirname(tself((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt_remove_compressed_attachmentss	cCstd|j}td}|jdstjrxtrttd}t|j}|ss|GHq;|dkrH|j	t
q;yt|||jd<PWq;tk
r||GHq;Xq;Wq|GH|j	t
|ndS(Ns!ERROR: %s requires a case number.s%ERROR: %s is not a valid case number.R>s/Please provide a case number (or 'q' to exit): tq(
R
Rt_optionsRtis_interactiveRt	raw_inputtstrtstripRXRR3R,(RWR)R5tline((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt_check_case_numbers,
	




cCs|jrd|jd<dStjr|jdsttd}t|j}|dkrzH|j	t
nt|jr||jd<qqn|jdsdtjj
|j}y-tj|j}|r|d|7}nWnnX||jd<ndS(NRGsJPlease provide a description or enter to accept default (or 'q' to exit): RYs[RHST] File %ss from package %s(tuse_ftpR'RZRR[R\R
R]R^RXRRQRRtbasenamet
attachmenttreporthelpertrpm_for_file(RWR_RGtpackage((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt_check_description2s,	



cCstjtjjddrtjr|jddkr|jdrtt	d}t
|jjdkrt
|jd<qt|jd<qn#|jddkrt|jd<n|jddkrt|jd<ndS(NR R<RRs%Is this a public attachment ([y]/n)? tn(RR8RRLRMR[RZR'R\R
R]R^tlowerRR(RWR_((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt_check_is_publicOs!!cCsP|jdrBtjdkrBtd}|GHt|qBn|jdrtjdkrtd}|GHt|qntd|j}d|_|jdrHdGHtj	dd	gd
tj
dtj}|jdj
d}xS|D]H}d
|krt|j}||_tjj|j|_qqWn|jr|jdr|jd|_tjj|j|_tjj|jsVtd|j}|GHt|qVntjrVtjdkr|jdr|jdsS|jdr0tjjtd|jdntjjtdt}t|j}|dkr	dGHtj	dd	gd
tj
dtj}|jdj
d}x|D]I}d
|krt|j}||_tjj|j|_PqqWqxtrttd}t|jdkrIHtnt|j}||_tjj|j|_tjj|jrPqtd|jGHqWqSqVxtrRttd}t|jdkrHtnt|j}||_tjj|j|_tjj|jr=Pqtd|jGHqWn|jdkry|GHt|n|jdrtj|j|_n|j|_|jd|_|jdptj|js2td|jGtjj tj!|j|_"|j"r2tdGH|j"|_q2n|jdrLt|_#dSdS(NRHis6ERROR: root user privileges required to obfuscate fileRIs:ERROR: root user privileges required to generate sosreports$ERROR: %s requires a path to a file.sGenerating sosreport...t	sosreports--batchtstdouttstderrs
s.tar.sERROR: %s is not a valid file.RER>sgWould you like Red Hat Support Tool to automatically generate and attach a SoS report to %s now? (y/N) saWould you like Red Hat Support Tool to automatically generate and attach a SoS report now? (y/N) tys;Please provide the full path to the file (or 'q' to exit): RYRRJsCompressing %s for upload ...scompleted successfully.R($RZRQtgeteuidR
RRR'Rct
subprocesstPopentPIPEtSTDOUTtcommunicateRR]R^RRt
expandusert_argstisfileRR[tsysRltwriteR\Rtobfuscate_filetupload_fileRat	ftphelpertis_compressed_filetflushtcompress_attachmentRPtsplit_attachment(RWR:tptoutputtoutRRR_((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt_check_file^s

	

	" 


	
							


	
	cCs&tjj|j}|jdr"|jr"||jkr"tjrt	t
dtjj|j}t|j
jdkrt|_|jdtkr|jrtdnt
dGHdSnE|jdst|_|jdtkr|jrtdndSt|_ndS(NR(su%s is too large to upload to the Red Hat Customer Portal, would you like to split the file before uploading ([y]/n)? RhRsBRed Hat Secure FTP does not support uploading private attachments.s?The attachment will be uploaded via Red Hat Secure FTP instead.(RQRRtgetsizeR{RZRaRKRR[R\R
RbR]R^RiRRRR(RWtattachment_sizeR_((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytcheck_file_sizes$	
	cCs,|j|j|j|jdS(N(RR`RgRj(RW((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt
validate_argss


c
Cstj}d}|jr$d}nd}|jd}tjj|j}|j	|j
r#idd6gd6|jjd|jd6}|j
jd	|d
|jd
d|jd|d
|jd
d|j}|rtdGHtd|}x)|dD]}|td|7}qWqnw|j
jd	|d
|jd
d|jd
|jd
d|j}|rtdGH|jrtd||f}qn|dkrtn|r
tjttt}	tdd|g}
|	jd||jd
f|
ndS(sE
        Upload using the Hydra APIs.
        :return: None

        sRed Hat Secure FTPsthe caseR>itnumtnamesR4tsizet
caseNumberRtfileNamet	fileChunkRGtuseFtpscompleted successfully.s6[RHST] The following split files were uploaded to %s:
s
    %ssN[RHST] The following attachment was uploaded to Red Hat Secure FTP:

    %s_%ss-c %s -p %sN(Rtget_apiR'RaRZRQRRRbR{RRRMRKtattachmentstaddR
RRtset_interactiveRRR
Rtrun(RWtapit	updatemsgt	uploadlocRtuploadBaseNametchunktretValt
chunk_nametlhtcomment_displayopt((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pythydra_api_uploadsV		

	
	


	
	
	c
Cstj}d}|jr$d}nd}|jd}tjj|j}|j	ridd6gd6|jj
d|jd6}|jj
d	|d
|jd
d|jd|d
|jd
d|j}|rtdGHtd|}x)|dD]}|td|7}qWqnw|jj
d	|d
|jd
d|jd
|jd
d|j}|rtdGH|jrtd||f}qn|dkrtn|rtjttt}	tdd|g}
|	jd||jd
f|
ndS(sI
        Upload using the AWS s3 REST APIs
        :return: None
        sRed Hat Secure FTPsthe caseR>iRRR4RRRRRRGRs completed successfully.s6[RHST] The following split files were uploaded to %s:
s
    %ssN[RHST] The following attachment was uploaded to Red Hat Secure FTP:

    %s_%ss-c %s -p %sN(RRR'RaRZRQRRRbR{RRMRKRtaws_addR
RRRRRR
RR(RWRRRRRRRRRR((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt
aws_s3_upload*sV		
	
	


	
	
	c
Csd}d}|jrd}nd}|jd}tjj|j}zeytj}t	d||fGHt
jjy|j
WnZtk
r}tjdn8tk
r}dGHtjdj||jnXWntk
r}d|GHntk
rU}t	d	j|}t	|GHtjd
j||nUtk
rl}dGHn>tk
r}	t	dt|	}t	d|GHtj|ntk
r}
t	d
|
j}t	d|GHtj||
jdkr
tjnntk
rn}t	d}t	d|GHt|jd}|dGHtj|n<t k
rt	d}t	d|GHtj|nXWd|j!HXdS(NsRed Hat Secure FTPsthe caseR>sUploading %s to %s ...    sSThe file may or may not be uploaded to the case. Please check the case attachments.sRetrying...   shProblem encountered whilst uploading the attachment via S3 
{}
***Retrying upload with the Hydra API ***s	ERROR: %ssERROR: Problem encountered whilst attaching your file to the case {}. Please consult the Red Hat Support Tool logs for details.s{} {}tsfailed.
sKERROR: Unable to fulfill request with support services API.  Reason: %s    tUnauthorizedsaERROR: Problem connecting to the support services API.  Is the service accessible from this host?s, isvERROR: Problem encountered whilst uploading the attachment.  Please consult the Red Hat Support Tool logs for details.("R'RaRZRQRRRbR{RRR
RxRlR~RRtloggertwarningRtformatRRRterrorRR	R]RtreasonRtremove_userRRRRX(
RWRRRRRtmeteR:tevetreterrmsgtemg((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pytnon_interactive_actionbsx		



		



	



N(t__name__t
__module__RR'tcommentRcRPR{RRRat	libconfigtattachment_max_sizeRKtclassmethodRRRRORXR`RgRjRRRRRR(((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyR+s,						u			9	8(+toptparseRRt(redhat_support_lib.infrastructure.errorsRRRRRRRt(redhat_support_tool.helpers.confighelperR	R
tredhat_support_tool.pluginsRRt'redhat_support_tool.plugins.add_commentR
tredhat_support_tool.helpersRRRt(redhat_support_tool.helpers.launchhelperRt%redhat_support_lib.utils.reporthelpertutilsRdt%redhat_support_lib.utils.confighelpertlibconfighelpert"redhat_support_lib.utils.ftphelperR|RQRxRTtloggingRpt
__author__t	getLoggerRRLRR(((sN/usr/lib/python2.7/site-packages/redhat_support_tool/plugins/add_attachment.pyt<module>s(4