Skip to navigation

DB Cluster Utils Cluster API

The db_cluster class contains methods that are performed on the cluster as a whole.

Attritbutes

database_name - the name of the database to be administered.
master_ip - the IP address of the master server.
control_host - the IP address of the control host
slave_ip_list - a list of slave IP addresses
root_password - the password of the root MySQL user
db_user_pw - the password of the MySQL user 'db_user'
slave_user_pw - the password of the replication MySQL user

 

Methods

__init__ (self)

Load settings from config file and from the log.
Return a cluster object.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()


init_cluster(self)

Load settings from config file, ignoring setting in the status log.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.init_cluster()

 

init_master(self)

Initialize a server, get and save its log file and position, and grant replication privileges for the slaves.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster = cluster.init_master()


init_slave(self, host)

Initialize a server, get and save its log file and position, set it read only, and tell it which master to use.

Argument

  • host - IP address of a slave server expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
for host in cluster.slave_ip_list:
    cluster.init_slave(host)

 

wipe (self, db_name)

Delete a database from each server listed in the server pool.

Argument

  • db_name - the name of the database to be removed

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.stop_replication ()
cluster.wipe (cluster.database_name)

 

add_slave (self, host)

Add a slave to the cluster.
Get the master server's log file and position.
Grant replication privileges for the new slave on the master.
Initialize the slave.

Argument

  • host - IP address expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.add_slave(arg)

 

remove_slave (self, host)

Remove a slave from the cluster.
Remove the host's record from the status log file.
Revoke replicatio privileges for this host on the master server.
Stop the slave.

Argument

  • host - IP address of a slave expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.remove_slave (arg)

 

print_config (self)

Load the cluster configuration information and print it.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.print_config ()


demote_cluster_master (self)

Demote a master to a slave.
Reset all slaves.
Revoke replication privileges for all slaves.
Update role in status file.
Set read only.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.stop_replication ()
cluster.demote_cluster_master()


promote_cluster_slave (self, host)

Promote a slave to a master.
Stop replication across the whole cluster.
Clear read only on the new master.
Update status log file.
Update slave IP address list.
Set the slave as a master.
Tell all the other slaves to use the new master.

Argument

  • host - IP address of a slave expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.promote_cluster_slave (arg)
cluster.start_replication ()


start_replication(self)

Start replication on all slaves in the cluster.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.start_replication ()


stop_replication(self)

Stop replication on all slaves in the cluster.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster()
cluster.stop_replication ()


move_db (self, host)

Move the database to a new slave.
Dump the database from the master.
Use the scp command to transfer the database file to the destination host.
Import the database on the destination host.

Argument

  • host - destination IP address expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster ()
cluster.move_db (arg)


get_master_ip (self)

Get the master server's IP address from the status log.

Return the IP address of master.

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster ()
master_ip = cluster.get_master_ip ()


update_slave_ip_list (self)

Get an updated slave list from the status log.

Example:

import db_cluster_utils

slave_list = []
cluster = db_cluster_utils.db_cluster ()
slave_list = cluster.update_slave_ip_list()

 

update_bin_log_role (self, host, role)

Update the role field in a status log file.

Arguments

  • host - IP address of a host expressed as a string in format xxx.xxx.xxx.xxx
  • role - the role of the host (master or slave)

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster ()
cluster.update_bin_log_role (host, "master")

 

get_master_bin_log (self, host)

Get the log file and log position information for a host from the status log file.

Return the log file and its postition.

Argument

  • host - IP address expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster ()
binlog_file, binlog_position = cluster.get_master_bin_log (host)


save_master_bin_log (self, host, mysqlbin, binlog, role)

Save log file and log position information for a host.

Arguments

  • host - IP address expressed as a string in format xxx.xxx.xxx.xxx
  • mysqlbin - the MySQL binary log file for this host
  • binlog - the position in the MySQL binary log file for this host
  • role - the role of this host (master or slave)

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster ()
mysql_bin_file, bin_log_pos = server.get_master_status ()
cluster.save_master_bin_log (server.ip_addr, mysql_bin_file, bin_log_pos, "slave")


remove_bin_log (self, host)

Remove a host's record from the status log.

Argument

  • host - IP address expressed as a string in format xxx.xxx.xxx.xxx

Example:

import db_cluster_utils

cluster = db_cluster_utils.db_cluster ()
cluster.remove_bin_log(host)

Share this page:

comments powered by Disqus