pynuoadmin
Management Client Package Setup
The pynuoadmin
client package enables the client management of a NuoDB database without the need to install the full NuoDB product on a client machine.
To set up client management, follow pynuoadmin installation instructions located on the PyPI (Python Package Index) website.
Once installed, add the following lines to your Linux shell startup file, for example .bashrc
if using Bash:
nuocmd () {
python -m nuodb_cli "$@"
}
export -f nuocmd
Setting up Command Argument Completion
NuoDB recommends that you install command argument completion for NuoDB Command nuocmd
.
To install using the pip
package manager for python, run:
pip install pynuoadmin[completion]
Enable nuocmd
argument completion in your Linux Bash environment by running the following command.
Also, to enable this feature for every Bash session, then add the line to your .bashrc after the nuocmd
function definition mentioned above.
eval "$(register-python-argcomplete nuocmd)"
Example
The pynuoadmin
package includes the command-line tool described above, and also a Python client API that can be used programmatically.
nuocmd show domain
server version: 5.0.3-1-f85205f560, server license: Community
server time: 2023-10-10T19:13:56.411, client token: 29a14551580574cd8690f747b1a2a4080c87fa6f
Servers:
[admin-nuodb-cluster0-0] admin-nuodb-cluster0-0.nuodb.nuodb.svc.cluster.local:48005 [last_ack = 0.16] ACTIVE (LEADER, Leader=admin-nuodb-cluster0-0, log=0/24/24) Connected *
Databases:
demo [state = RUNNING]
[SM] sm-demo-nuodb-cluster0-demo-database-0/10.1.2.2:48006 [start_id = 0] [server_id = admin-nuodb-cluster0-0] [pid = 446] [node_id = 1] [last_ack = 3.72] MONITORED:RUNNING
[TE] te-demo-nuodb-cluster0-demo-database-59968544cd-65gtc/10.1.2.1:48006 [start_id = 1] [server_id = admin-nuodb-cluster0-0] [pid = 338] [node_id = ] [last_ack = 3.98] TRACKED:STARTING_UP
Using a Python distribution that has the pynuoadmin
package you can run the following script.
import nuodb_mgmt
# In this example two nuodb admin servers are used, 'server0' and 'server1'
# Get client object; the client key and server certificate are assumed to be configured according to the Unique Admin Key model
conn = nuodb_mgmt.AdminConnection(url_base='https://server0:8888', client_key='/etc/nuodb/keys/nuocmd.pem', verify='/etc/nuodb/keys/ca.cert')
# create an archive object for database 'db' on admin server 'server0'
archive = conn.create_archive(db_name='db', server_id='server0', archive_path='/var/opt/nuodb/archive/db')
# create a database object for 'db'
db = conn.create_database(db_name='db', dba_user='user', dba_password='secret')
# start an SM on 'server0' and a TE on 'server1'
sm = conn.start_process(db_name='db', engine_type='SM', server_id='server0', archive_id=archive.id)
te = conn.start_process(db_name='db', engine_type='TE', server_id='server1')