def parse_config(self):
        """Parse charm configuration and calculate values for config files."""
        config = config_get()
        mysql_config = {}
        if 'max-connections' in config:
            mysql_config['max_connections'] = config['max-connections']

        if 'wait-timeout' in config:
            mysql_config['wait_timeout'] = config['wait-timeout']

        if 'innodb-flush-log-at-trx-commit' in config:
            mysql_config['innodb_flush_log_at_trx_commit'] = \
                config['innodb-flush-log-at-trx-commit']
        elif 'tuning-level' in config:
            mysql_config['innodb_flush_log_at_trx_commit'] = \
                self.INNODB_FLUSH_CONFIG_VALUES.get(config['tuning-level'], 1)

        if ('innodb-change-buffering' in config and
                config['innodb-change-buffering'] in self.INNODB_VALID_BUFFERING_VALUES):
            mysql_config['innodb_change_buffering'] = config['innodb-change-buffering']

        if 'innodb-io-capacity' in config:
            mysql_config['innodb_io_capacity'] = config['innodb-io-capacity']

        # Set a sane default key_buffer size
        mysql_config['key_buffer'] = self.human_to_bytes('32M')
        total_memory = self.human_to_bytes(self.get_mem_total())

        dataset_bytes = config.get('dataset-size', None)
        innodb_buffer_pool_size = config.get('innodb-buffer-pool-size', None)

        if innodb_buffer_pool_size:
            innodb_buffer_pool_size = self.human_to_bytes(
                innodb_buffer_pool_size)
        elif dataset_bytes:
            log("Option 'dataset-size' has been deprecated, please use"
                "innodb_buffer_pool_size option instead", level="WARN")
            innodb_buffer_pool_size = self.human_to_bytes(
                dataset_bytes)
        else:
            # NOTE(jamespage): pick the smallest of 50% of RAM or 512MB
            #                  to ensure that deployments in containers
            #                  without constraints don't try to consume
            #                  silly amounts of memory.
            innodb_buffer_pool_size = min(
                int(total_memory * self.DEFAULT_INNODB_BUFFER_FACTOR),
                self.DEFAULT_INNODB_BUFFER_SIZE_MAX
            )

        if innodb_buffer_pool_size > total_memory:
            log("innodb_buffer_pool_size; {} is greater than system available memory:{}".format(
                innodb_buffer_pool_size,
                total_memory), level='WARN')

        mysql_config['innodb_buffer_pool_size'] = innodb_buffer_pool_size
        return mysql_config
def parse_config ( self ) : config = config_get ( ) mysql_config = { } if 'max-connections' in config : mysql_config [ 'max_connections' ] = config [ 'max-connections' ] if 'wait-timeout' in config : mysql_config [ 'wait_timeout' ] = config [ 'wait-timeout' ] if 'innodb-flush-log-at-trx-commit' in config : mysql_config [ 'innodb_flush_log_at_trx_commit' ] = config [ 'innodb-flush-log-at-trx-commit' ] elif 'tuning-level' in config : mysql_config [ 'innodb_flush_log_at_trx_commit' ] = self . INNODB_FLUSH_CONFIG_VALUES . get ( config [ 'tuning-level' ] , 1 ) if ( 'innodb-change-buffering' in config and config [ 'innodb-change-buffering' ] in self . INNODB_VALID_BUFFERING_VALUES ) : mysql_config [ 'innodb_change_buffering' ] = config [ 'innodb-change-buffering' ] if 'innodb-io-capacity' in config : mysql_config [ 'innodb_io_capacity' ] = config [ 'innodb-io-capacity' ] mysql_config [ 'key_buffer' ] = self . human_to_bytes ( '32M' ) total_memory = self . human_to_bytes ( self . get_mem_total ( ) ) dataset_bytes = config . get ( 'dataset-size' , None ) innodb_buffer_pool_size = config . get ( 'innodb-buffer-pool-size' , None ) if innodb_buffer_pool_size : innodb_buffer_pool_size = self . human_to_bytes ( innodb_buffer_pool_size ) elif dataset_bytes : log ( "Option 'dataset-size' has been deprecated, please use" "innodb_buffer_pool_size option instead" , level = "WARN" ) innodb_buffer_pool_size = self . human_to_bytes ( dataset_bytes ) else : innodb_buffer_pool_size = min ( int ( total_memory * self . DEFAULT_INNODB_BUFFER_FACTOR ) , self . DEFAULT_INNODB_BUFFER_SIZE_MAX ) if innodb_buffer_pool_size > total_memory : log ( "innodb_buffer_pool_size; {} is greater than system available memory:{}" . format ( innodb_buffer_pool_size , total_memory ) , level = 'WARN' ) mysql_config [ 'innodb_buffer_pool_size' ] = innodb_buffer_pool_size return mysql_config
Parse charm configuration and calculate values for config files.