Managing Network Communications in Python

As explained in the Network Communications page, eXtremeDB release 7.1.1795 and later allow the IPv6 address protocol for specifying node addresses. The following section describes issues that can be important for developers porting applications that used network communications in prior versions of eXtremeDB. The OpenSSL section describes how to enable SSL security for network communications.

IPv4 vs. IPv6 issues

For developers porting applications built with versions of eXtremeDB prior to release 7.1.1795 the following API changes should be noted:

 

OpenSSL support

To enable SSL support, the application must first initialize the SSL layer and set verify locations with the following calls:

 
    >>>exdb.ssl_init()
    >>>exdb. ssl_load_verify_locations(ca_file, ca_path)
     

The SSL layer parameters are defined in a Python dictionary. For example:

 
    ssl_params=
    {
        'verify_mode'  : self.exdb.SSLVerifyMode.VerifyPeer |
            self.exdb.SSLVerifyMode.VerifyFailIfNoPeerCert,
        'cert_file_pem': "../../thlib/certs/client.crt",
        'pkey_file_pem': "../../thlib/certs/client.key"
    }
     

(Please refer to the OpenSSL Parameters page for details on setting the values of verify_mode, cert_file_pem and pkey_file_pem).

SSL Security with SQL

The connect() method accepts arguments sql_login, sql_password, and ssl_params to create a RemoteSQL SSL connection. The connect() method is defined as:

 
    def connect(	dbname = None, port = 0, nodes = None, nReplicas = 1,
            replType = ReplicationType.SQL_REPLICATION,
            maxConnectAttempts = 10, local = False,
            useConnectionPool=False, recover = False,
            txBufSize = 64*1024,
            connectTimeout=2000L, readTimeout=1200*1000L,
            sql_login=None, sql_password=None, ssl_params=None):
             

For SSL connections the ssl_params are required, while sql_login and sql_password are optional. For example, to create an SSL connection to an xSQL server the following connection parameters could be specified:

 
    >>>conn = exdb.connect('localhost', 5001, sql_login='login',
                    sql_password='password', ssl_params=ssl_params)
                     

Similar to the RemoteSQL client connection above, a DistributedSQL client connection could be created as follows:

 
    >>>conn = exdb.connect( nodes=('localhost:5010', 'localhost:5011'),
                    sql_login='login', sql_password='password',
                    ssl_params=ssl_params)
                     

An SSL enabled SQL server can be instantiated by specifying SqlServer constructor parameters ssl_params and auth_required. The SqlServer constructor is defined as follows:

 
    exdb.SqlServer(engine, port, bufsize, nThreads, listen_queue_size, 
            local_domain, ssl_params, auth_required, interrupt_timeout)
             

In order to use authentication with SqlServer, the application must create a table called Users and insert user names (login) and their respective passwords (password). For example:

 
    sql_statements = 
    [
        "create table Users (login string primary key, password string)",
        "insert into Users values ('user1', 'mypass')",
        "insert into Users values ('user2', 'hYfjdKK2')"
    ]
    server = exdb.SqlServer(engine, port,ssl_params=ssl_params, auth_required=True)
    for stmt in sql_statements:
        self.engine.execute(stmt)