Database Connection Settings

Asterisk Configuration File

This module is used to read the database settings from an Asterisk configuration file. It uses the Python ConfigParser to load the setting values directly from the specified section (context) of the Asterisk configuration file.

Note

You need the MySQL Connector/Python installed on your system to connect to the database.

Example

Import the module, get the config settings, and pass them to your mysql connection:

import ivr.connection

config = ivr.connection.config()
 -or-
config = ivr.connection.config('context')

database = mysql.connect(**config)

Configuration

connection.asterisk_path = '/etc/asterisk'

String – Asterisk Configuration Directory Path

The path to the Asterisk Configuration Files for your installation.

connection.asterisk_conf = 'res_config_mysql.conf'

String – Name of the configuration file you want to use.

Warning

The MySQL Connector/Python does not support DSN configuration options.

Do not use Asterisk ODBC configuration files!

You can use any Asterisk configuration file that contains the host, database, user, and password details. You could create a dedicate configuration file too.

connection.context = 'general'

String – The section (context) of the configuration file to use.

The Asterisk configuration file can be read by the Python ConfigParser. Just specify the section of the configuration you would like to use. The section is contained in square brackets, as shown in the following configuration file example:

[general]
dbhost = 127.0.0.1
dbname = asterisk
dbuser = myuser
dbpass = mypass
dbport = 3306
dbsock = /tmp/mysql.sock
dbcharset = utf8
requirements=warn  ; or createclose or createchar

Connection Settings

connection.config = <function config>