def put(self, name, device_id, date_time): power_usage = request.args.get('power_usage') abort_when_not_int(power_usage) power_usage = int(power_usage) try: datetime.datetime.strptime(date_time, '%Y-%m-%dT%H:%M') except ValueError: abort(400) computation_node = abort_when_node_not_found(name) abort_when_device_not_found(device_id, computation_node) if database.check_stats_present(name, device_id): database.update_stats_data(name, device_id, {date_time: power_usage}) log.debug('Stats updated for device %s:%s, date: %s, power usage: %s', name, device_id, date_time, power_usage) else: database.replace_stats_data(name, device_id, {'name': name, 'device_id': device_id, date_time: power_usage}) log.debug('Stats set for device %s:%s, date: %s, power usage: %s', name, device_id, date_time, power_usage) interval_info = database.get_stats_interval_info(name, device_id) interval = datetime.timedelta(minutes=interval_info['interval']) new_next_measurement = (datetime.datetime.utcnow() + interval) new_next_measurement_str = new_next_measurement.strftime('%Y-%m-%dT%H:%M') # pylint: disable=no-member interval_info['next_measurement'] = new_next_measurement_str database.replace_stats_interval_info(name, device_id, interval_info) return 'Statistics data successfully set', 201
def parse_args(argv): parser = create_parser() log.debug('parser created') add_arguments_to_parser(parser) args = parser.parse_args(argv) log.debug('arguments parsed') return args
def parse_config_file(config_file_path): config = configparser.ConfigParser() config.read(config_file_path) log.debug(str.format('Application configuration loaded from {}', config_file_path)) return config
def configure_logging(config_file_path): logging.config.fileConfig(config_file_path) log.debug(str.format('Logging configuration loaded from {}', config_file_path))
def create_parser(): log.debug('creating argument parser') return argparse.ArgumentParser(description='HPC Power Management - API')
def run(port): http_server = HTTPServer(WSGIContainer(flask_app)) http_server.bind(port, '0.0.0.0') log.debug('HTTP server starting') http_server.start(5) IOLoop.instance().start()