def postinit(self): kb_object = None self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() kb_object = api.solutions.get(self.solutionID) if not self._parse_solution_sections(kb_object): raise Exception() except Exception: # See if the given ID is an article. try: kb_object = api.articles.get(self.solutionID) if not self._parse_article_sections(kb_object): raise Exception() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise except RequestError, re: msg = _('Unable to connect to support services API. ' 'Reason: %s') % re.reason print msg logger.log(logging.WARNING, msg) raise
def downloaduuid(self, uuid, filename=None, length=None): api = None try: api = apihelper.get_api() if not length: logger.debug("Getting attachment length ...") print _("Downloading ... "), sys.stdout.flush() all_attachments = api.attachments.list( self._options['casenumber']) for attach in all_attachments: if attach.get_uuid() == uuid: length = attach.get_length() logger.debug("... %d bytes" % length) break filename = api.attachments.get( caseNumber=self._options['casenumber'], attachmentUUID=uuid, fileName=filename, attachmentLength=length, destDir=self._options['destdir']) print _('File downloaded to %s') % (filename) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): kb_object = None self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() kb_object = api.solutions.get(self.solutionID) if not self._parse_solution_sections(kb_object): raise Exception() except Exception: # See if the given ID is an article. try: kb_object = api.articles.get(self.solutionID) if not self._parse_article_sections(kb_object): raise Exception() except EmptyValueError, eve: msg = _("ERROR: %s") % str(eve) print msg logger.log(logging.WARNING, msg) raise except RequestError, re: msg = _("Unable to connect to support services API. " "Reason: %s") % re.reason print msg logger.log(logging.WARNING, msg) raise
def downloaduuid(self, uuid, filename=None, length=None): api = None try: api = apihelper.get_api() if not length: logger.debug("Getting attachment length ...") print _("Downloading ... "), sys.stdout.flush() all_attachments = api.attachments.list(self._options['casenumber']) for attach in all_attachments: if attach.get_uuid() == uuid: length = attach.get_length() logger.debug("... %d bytes" % length) break filename = api.attachments.get( caseNumber=self._options['casenumber'], attachmentUUID=uuid, fileName=filename, attachmentLength=length, destDir=self._options['destdir']) print _('File downloaded to %s') % (filename) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _get_solutions(self, searchopts): api = None try: api = apihelper.get_api() return api.solutions.list(self._line, searchopts=searchopts) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _listattachs(self): api = None try: api = apihelper.get_api() return api.attachments.list(self._options['casenumber']) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _listattachs(self): api = None try: api = apihelper.get_api() return api.attachments.list(self._options['casenumber']) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _get_solutions(self, searchopts): api = None try: api = apihelper.get_api() return api.solutions.list(self._line, searchopts=searchopts) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def get_statuses(): ''' A utility function to get the available statuses from the API. ''' api = None try: api = apihelper.get_api() statusesAry = api.values.getStatus() return statusesAry except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def get_groups(): ''' A utility function to get the available groups from the API. ''' api = None try: api = apihelper.get_api() groupsAry = api.groups.list() return groupsAry except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def get_statuses(): ''' A utility function to get the available statuses from the API. ''' api = None try: api = apihelper.get_api() statusesAry = api.values.getStatus() return statusesAry except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() self.aAry = api.attachments.list(self.case) if not self._parse_cases(): raise Exception() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def get_groups(): ''' A utility function to get the available groups from the API. ''' api = None try: api = apihelper.get_api() groupsAry = api.groups.list() return groupsAry except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() self._case = api.cases.get(self._caseNumber) # Case needs to be retrieved before check version. # Product needs to be retrieved to check version self._check_ver() self._createDisplayOpts() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _check_owner(self): # Firstly, determine for whom listcases is being run and if they're a # Red Hat employee (isInternal == True) or not # If they're internal, then display the open cases they *own* in SFDC # ...except however if the -o all, -g or -u options are specified, then # it displays cases in the Red Hat employee's account. # If they're not internal, then display the open cases in their account try: api = apihelper.get_api() username = api.config.username userobj = contextmanager.get('user') if not userobj: userobj = api.users.get(username) contextmanager.add('user', userobj) if self._options['owner']: if not userobj.isInternal: raise Exception("The -o switch is only available to Red Hat" " employees") elif self._options['owner'].lower() != 'all': username = self._options['owner'] userobj = api.users.get(username) if not userobj.isInternal: # for some reason RH users can't display non-RH users raise Exception("Red Hat employees are unable to list" "cases for non-Red Hat portal users.") if userobj.isInternal: if not (str(self._options['owner']).lower() == 'all' or self._caseGroupNumbers or self._options['ungrouped']): # this will trigger the display of cases owned as per SFDC self._associateSSOName = username self._view = 'internal' except RequestError, re: if re.status == 404: msg = _("Unable to find user %s" % username) else: msg = _('Problem querying the support services API. Reason: ' '%s' % re.reason) print msg logger.log(logging.WARNING, msg) raise
def _check_owner(self): # Firstly, determine for whom listcases is being run and if they're a # Red Hat employee (isInternal == True) or not # If they're internal, then display the open cases they *own* in SFDC # ...except however if the -o all, -g or -u options are specified, then # it displays cases in the Red Hat employee's account. # If they're not internal, then display the open cases in their account try: api = apihelper.get_api() username = api.config.username userobj = contextmanager.get('user') if not userobj: userobj = api.users.get(username) contextmanager.add('user', userobj) if self._options['owner']: if not userobj.isInternal: raise Exception( "The -o switch is only available to Red Hat" " employees") elif self._options['owner'].lower() != 'all': username = self._options['owner'] userobj = api.users.get(username) if not userobj.isInternal: # for some reason RH users can't display non-RH users raise Exception("Red Hat employees are unable to list" "cases for non-Red Hat portal users.") if userobj.isInternal: if not (str(self._options['owner']).lower() == 'all' or self._caseGroupNumbers or self._options['ungrouped']): # this will trigger the display of cases owned as per SFDC self._associateSSOName = username self._view = 'internal' except RequestError, re: if re.status == 404: msg = _("Unable to find user %s" % username) else: msg = _('Problem querying the support services API. Reason: ' '%s' % re.reason) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() self._case = api.cases.get(self._caseNumber) # Case needs to be retrieved before check version. # Product needs to be retrieved to check version self._check_ver() self._createDisplayOpts() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() self.case_obj = api.cases.get(self.case) # add the case group info (if it exists) to the case object self.case_obj.group = None case_group = self.case_obj.get_folderNumber() if case_group: self.case_obj.group = api.groups.get(case_group) if not self._parse_sections(self.case_obj): raise Exception() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() self.case_obj = api.cases.get(self.case) # add the case group info (if it exists) to the case object self.case_obj.group = None case_group = self.case_obj.get_folderNumber() if case_group: self.case_obj.group = api.groups.get(case_group) if not self._parse_sections(self.case_obj): raise Exception() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def non_interactive_action(self): api = None try: api = apihelper.get_api() if not self.comment: print _('ERROR: The comment has no content.') raise Exception() com = api.im.makeComment(caseNumber=self._options['casenumber'], public=self._options['public'], text=self.comment) retVal = api.comments.add(com) if retVal is None: print _('ERROR: There was a problem adding your comment ' 'to %s') % self._options['casenumber'] raise Exception() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _get_cases(self, searchopts): api = None try: api = apihelper.get_api() filt = api.im.makeCaseFilter( count=searchopts['count'], start=searchopts['start'], includeClosed=self._options['includeclosed'], groupNumbers=self._caseGroupNumbers, associateSSOName=self._associateSSOName, view=self._view, sortField=self._options['sortfield'], sortOrder=self._options['sortorder'], #keyword=self._options['keyword'], onlyUngrouped=self._options['ungrouped']) return api.cases.filter(filt) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def _get_cases(self, searchopts): api = None try: api = apihelper.get_api() filt = api.im.makeCaseFilter( count=searchopts['count'], start=searchopts['start'], includeClosed=self._options['includeclosed'], groupNumbers=self._caseGroupNumbers, associateSSOName=self._associateSSOName, view=self._view, sortField=self._options['sortfield'], sortOrder=self._options['sortorder'], #keyword=self._options['keyword'], onlyUngrouped=self._options['ungrouped']) return api.cases.filter(filt) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def postinit(self): self._submenu_opts = deque() self._sections = {} api = None try: api = apihelper.get_api() if not os.path.isfile(self._line): self._pAry = api.problems.diagnoseStr(self._line) else: report_file = os.path.expanduser(self._line) self._pAry = api.problems.diagnoseFile(report_file) if len(self._pAry) > 0: if not self._parse_problem(): raise Exception() else: raise Exception() except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def non_interactive_action(self): api = None updatemsg = None if self.use_ftp: uploadloc = libconfig.ftp_host else: uploadloc = "the case" caseNumber = self._options['casenumber'] uploadBaseName = os.path.basename(self.upload_file) try: try: api = apihelper.get_api() print _("Uploading %s to %s ..." % (uploadBaseName, uploadloc)), sys.stdout.flush() if self.split_attachment: chunk = { 'num': 0, 'names': [], 'size': self._options.get('splitsize', self.max_split_size) } retVal = api.attachments.add( caseNumber=caseNumber, public=self._options['public'], fileName=self.upload_file, fileChunk=chunk, description=self._options['description'], useFtp=self.use_ftp) if retVal: print _("completed successfully.") updatemsg = _('[RHST] The following split files were ' 'uploaded to %s:\n' % uploadloc) for chunk_name in chunk['names']: updatemsg += _('\n %s' % chunk_name) else: retVal = api.attachments.add( caseNumber=caseNumber, public=self._options['public'], fileName=self.upload_file, description=self._options['description'], useFtp=self.use_ftp) if retVal: print _("completed successfully.") if self.use_ftp: updatemsg = _('[RHST] The following attachment was' ' uploaded to %s:\n\n %s-%s' % (libconfig.ftp_host, caseNumber, uploadBaseName)) if retVal is None: raise Exception() if updatemsg: lh = LaunchHelper(AddComment) comment_displayopt = ObjectDisplayOption( None, None, [updatemsg]) lh.run('-c %s' % caseNumber, comment_displayopt) except EmptyValueError, eve: msg = _("ERROR: %s") % str(eve) print _("failed.\n" + msg) logger.error(msg) raise except RequestError, re: msg = _("ERROR: Unable to connect to support services API. " "Reason: %s " % re.reason) print _("failed.\n" + msg) logger.error(msg) raise
def non_interactive_action(self): api = None try: api = apihelper.get_api() case = api.im.makeCase() case.summary = self._options['summary'] case.product = self._options['product'] case.version = self._options['version'] case.description = self._options['description'] case.severity = self._options['severity'] if self._options['casegroup']: case.folderNumber = self._options['casegroupnumber'] if common.is_interactive(): line = raw_input(_('Would see if there is a solution to this ' 'problem before opening a support case? (y/N) ')) line = str(line).strip().lower() if line == 'y': recommendations = api.problems.diagnoseCase(case) recprompt, recdoc = \ recommendationprompter.generate_metadata( recommendations) lh = LaunchHelper(GenericPrompt) lh.run('', recprompt, prompt=_(\ 'Selection (q returns to case creation menu): ')) line = raw_input(\ _('Would you still like to open the support' ' case? (Y/n) ')) if line.lower() == 'n': print _('Thank you for using Red Hat Access') return cs = api.cases.add(case) if cs.get_caseNumber() is None: msg = _("ERROR: There was a problem creating your case.") print msg raise Exception(msg) self._caseNumber = cs.get_caseNumber() print '%s%s%s' % (Constants.BOLD, str('-' * Constants.MAX_RULE), Constants.END) msg = _("Support case %s has successfully been opened.\n") % \ self._caseNumber print msg logger.log(logging.INFO, msg) # Attach a file if self._options['attachment']: lh = LaunchHelper(AddAttachment) lh.run('-c %s -d \'[RHST] File %s \' %s' % ( self._caseNumber, os.path.basename(self._options['attachment']), self._options['attachment'])) elif (os.geteuid() == 0): sys.stdout.write(_( 'Would you like Red Hat Support Tool to automatically generate and\n' 'attach a SoS report to %s now? (y/N) ') % (self._caseNumber)) line = raw_input() line = str(line).strip() if line == 'y': # retval = os.system('sosreport') p = sub.Popen(['sosreport', '--batch'], stdout=sub.PIPE, stderr=sub.STDOUT) output = p.communicate()[0].split('\n') for out in output: if '.tar.' in out: path = str(out).strip() lh = LaunchHelper(AddAttachment) lh.run('-c %s %s' % (self._caseNumber, path)) break else: print _( 'Please attach a SoS report to support case %s. Create a SoS report as\n' 'the root user and execute the following command to attach the SoS report\n' 'directly to the case:\n' ' redhat-support-tool addattachment -c %s <path to sosreport>\n') % \ (self._caseNumber, self._caseNumber) if not self._options['attachment']: line = raw_input(_('Would you like to attach a file to %s ' 'at this time? (y/N) ') % self._caseNumber) line = str(line).strip() if line == 'y': lh = LaunchHelper(AddAttachment) lh.run('-c %s' % (self._caseNumber)) except EmptyValueError, eve: msg = _('ERROR: %s') % str(eve) print msg logger.log(logging.WARNING, msg) raise
def non_interactive_action(self): api = None updatemsg = None if self.use_ftp: uploadloc = libconfig.ftp_host else: uploadloc = "the case" caseNumber = self._options['casenumber'] uploadBaseName = os.path.basename(self.upload_file) try: try: api = apihelper.get_api() print _("Uploading %s to %s ..." % (uploadBaseName, uploadloc)), sys.stdout.flush() if self.split_attachment: chunk = {'num': 0, 'names': [], 'size': self._options.get( 'splitsize', self.max_split_size)} retVal = api.attachments.add( caseNumber=caseNumber, public=self._options['public'], fileName=self.upload_file, fileChunk=chunk, description=self._options['description'], useFtp=self.use_ftp) if retVal: print _("completed successfully.") updatemsg = _('[RHST] The following split files were ' 'uploaded to %s:\n' % uploadloc) for chunk_name in chunk['names']: updatemsg += _('\n %s' % chunk_name) else: retVal = api.attachments.add( caseNumber=caseNumber, public=self._options['public'], fileName=self.upload_file, description=self._options['description'], useFtp=self.use_ftp) if retVal: print _("completed successfully.") if self.use_ftp: updatemsg = _('[RHST] The following attachment was' ' uploaded to %s:\n\n %s-%s' % (libconfig.ftp_host, caseNumber, uploadBaseName)) if retVal is None: raise Exception() if updatemsg: lh = LaunchHelper(AddComment) comment_displayopt = ObjectDisplayOption(None, None, [updatemsg]) lh.run('-c %s' % caseNumber, comment_displayopt) except EmptyValueError, eve: msg = _("ERROR: %s") % str(eve) print _("failed.\n" + msg) logger.error(msg) raise except RequestError, re: msg = _("ERROR: Unable to connect to support services API. " "Reason: %s " % re.reason) print _("failed.\n" + msg) logger.error(msg) raise
def non_interactive_action(self): api = None try: api = apihelper.get_api() case = api.im.makeCase() case.summary = self._options['summary'] case.product = self._options['product'] case.version = self._options['version'] case.description = self._options['description'] case.severity = self._options['severity'] if self._options['casegroup']: case.folderNumber = self._options['casegroupnumber'] if common.is_interactive(): line = raw_input( _('Would see if there is a solution to this ' 'problem before opening a support case? (y/N) ')) line = str(line).strip().lower() if line == 'y': recommendations = api.problems.diagnoseCase(case) recprompt, recdoc = \ recommendationprompter.generate_metadata( recommendations) lh = LaunchHelper(GenericPrompt) lh.run('', recprompt, prompt=_(\ 'Selection (q returns to case creation menu): ')) line = raw_input(\ _('Would you still like to open the support' ' case? (Y/n) ')) if line.lower() == 'n': print _('Thank you for using Red Hat Access') return cs = api.cases.add(case) if cs.get_caseNumber() is None: msg = _("ERROR: There was a problem creating your case.") print msg raise Exception(msg) self._caseNumber = cs.get_caseNumber() print '%s%s%s' % (Constants.BOLD, str( '-' * Constants.MAX_RULE), Constants.END) msg = _("Support case %s has successfully been opened.\n") % \ self._caseNumber print msg logger.log(logging.INFO, msg) # Attach a file if self._options['attachment']: lh = LaunchHelper(AddAttachment) lh.run('-c %s -d \'[RHST] File %s \' %s' % (self._caseNumber, os.path.basename(self._options['attachment']), self._options['attachment'])) elif (os.geteuid() == 0): sys.stdout.write( _('Would you like Red Hat Support Tool to automatically generate and\n' 'attach a SoS report to %s now? (y/N) ') % (self._caseNumber)) line = raw_input() line = str(line).strip() if line == 'y': # retval = os.system('sosreport') p = sub.Popen(['sosreport', '--batch'], stdout=sub.PIPE, stderr=sub.STDOUT) output = p.communicate()[0].split('\n') for out in output: if '.tar.' in out: path = str(out).strip() lh = LaunchHelper(AddAttachment) lh.run('-c %s %s' % (self._caseNumber, path)) break else: print _( 'Please attach a SoS report to support case %s. Create a SoS report as\n' 'the root user and execute the following command to attach the SoS report\n' 'directly to the case:\n' ' redhat-support-tool addattachment -c %s <path to sosreport>\n') % \ (self._caseNumber, self._caseNumber) if not self._options['attachment']: line = raw_input( _('Would you like to attach a file to %s ' 'at this time? (y/N) ') % self._caseNumber) line = str(line).strip() if line == 'y': lh = LaunchHelper(AddAttachment) lh.run('-c %s' % (self._caseNumber))