def configure(config, args=None): global CONFIG if 'connections' in config and 'mysql' in config['connections']: helper.update_config(config['connections']['mysql'], CONFIG['connections']['mysql']) try: CONFIG['rrd']['dir'] = config['stats_poller']['rrd_db_dir'] except: pass try: helper.update_config( config['stats_poller']['connections']['mysql'], CONFIG['connections']['mysql'] ) except: pass try: CONFIG['rrd']['dir'] = config['load_statistics']['rrd']['dir'] except: pass try: helper.update_config( config['load_statistics']['connections']['mysql'], CONFIG['connections']['mysql'] ) except: pass if 'stats_cleaner' in config: helper.update_config(config['stats_cleaner'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000 )
def configure(config, args=None): enabled = config.get("analytics", {}).get("enabled", False) if not enabled: sys.stdout.write("Analytics is disabled\n") sys.exit(0) global CONFIG helper.update_config(config.get("connections", {}).get("mysql", {}), CONFIG["connections"]["mysql"]["scalr"]) helper.update_config( config.get("analytics", {}).get("connections", {}).get("scalr", {}), CONFIG["connections"]["mysql"]["scalr"] ) helper.update_config( config.get("analytics", {}).get("connections", {}).get("analytics", {}), CONFIG["connections"]["mysql"]["analytics"], ) helper.update_config(config.get("analytics", {}).get("processing", {}), CONFIG) helper.update_config(config_to=CONFIG, args=args) CONFIG["pool_size"] = max(21, CONFIG["pool_size"]) helper.validate_config(CONFIG) if CONFIG["recalculate"] and (not CONFIG["platform"] or not CONFIG["date_from"]): sys.stderr.write("Error. You must specify 'platform' and 'date-from' for recalculating\n") sys.exit(1) helper.configure_log(log_level=CONFIG["verbosity"], log_file=CONFIG["log_file"], log_size=1024 * 10000) global POOL POOL = Pool() global SCALR_DB SCALR_DB = dbmanager.ScalrDB(CONFIG["connections"]["mysql"]["scalr"]) global ANALYTICS_DB ANALYTICS_DB = dbmanager.DB(CONFIG["connections"]["mysql"]["analytics"])
def configure(config, args=None): enabled = config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled\n') sys.exit(0) global CONFIG helper.update_config( config.get('connections', {}).get('mysql', {}), CONFIG['connections']['scalr']) helper.update_config( config.get('analytics', {}).get('connections', {}).get('scalr', {}), CONFIG['connections']['scalr']) helper.update_config( config.get('analytics', {}).get('connections', {}).get('analytics', {}), CONFIG['connections']['analytics']) helper.update_config( config.get('analytics', {}).get('poller', {}), CONFIG) helper.update_config(config_to=CONFIG, args=args) CONFIG['pool_size'] = max(11, CONFIG['pool_size']) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000 ) socket.setdefaulttimeout(CONFIG['cloud_connection_timeout']) crypto_key_path = os.path.join(os.path.dirname(os.path.abspath(args.config_file)), '.cryptokey') global CRYPTO_KEY CRYPTO_KEY = cryptotool.read_key(crypto_key_path) global SCALR_DB SCALR_DB = dbmanager.ScalrDB(CONFIG['connections']['scalr']) global ANALYTICS_DB ANALYTICS_DB = dbmanager.ScalrDB(CONFIG['connections']['analytics'])
def configure(self): helper.update_config( self.scalr_config.get('msg_sender', {}), self.config) helper.validate_config(self.config) socket.setdefaulttimeout(self.config['instances_connection_timeout']) self._db = dbmanager.ScalrDB(self.config['connections']['mysql']) self._pool = helper.GPool(pool_size=self.config['pool_size'])
def configure(self): helper.update_config(self.scalr_config.get('dbqueue_event', {}), self.config) helper.validate_config(self.config) socket.setdefaulttimeout(self.config['instances_connection_timeout']) self._db = dbmanager.ScalrDB(self.config['connections']['mysql']) self._pool = helper.GPool(pool_size=self.config['pool_size'])
def configure(self): helper.update_config(self.scalr_config.get('msg_sender', {}), self.config) helper.validate_config(self.config) socket.setdefaulttimeout(self.config['instances_connection_timeout']) self._db = dbmanager.ScalrDB(self.config['connections']['mysql']) self._pool = helper.GPool(pool_size=self.config['pool_size']) self.max_processing_messages = 2 * self.config['pool_size']
def configure(self): helper.update_config(self.scalr_config.get("scalarizr_update", {}).get("service", {}), self.config) helper.validate_config(self.config) if self.config["interval"]: self.iteration_timeout = int(self.config["interval"]) socket.setdefaulttimeout(self.config["instances_connection_timeout"]) self._db = dbmanager.ScalrDB(self.config["connections"]["mysql"]) self._pool = helper.GPool(pool_size=self.config["pool_size"])
def configure(self): helper.update_config( self.scalr_config.get('scalarizr_update', {}).get('service', {}), self.config) helper.validate_config(self.config) if self.config['interval']: self.iteration_timeout = int(self.config['interval']) socket.setdefaulttimeout(self.config['instances_connection_timeout']) self._db = dbmanager.ScalrDB(self.config['connections']['mysql']) self._pool = helper.GPool(pool_size=self.config['pool_size'])
def load_config(self): try: self.scalr_config = yaml.safe_load(open(self.args['--config']))['scalr'] except: msg = 'Unable to load Scalr config.yml file, reason: {error}'.format( error=helper.exc_info()) raise Exception(msg) helper.update_config( self.scalr_config.get('connections', {}).get('mysql', {}), self.config['connections']['mysql']) self.config['instances_connection_timeout'] = self.scalr_config.get( 'system', {}).get( 'instances_connection_timeout', self.config['instances_connection_timeout'])
def __init__(self, config, args=None): for k, v in config.iteritems(): if k not in self.config: self.config[k] = v self.args = args or argparse.Namespace() self.configure() helper.update_config(config_to=self.config, args=args) helper.validate_config(self.config) helper.configure_log( log_level=self.config['verbosity'], log_file=self.config['log_file'], log_size=self.config['log_size']) super(Application, self).__init__(self.config['pid_file'])
def configure(self): helper.update_config( self.scalr_config.get('dbqueue_event', {}), self.config) helper.validate_config(self.config) socket.setdefaulttimeout(self.config['instances_connection_timeout']) self._db = dbmanager.ScalrDB(self.config['connections']['mysql']) self._pool = helper.GPool(pool_size=self.config['pool_size']) proxy_settings = helper.get_proxy_settings(self.scalr_config, 'system.webhooks') if proxy_settings: self.proxy = { 'http': proxy_settings['url'], 'https': proxy_settings['url'] }
def configure(config, args=None): global CONFIG helper.update_config(config["connections"]["mysql"], CONFIG["connections"]["mysql"]) if "email" in config: helper.update_config(config["email"], CONFIG["email"]) if "system" in config and "instances_connection_timeout" in config["system"]: timeout = config["system"]["instances_connection_timeout"] CONFIG["instances_connection_timeout"] = timeout if "dbqueue_event" in config: helper.update_config(config["dbqueue_event"], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log(log_level=CONFIG["verbosity"], log_file=CONFIG["log_file"], log_size=1024 * 1000)
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('poller', {}), self.config) helper.validate_config(self.config) self.config['pool_size'] = max(11, self.config['pool_size']) self.iteration_timeout = self.config['interval'] - 5 crypto_key_path = os.path.join(self.scalr_dir, 'app/etc/.cryptokey') self.crypto_key = cryptotool.read_key(crypto_key_path) self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.ScalrDB( self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self.pool = helper.GPool(pool_size=self.config['pool_size']) socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('processing', {}), self.config) helper.validate_config(self.config) self.config['pool_size'] = max(21, self.config['pool_size']) self.config['recalculate'] = self.args['--recalculate'] self.config['date_from'] = self.args['--date-from'] self.config['date_to'] = self.args['--date-to'] self.config['platform'] = self.args['--platform'] if self.config['recalculate']: self.iteration_timeout = None else: self.iteration_timeout = self.config['interval'] - 5 self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.DB(self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self._pool = helper.GPool(pool_size=self.config['pool_size']) socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(self): enabled = self.scalr_config.get("analytics", {}).get("enabled", False) if not enabled: sys.stdout.write("Analytics is disabled. Exit\n") sys.exit(0) helper.update_config( self.scalr_config.get("analytics", {}).get("connections", {}).get("scalr", {}), self.config["connections"]["mysql"], ) helper.update_config( self.scalr_config.get("analytics", {}).get("connections", {}).get("analytics", {}), self.config["connections"]["analytics"], ) helper.update_config(self.scalr_config.get("analytics", {}).get("poller", {}), self.config) helper.validate_config(self.config) self.config["pool_size"] = max(11, self.config["pool_size"]) self.iteration_timeout = self.config["interval"] - self.error_sleep crypto_key_path = os.path.join(os.path.dirname(self.args["--config"]), ".cryptokey") self.crypto_key = cryptotool.read_key(crypto_key_path) self.scalr_db = dbmanager.ScalrDB(self.config["connections"]["mysql"]) self.analytics_db = dbmanager.ScalrDB(self.config["connections"]["analytics"]) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self.pool = helper.GPool(pool_size=self.config["pool_size"]) self.set_proxy() socket.setdefaulttimeout(self.config["instances_connection_timeout"])
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('poller', {}), self.config) helper.validate_config(self.config) self.config['pool_size'] = max(11, self.config['pool_size']) self.iteration_timeout = self.config['interval'] - self.error_sleep crypto_key_path = os.path.join(os.path.dirname(self.args['--config']), '.cryptokey') self.crypto_key = cryptotool.read_key(crypto_key_path) self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.ScalrDB(self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self.pool = helper.GPool(pool_size=self.config['pool_size']) self.set_proxy() socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(args=None): global CONFIG helper.update_config( SCALR_CONFIG.get('connections', {}).get('mysql', {}), CONFIG['connections']['mysql']) helper.update_config(SCALR_CONFIG.get('scalarizr_update', {}).get('service', {}), CONFIG) inst_conn_timeout = SCALR_CONFIG.get('system', {}).get('instances_connection_timeout', None) if inst_conn_timeout: CONFIG['instances_connection_timeout'] = inst_conn_timeout helper.update_config(SCALR_CONFIG['scalarizr_update']['repos'], CONFIG['repos']) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000) socket.setdefaulttimeout(CONFIG['instances_connection_timeout'])
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) # set date_from if self.args['--date-from']: dtime_from = datetime.datetime.strptime(self.args['--date-from'], '%Y-%m-%d') two_weeks_ago = datetime.datetime.utcnow() + datetime.timedelta( days=-14) assert_msg = 'Processing is not supported for dtime-from more than two weeks ago' assert dtime_from > two_weeks_ago, assert_msg self.config['dtime_from'] = dtime_from # set date_to if self.args['--date-to']: dtime_to = datetime.datetime.strptime(self.args['--date-to'], '%Y-%m-%d') dtime_to = dtime_to.replace(minute=59, second=59) self.config['dtime_to'] = dtime_to # update config helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('processing', {}), self.config) self.config['platform'] = self.args['--platform'] or False helper.validate_config(self.config) self.iteration_timeout = self.config['interval'] - self.error_sleep crypto_key_path = os.path.join(os.path.dirname(self.args['--config']), '.cryptokey') self.crypto_key = cryptotool.read_key(crypto_key_path) self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.ScalrDB( self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self.pool = helper.GPool(pool_size=self.config['pool_size']) socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(config, args=None): global CONFIG helper.update_config(config['connections']['mysql'], CONFIG['connections']['mysql']) if 'stats_poller' in config: CONFIG['rrd_db_dir'] = config['stats_poller']['rrd_db_dir'] if 'connections' in config['stats_poller']: helper.update_config( config['stats_poller']['connections']['mysql'], CONFIG['connections']['mysql']) if 'stats_cleaner' in config: helper.update_config(config['stats_cleaner'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log(log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000)
def configure(config, args=None): global CONFIG helper.update_config(config['connections']['mysql'], CONFIG['connections']['mysql']) if 'email' in config: helper.update_config(config['email'], CONFIG['email']) if 'system' in config and 'instances_connection_timeout' in config[ 'system']: timeout = config['system']['instances_connection_timeout'] CONFIG['instances_connection_timeout'] = timeout if 'dbqueue_event' in config: helper.update_config(config['dbqueue_event'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log(log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000)
def configure(config, args=None): global CONFIG helper.update_config( config['connections']['mysql'], CONFIG['connections']['mysql']) if 'email' in config: helper.update_config(config['email'], CONFIG['email']) if 'system' in config and 'instances_connection_timeout' in config['system']: timeout = config['system']['instances_connection_timeout'] CONFIG['instances_connection_timeout'] = timeout if 'dbqueue_event' in config: helper.update_config(config['dbqueue_event'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000 )
def configure(config, args=None): global CONFIG helper.update_config(config['connections']['mysql'], CONFIG['connections']['mysql']) if 'msg_sender_alert' in config: helper.update_config(config['msg_sender_alert'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log(log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000)
def configure(config, args=None): global CONFIG helper.update_config(config['connections']['mysql'], CONFIG['connections']['mysql']) if 'stats_poller' in config: CONFIG['rrd_db_dir'] = config['stats_poller']['rrd_db_dir'] if 'connections' in config['stats_poller']: helper.update_config( config['stats_poller']['connections']['mysql'], CONFIG['connections']['mysql'] ) if 'stats_cleaner' in config: helper.update_config(config['stats_cleaner'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024*1000 )
def configure(config, args=None): global CONFIG helper.update_config(config['connections']['mysql'], CONFIG['connections']['mysql']) if 'dbqueue_event_alert' in config: helper.update_config(config['dbqueue_event_alert'], CONFIG) helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024*1000 )
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) # set date_from if self.args['--date-from']: dtime_from = datetime.datetime.strptime(self.args['--date-from'], '%Y-%m-%d') two_weeks_ago = datetime.datetime.utcnow() + datetime.timedelta(days=-14) assert_msg = 'Processing is not supported for dtime-from more than two weeks ago' assert dtime_from > two_weeks_ago, assert_msg self.config['dtime_from'] = dtime_from # set date_to if self.args['--date-to']: dtime_to = datetime.datetime.strptime(self.args['--date-to'], '%Y-%m-%d') dtime_to = dtime_to.replace(minute=59, second=59) self.config['dtime_to'] = dtime_to # update config helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('processing', {}), self.config) self.config['platform'] = self.args['--platform'] or False helper.validate_config(self.config) self.iteration_timeout = self.config['interval'] - self.error_sleep crypto_key_path = os.path.join(os.path.dirname(self.args['--config']), '.cryptokey') self.crypto_key = cryptotool.read_key(crypto_key_path) self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.ScalrDB(self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self.pool = helper.GPool(pool_size=self.config['pool_size']) socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('processing', {}), self.config) helper.validate_config(self.config) self.config['pool_size'] = max(21, self.config['pool_size']) self.config['recalculate'] = self.args['--recalculate'] self.config['date_from'] = self.args['--date-from'] self.config['date_to'] = self.args['--date-to'] self.config['platform'] = self.args['--platform'] if self.config['recalculate']: self.iteration_timeout = None else: self.iteration_timeout = self.config['interval'] - 5 self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.DB( self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) self._pool = helper.GPool(pool_size=self.config['pool_size']) socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(args=None): global CONFIG, SCALR_CONFIG helper.update_config( SCALR_CONFIG.get('connections', {}).get('mysql', {}), CONFIG['connections']['mysql']) helper.update_config(SCALR_CONFIG.get('load_statistics', {}), CONFIG) inst_conn_timeout = SCALR_CONFIG.get('system', {}).get('instances_connection_timeout', None) if inst_conn_timeout: CONFIG['instances_connection_timeout'] = inst_conn_timeout helper.update_config(config_to=CONFIG, args=args) helper.validate_config(CONFIG) helper.configure_log( log_level=CONFIG['verbosity'], log_file=CONFIG['log_file'], log_size=1024 * 1000) socket.setdefaulttimeout(CONFIG['instances_connection_timeout']) if CONFIG['connections']['plotter']['scheme'] == 'https': try: import OpenSSL except ImportError: msg = "Configure failed, https is not supported, reason: PyOpenSSL is not installed" raise Exception(msg) if not os.path.exists(os.path.dirname(CONFIG['rrd']['rrdcached_sock_path'])): os.makedirs(os.path.dirname(CONFIG['rrd']['rrdcached_sock_path']), 0755) rrd.RRDCACHED_SOCK_FILE = CONFIG['rrd']['rrdcached_sock_path']
def configure(self): helper.update_config( self.scalr_config.get('load_statistics', {}), self.config) helper.validate_config(self.config) socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) utcnow = datetime.datetime.utcnow().replace(microsecond=0) if self.args['--date-from']: dtime_from = datetime.datetime.strptime(self.args['--date-from'], '%Y-%m-%d') if not self.args['--recalculate']: if self.args['--billing'] in ('aws-detailed-billing', 'azure'): three_months_ago = utcnow + datetime.timedelta(days=-119) assert_msg = 'Processing is not supported for dtime-from more than four months ago' assert dtime_from > three_months_ago, assert_msg else: two_weeks_ago = utcnow + datetime.timedelta(days=-14) assert_msg = 'Processing is not supported for dtime-from more than two weeks ago' assert dtime_from > two_weeks_ago, assert_msg self.config['dtime_from'] = dtime_from if self.args['--date-to']: dtime_to = datetime.datetime.strptime(self.args['--date-to'], '%Y-%m-%d') self.config['dtime_to'] = dtime_to helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('processing', {}), self.config) if self.args['--billing']: self.config['billing'] = (self.args['--billing'],) if self.args['--platform']: assert_msg = "--platform option supported only for 'poller' billing type" assert 'poller' in self.config['billing'], assert_msg self.config['platform'] = (self.args['--platform'],) helper.validate_config(self.config) crypto_key_path = os.path.join(os.path.dirname(self.args['--config']), '.cryptokey') self.config['crypto_key'] = cryptotool.read_key(crypto_key_path) self.config['azure_app_client_id'] = self.scalr_config.get('azure', {}).get('app_client_id') self.config['azure_app_secret_key'] = self.scalr_config.get('azure', {}).get('app_secret_key') self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.ScalrDB(self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) if self.args['--year']: # XXX pymysql.connect issue time.sleep(0) quarters_calendar = self.analytics.get_quarters_calendar() year = int(self.args['--year']) quarter = int(self.args['--quarter'] or 1) dtime_from, dtime_to = quarters_calendar.dtime_for_quarter(quarter, year=year) self.config['dtime_from'] = dtime_from self.config['dtime_to'] = min(utcnow, dtime_to) self.config['proxy']['aws'] = helper.get_proxy_settings(self.scalr_config, 'aws') self.config['proxy']['azure'] = helper.get_proxy_settings(self.scalr_config, 'azure') socket.setdefaulttimeout(self.config['instances_connection_timeout'])
def configure(self): enabled = self.scalr_config.get('analytics', {}).get('enabled', False) if not enabled: sys.stdout.write('Analytics is disabled. Exit\n') sys.exit(0) utcnow = datetime.datetime.utcnow().replace(microsecond=0) if self.args['--date-from']: dtime_from = datetime.datetime.strptime(self.args['--date-from'], '%Y-%m-%d') if not self.args['--recalculate']: if self.args['--billing'] in ('aws-detailed-billing', 'azure'): three_months_ago = utcnow + datetime.timedelta(days=-119) assert_msg = 'Processing is not supported for dtime-from more than four months ago' assert dtime_from > three_months_ago, assert_msg else: two_weeks_ago = utcnow + datetime.timedelta(days=-14) assert_msg = 'Processing is not supported for dtime-from more than two weeks ago' assert dtime_from > two_weeks_ago, assert_msg self.config['dtime_from'] = dtime_from if self.args['--date-to']: dtime_to = datetime.datetime.strptime(self.args['--date-to'], '%Y-%m-%d') self.config['dtime_to'] = dtime_to helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('scalr', {}), self.config['connections']['mysql']) helper.update_config( self.scalr_config.get('analytics', {}).get('connections', {}).get('analytics', {}), self.config['connections']['analytics']) helper.update_config( self.scalr_config.get('analytics', {}).get('processing', {}), self.config) if self.args['--billing']: self.config['billing'] = (self.args['--billing'], ) if self.args['--platform']: assert_msg = "--platform option supported only for 'poller' billing type" assert 'poller' in self.config['billing'], assert_msg self.config['platform'] = (self.args['--platform'], ) helper.validate_config(self.config) crypto_key_path = os.path.join(os.path.dirname(self.args['--config']), '.cryptokey') self.config['crypto_key'] = cryptotool.read_key(crypto_key_path) self.config['azure_app_client_id'] = self.scalr_config.get( 'azure', {}).get('app_client_id') self.config['azure_app_secret_key'] = self.scalr_config.get( 'azure', {}).get('app_secret_key') self.scalr_db = dbmanager.ScalrDB(self.config['connections']['mysql']) self.analytics_db = dbmanager.ScalrDB( self.config['connections']['analytics']) self.analytics = analytics.Analytics(self.scalr_db, self.analytics_db) if self.args['--year']: # XXX pymysql.connect issue time.sleep(0) quarters_calendar = self.analytics.get_quarters_calendar() year = int(self.args['--year']) quarter = int(self.args['--quarter'] or 1) dtime_from, dtime_to = quarters_calendar.dtime_for_quarter( quarter, year=year) self.config['dtime_from'] = dtime_from self.config['dtime_to'] = min(utcnow, dtime_to) self.config['proxy']['aws'] = helper.get_proxy_settings( self.scalr_config, 'aws') self.config['proxy']['azure'] = helper.get_proxy_settings( self.scalr_config, 'azure') socket.setdefaulttimeout(self.config['instances_connection_timeout'])