コード例 #1
0
 def run(self):
     LOG.info("addRecord called with: " + str(self.args))
     credentials = utils.getCredentials(self.args)
     url = utils.getUrl(self.args)
     data = utils.getData(self.args)
     if not self.args.test:
         response = utils.call(credentials, url, data)
         if self.args.verbose:
             print(response.text)
         if not response.ok:
             LOG.error("status: %s" % response.status_code)
             sys.exit(str(response.status_code))
         LOG.info("status: %s -- record key: %s" %
                  (response.status_code, response.text))
     else:
         print("Dry run; would call %s with %s" % (url, data))
コード例 #2
0
 def run(self):
     LOG.info("addRecord called with: " + str(self.args))
     credentials = utils.getCredentials(self.args)
     url = utils.getUrl(self.args)
     data = utils.getData(self.args)
     if not self.args.test:
         response = utils.call(credentials, url, data)
         if self.args.verbose:
             print(response.text)
         if not response.ok:
             LOG.error("status: %s" % response.status_code)
             sys.exit(str(response.status_code))
         LOG.info("status: %s -- record key: %s" % (response.status_code,
                                                    response.text))
     else:
         print("Dry run; would call %s with %s" % (url, data))
コード例 #3
0
    def reportStatistics(self, args):
        """
        Report statistical data on resource consumption to remote server
        """
        data = self._query_iCATDb()

        acctRecords = []
        acctRecords.append(self._toAccountingRecord(data))
        # adding the data to the args so other command line args
        # resp their defaults are available as well
        args.account = acctRecords[0]['account']
        args.value = acctRecords[0]['value']
        args.number = acctRecords[0]['number']
        pretty_data = json.dumps(acctRecords, indent=4)
        self.logger.info('Data: ' + pretty_data)

        credentials = utils.getCredentials(self.conf)
        self.logger.info("Credentials found")
        self.logger.debug("Credentials: " + str(credentials))
        url = utils.getUrl(self.conf)
        self.logger.info("URL to call: " + url)
        data = utils.getData(args)
        self.logger.info("Data as query string: " + data)

        if args.test:
            print("Test: Would send the following data: " \
                + data)
            return None

        response = utils.call(credentials, url, data)

        self.logger.info('Data sent. Status code: ' \
                         + str(response.status_code))
        if args.verbose:
            print("\nData sent. Status code: " \
                + str(response.status_code))
            print("Key of generated accounting record: " \
                + response.text)
コード例 #4
0
    def reportStatistics(self, args):
        """
        Report statistical data on resource consumption to remote server
        """
        data = self._query_iCATDb()

        acctRecords = []
        acctRecords.append(self._toAccountingRecord(data))
        # adding the data to the args so other command line args 
        # resp their defaults are available as well
        args.account = acctRecords[0]['account']
        args.value = acctRecords[0]['value']
        args.number = acctRecords[0]['number']
        pretty_data = json.dumps(acctRecords, indent=4)
        self.logger.info('Data: ' + pretty_data)

        credentials = utils.getCredentials(self.conf)
        self.logger.info("Credentials found")
        self.logger.debug("Credentials: " + str(credentials))
        url = utils.getUrl(self.conf)
        self.logger.info("URL to call: " + url)
        data = utils.getData(args)
        self.logger.info("Data as query string: " + data)

        if args.test:
            print("Test: Would send the following data: " \
                + data)
            return None

        response = utils.call(credentials, url, data)

        self.logger.info('Data sent. Status code: ' \
                         + str(response.status_code))
        if args.verbose:
            print("\nData sent. Status code: " \
                + str(response.status_code))
            print("Key of generated accounting record: " \
                + response.text)