Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# this method will be called before the gathering begins
if self.cInfo['cmdlineopts'].customerName:
localname = self.cInfo['cmdlineopts'].customerName
else:
localname = self.rhnUsername()
if len(localname) == 0:
localname = self.hostName()
if self.cInfo['cmdlineopts'].ticketNumber:
self.ticketNumber = self.cInfo['cmdlineopts'].ticketNumber
if not self.cInfo['cmdlineopts'].batch:
try:
self.reportName = raw_input(
_("Please enter your first initial and last name [%s]: ")
% localname)
self.ticketNumber = raw_input(
_("Please enter the case number that you are "
+ "generating this report for [%s]: ")
% self.ticketNumber)
print
except:
sys.exit(0)
if len(self.reportName) == 0:
self.reportName = localname
self.reportName = sanitizeReportName(self.reportName)
self.ticketNumber = sanitizeTicketNumber(self.ticketNumber)
if (self.reportName == ""):
try:
from ftplib import FTP
upload_name = os.path.basename(self.report_file)
ftp = FTP()
ftp.connect(host, port)
if username and passwd:
ftp.login(username, passwd)
else:
ftp.login()
ftp.cwd(path)
ftp.set_pasv(True)
ftp.storbinary('STOR %s' % upload_name, fp)
ftp.quit()
except:
print _("There was a problem uploading your report to Red Hat support.")
else:
print _("Your report was successfully uploaded to %s with name:" % (upload_url,))
print " " + upload_name
print
print _("Please communicate this name to your support representative.")
print
fp.close()
if tmpcount2 == 0:
soslog.warning("%s:" % plugname)
soslog.warning(" * %s" % plug.diagnose_msgs[tmpcount2])
fp.write("%s: %s\n" % (plugname, plug.diagnose_msgs[tmpcount2]))
self.archive.add_file(fp.name, dest=os.path.join(self.rptdir, 'diagnose.txt'))
self.ui_log.info("")
if not self.opts.batch:
try:
while True:
yorno = raw_input( _("Are you sure you would like to "
"continue (y/n) ? ") )
if yorno == _("y") or yorno == _("Y"):
self.ui_log.info("")
break
elif yorno == _("n") or yorno == _("N"):
self._exit(0)
del yorno
except KeyboardInterrupt:
self.ui_log.info("")
self._exit(0)
# read ftp URL from configuration
if self.cInfo['cmdlineopts'].upload:
upload_url = self.cInfo['cmdlineopts'].upload
else:
try:
upload_url = self.cInfo['config'].get("general", "ftp_upload_url")
except:
print _("No URL defined in config file.")
return
from urlparse import urlparse
url = urlparse(upload_url)
if url[0] != "ftp":
print _("Cannot upload to specified URL.")
return
# extract username and password from URL, if present
if url[1].find("@") > 0:
username, host = url[1].split("@", 1)
if username.find(":") > 0:
username, passwd = username.split(":", 1)
else:
passwd = None
else:
username, passwd, host = None, None, url[1]
# extract port, if present
if host.find(":") > 0:
host, port = host.split(":", 1)
port = int(port)
def print_header(self):
self.ui_log.info("\n%s\n" % _("sosreport (version %s)" % (__version__,)))
for plug in plugins:
plugbase, ext = os.path.splitext(plug)
try:
plugin_classes = import_plugin(plugbase, valid_plugin_classes)
if not len(plugin_classes):
# no valid plugin classes for this policy
continue
plugin_class = self.policy.match_plugin(plugin_classes)
if not validate_plugin(plugin_class,
experimental=self.opts.experimental):
self.soslog.warning(
_("plugin %s does not validate, skipping") % plug)
if self.opts.verbosity > 0:
self._skip(plugin_class, _("does not validate"))
continue
if plugin_class.requires_root and not self._is_root:
self.soslog.info(_("plugin %s requires root permissions"
"to execute, skipping") % plug)
self._skip(plugin_class, _("requires root"))
continue
# plug-in is valid, let's decide whether run it or not
self.plugin_names.append(plugbase)
in_profile = self._is_in_profile(plugin_class)
if not in_profile:
self._skip(plugin_class, _("excluded"))
continue
if not len(plugin_classes):
# no valid plugin classes for this policy
continue
plugin_class = self.policy.match_plugin(plugin_classes)
if not validate_plugin(plugin_class,
experimental=self.opts.experimental):
self.soslog.warning(
_("plugin %s does not validate, skipping") % plug)
if self.opts.verbosity > 0:
self._skip(plugin_class, _("does not validate"))
continue
if plugin_class.requires_root and not self._is_root:
self.soslog.info(_("plugin %s requires root permissions"
"to execute, skipping") % plug)
self._skip(plugin_class, _("requires root"))
continue
# plug-in is valid, let's decide whether run it or not
self.plugin_names.append(plugbase)
in_profile = self._is_in_profile(plugin_class)
if not in_profile:
self._skip(plugin_class, _("excluded"))
continue
if self._is_skipped(plugbase):
self._skip(plugin_class, _("skipped"))
continue
def print_header(self):
print("\n%s\n" % _("sosreport (version %s)" % (__version__,)))
return ret
def get_tmp_dir(self, opt_tmp_dir):
if not opt_tmp_dir:
return self._tmp_dir
return opt_tmp_dir
def get_local_name(self):
return self.host_name()
class OpenSuSEPolicy(SuSEPolicy):
distro = "OpenSuSE"
vendor = "SuSE"
vendor_url = "https://www.opensuse.org/"
msg = _("""\
This command will collect diagnostic and configuration \
information from this %(distro)s system and installed \
applications.
An archive containing the collected information will be \
generated in %(tmpdir)s and may be provided to a %(vendor)s \
support representative.
No changes will be made to system configuration.
%(vendor_text)s
""")
def __init__(self, sysroot=None):
super(OpenSuSEPolicy, self).__init__(sysroot=sysroot)
@classmethod
if not self.loaded_plugins and not self.skipped_plugins:
self.soslog.fatal(_("no valid plugins found"))
return
if self.loaded_plugins:
self.ui_log.info(_("The following plugins are currently enabled:"))
self.ui_log.info("")
for (plugname, plug) in self.loaded_plugins:
self.ui_log.info(" %-20s %s" % (plugname,
plug.get_description()))
else:
self.ui_log.info(_("No plugin enabled."))
self.ui_log.info("")
if self.skipped_plugins:
self.ui_log.info(_("The following plugins are currently "
"disabled:"))
self.ui_log.info("")
for (plugname, plugclass, reason) in self.skipped_plugins:
self.ui_log.info(" %-20s %-14s %s" % (
plugname,
reason,
plugclass.get_description()))
self.ui_log.info("")
if self.all_options:
self.ui_log.info(_("The following plugin options are available:"))
self.ui_log.info(_("\n Option 'timeout' available to all plugins -"
" time in seconds to allow plugin to run, use 0"
" for no timeout\n"))
for (plug, plugname, optname, optparm) in self.all_options:
if optname == 'timeout':