def operation_unlock(mysql_conn, dg_id, process_type): logger.info( "Unlock the %s process status in db_servers_oracle_dg for dataguard group: %s" % (process_type, dg_id)) # update process status to 1 col_name = "" if process_type == "SWITCHOVER": col_name = "on_switchover" elif process_type == "FAILOVER": col_name = "on_failover" elif process_type == "MRP_START": col_name = "on_startmrp" elif process_type == "MRP_STOP": col_name = "on_stopmrp" else: col_name = "" str = 'update db_servers_oracle_dg set on_process = 0, %s = 0 where id= %s ' % ( col_name, dg_id) op_status = mysql.ExecuteSQL(mysql_conn, str) logger.info(str) # 清理操作日志 str = 'delete from db_oracle_dg_process ' op_status = mysql.ExecuteSQL(mysql_conn, str) if op_status == 1: logger.info( "Unlock process status for dataguard group: %s successfully." % (dg_id)) else: logger.error("Unlock process status for dataguard group: %s failed." % (dg_id))
def update_mrp_status(mysql_conn, sta_id): logger.info( "Update MRP status in oracle_dg_s_status for server %s in progress..." % (sta_id)) # get current switch flag str = 'select mrp_status from oracle_dg_s_status where server_id= %s' % ( sta_id) mrp_status = mysql.GetSingleValue(mysql_conn, str) logger.info("debug the mrp_status: %s" % (mrp_status)) if mrp_status == '0': logger.info("The current MRP status is inactive.") str = """update oracle_dg_s_status s set s.mrp_status = 1 where s.id in (select * from (select max(t.id) from oracle_dg_s_status t where t.server_id = %s) m) """ % ( sta_id) is_succ = mysql.ExecuteSQL(mysql_conn, str) if is_succ == 1: logger.info( "Update MRP status to active in oracle_dg_s_status for server %s successfully." % (sta_id)) else: logger.info( "Update MRP status to active in oracle_dg_s_status for server %s failed." % (sta_id))
def db_op_unlock(mysql_conn, db_type, group_id, process_type): tab_name = "" if db_type == "sqlserver": tab_name = "db_cfg_sqlserver_mirror" elif db_type == "mysql": tab_name = "db_cfg_mysql_dr" logger.info("Unlock the %s process status in %s for group: %s" % (process_type, tab_name, group_id)) # update process status to 1 col_name = "" if process_type == "SWITCHOVER": col_name = "on_switchover" elif process_type == "FAILOVER": col_name = "on_failover" else: col_name = "" str = 'update %s set on_process = 0, %s = 0 where id= %s ' % ( tab_name, col_name, group_id) op_status = mysql.ExecuteSQL(mysql_conn, str) logger.info(str) if op_status == 1: logger.info("Unlock process status for group: %s successfully." % (group_id)) else: logger.error("Unlock process status for group: %s failed." % (group_id))
def init_db_op_instance(mysql_conn, db_type, group_id, op_type): logger.info("Initialize %s opration instance for group %s." % (db_type, group_id)) str = """insert into db_opration(db_type, group_id, op_type) values('%s', '%s', '%s') """ % ( db_type, group_id, op_type) is_succ = mysql.ExecuteSQL(mysql_conn, str)
def update_switch_flag(mysql_conn, group_id): logger.info( "Update switch flag in db_cfg_oracle_dg for group %s in progress..." % (group_id)) # get current switch flag str = 'select is_switch from db_cfg_oracle_dg where id= %s' % (group_id) is_switch = mysql.GetSingleValue(mysql_conn, str) logger.info("The current switch flag is: %s" % (is_switch)) if is_switch == 0: str = """update db_cfg_oracle_dg set is_switch = 1 where id = %s""" % ( group_id) else: str = """update db_cfg_oracle_dg set is_switch = 0 where id = %s""" % ( group_id) is_succ = mysql.ExecuteSQL(mysql_conn, str) if is_succ == 1: logger.info( "Update switch flag in db_cfg_oracle_dg for group %s successfully." % (group_id)) else: logger.info( "Update switch flag in db_cfg_oracle_dg for group %s failed." % (group_id))
def update_switch_flag(mysql_conn, group_id): logger.info( "Update switch flag in db_cfg_mysql_dr for group %s in progress..." % (group_id)) # get current switch flag str = 'select is_switch from db_cfg_mysql_dr where id= %s' % (group_id) is_switch = mysql.GetSingleValue(mysql_conn, str) logger.info("The current switch flag is: %s" % (is_switch)) if is_switch == 0: str = """update db_cfg_mysql_dr set is_switch = 1 where id = %s""" % ( group_id) else: str = """update db_cfg_mysql_dr set is_switch = 0 where id = %s""" % ( group_id) is_succ = mysql.ExecuteSQL(mysql_conn, str) if is_succ == 1: common.log_db_op_process(mysql_conn, db_type, group_id, 'FAILOVER', '容灾组更新状态成功', 100, 2) logger.info( "Update switch flag in db_cfg_mysql_dr for group %s successfully." % (group_id)) else: logger.info( "Update switch flag in db_cfg_mysql_dr for group %s failed." % (group_id))
def finish_flashback(mysql_conn, server_id): logger.info("Finish the flashback process infomation for server: %s" % (server_id)) # update flashback process str = """update oracle_fb_process set on_process=0, blocked=0 where server_id=%s """ % ( server_id) op_status = mysql.ExecuteSQL(mysql_conn, str)
def flashback_table(mysql_conn, server_id, conn, conn_str, restore_str, tab_name): result = -1 logger.info("Check the target database role. server_id is %s" % (server_id)) # get database role str = 'select database_role from v$database' role = oracle.GetSingleValue(conn, str) logger.info("The current database role is: " + role) # get instance status str = 'select status from v$instance' ins_status = oracle.GetSingleValue(conn, str) logger.info("The current instance status is: " + ins_status) if role == "PRIMARY" and ins_status == "OPEN": sqlplus = Popen(["sqlplus", "-S", conn_str, "as", "sysdba"], stdout=PIPE, stdin=PIPE) sqlplus.stdin.write( bytes("alter table " + tab_name + " enable row movement;" + os.linesep)) sqlplus.stdin.write(bytes(restore_str + os.linesep)) out, err = sqlplus.communicate() logger.debug(out) #logger.error(err) if err is None: logger.info("Flashback table successfully.") str = """update oracle_fb_process set result='1', reason='' where server_id=%s """ % ( server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) result = 0 else: logger.info("Flashback failed.") str = """update oracle_fb_process set result='0', reason='%s' where server_id=%s """ % ( err, server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) else: msg = "The current database role is not PRIMARY, not allow to flashback table." logger.info(msg) str = """update oracle_fb_process set result='0', reason='%s' where server_id=%s """ % ( msg, server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) return result
def update_op_result(mysql_conn, group_id, op_type, result): logger.info("update switch result for group %s." % (group_id)) # get max inst id str = """select max(id) from oracle_dg_opration where group_id= %s and op_type = '%s' """ % ( group_id, op_type) max_id = mysql.GetSingleValue(mysql_conn, str) str = """update oracle_dg_opration set result = '%s' where id = %s and op_type = '%s' """ % ( result, max_id, op_type) is_succ = mysql.ExecuteSQL(mysql_conn, str)
def update_db_op_reason(mysql_conn, db_type, group_id, op_type, reason): logger.info("update opration reason for group %s." % (group_id)) # get max inst id str = """select max(id) from db_opration where group_id= %s and op_type = '%s' """ % ( group_id, op_type) max_id = mysql.GetSingleValue(mysql_conn, str) str = """update db_opration set reason = '%s' where id = %s and op_type = '%s' """ % ( reason, max_id, op_type) is_succ = mysql.ExecuteSQL(mysql_conn, str)
def rebuild_replication(mysql_conn, db_type, group_id, p_conn, pri_id, s_conn, sta_id, s_host, s_port, s_username, s_password): result=-1 logger.info("Rebuild replication in progress...") # unlock tables logger.debug("Unlock tables for database: %s first" %(pri_id)) unlock_tables(p_conn, pri_id) # get master status master_info=mysql.GetSingleRow(s_conn, 'show master status;') if master_info: master_binlog_file=master_info[0] master_binlog_pos=master_info[1] str='''stop slave; ''' res=mysql.ExecuteSQL(p_conn, str) logger.debug("Stop slave") str='''change master to master_host='%s',master_port=%s,master_user='******',master_password='******',master_log_file='%s',master_log_pos=%s; '''%(s_host, s_port, s_username, s_password, master_binlog_file, master_binlog_pos) logger.debug("Change master command: %s" %(str)) res=mysql.ExecuteSQL(p_conn, str) str='''start slave; ''' res=mysql.ExecuteSQL(p_conn, str) logger.debug("Start slave") slave_info=mysql.GetSingleRow(p_conn, 'show slave status;') if slave_info: logger.info("Rebuild replication successfully !") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '重建复制关系成功', 0, 2) result=0 else: common.update_db_op_reason(mysql_conn, db_type, group_id, 'SWITCHOVER', '重建复制关系失败') common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '重建复制关系失败', 0, 2) logger.error("Rebuild replication failed !") result=-1 return result
def add_alert(server_id, tags, db_host, db_port, create_time, db_type, alert_item, alert_value, level, message, send_mail, send_mail_to_list, send_sms, send_sms_to_list): try: mysql_conn = mysql.ConnectMysql() if db_type == 'os': count_str = "select id from alerts where host='%s' and alert_item='%s';" % ( db_host, alert_item) alert_count = mysql.GetSingleValue(mysql_conn, count_str) if int(alert_count) > 0: sql = "insert into alerts_his select *,DATE_FORMAT(sysdate(),'%%Y%%m%%d%%H%%i%%s') from alerts where host='%s' and alert_item='%s';" % ( db_host, alert_item) try: mysql.ExecuteSQL(mysql_conn, sql) except Exception, e: print "Move alert to history: " + str(e) sql = "delete from alerts where host='%s' and alert_item='%s' ;" % ( db_host, alert_item) mysql.ExecuteSQL(mysql_conn, sql) else:
def db_op_lock(mysql_conn, db_type, group_id, process_type): tab_name = "" if db_type == "sqlserver": tab_name = "db_cfg_sqlserver_mirror" elif db_type == "mysql": tab_name = "db_cfg_mysql_dr" logger.info("Lock the %s process status in %s for group: %s" % (process_type, tab_name, group_id)) # update process status to 1 col_name = "" if process_type == "SWITCHOVER": col_name = "on_switchover" elif process_type == "FAILOVER": col_name = "on_failover" else: col_name = "" str = 'update %s set on_process = 1, %s = 1 where id= %s ' % ( tab_name, col_name, group_id) op_status = mysql.ExecuteSQL(mysql_conn, str) logger.info(str) if op_status == 1: logger.info("Lock the process status for group: %s successfully." % (group_id)) else: logger.error("Lock the process status for group: %s failed." % (group_id)) # 清理操作日志 str = "insert into db_op_process_his SELECT *,DATE_FORMAT(sysdate(),'%%Y%%m%%d%%H%%i%%s') from db_op_process where db_type = '%s' and group_id = %s; " % ( db_type, group_id) op_status = mysql.ExecuteSQL(mysql_conn, str) str = "delete from db_op_process where db_type = '%s' and group_id = %s; " % ( db_type, group_id) op_status = mysql.ExecuteSQL(mysql_conn, str)
def pre_flashback(mysql_conn, server_id, fb_type, fb_object): logger.info("Check the flashback process status for server: %s" % (server_id)) # get flashback process str = """select count(1) from oracle_fb_process where server_id=%s """ % ( server_id) fb_record = mysql.GetSingleValue(mysql_conn, str) if fb_record == 0: logger.info("Generate a flashback process for server: %s" % (server_id)) str = """insert into oracle_fb_process(server_id, fb_type, fb_object, on_process) values('%s', '%s', '%s', 1) """ % ( server_id, fb_type, fb_object) op_status = mysql.ExecuteSQL(mysql_conn, str) return 0 else: str = """select on_process from oracle_fb_process where server_id=%s """ % ( server_id) fb_process = mysql.GetSingleValue(mysql_conn, str) if fb_process == 1: logger.error("Blocked, another flashback process is running.") str = """update oracle_fb_process set blocked = 1 where server_id=%s """ % ( server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) sys.exit(2) else: logger.info( "Update the flashback process infomation for server: %s" % (server_id)) str = """update oracle_fb_process set fb_type = '%s', fb_object='%s', on_process=1, result='-1', reason='', blocked=0, create_time=CURRENT_TIMESTAMP where server_id=%s """ % ( fb_type, fb_object, server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) logger.info( "The flashback process is already prepared for server: %s" % (server_id)) return 0
def operation_unlock(mysql_conn, dg_id, process_type): logger.info( "Unlock the %s process status in db_cfg_oracle_dg for dataguard group: %s" % (process_type, dg_id)) # update process status to 1 col_name = "" if process_type == "SWITCHOVER": col_name = "on_switchover" elif process_type == "FAILOVER": col_name = "on_failover" elif process_type == "MRP_START": col_name = "on_startmrp" elif process_type == "MRP_STOP": col_name = "on_stopmrp" elif process_type == "SNAPSHOT_START": col_name = "on_startsnapshot" elif process_type == "SNAPSHOT_STOP": col_name = "on_stopsnapshot" else: col_name = "" str = 'update db_cfg_oracle_dg set on_process = 0, %s = 0 where id= %s ' % ( col_name, dg_id) op_status = mysql.ExecuteSQL(mysql_conn, str) logger.info(str) if op_status == 1: logger.info( "Unlock process status for dataguard group: %s successfully." % (dg_id)) else: logger.error("Unlock process status for dataguard group: %s failed." % (dg_id)) # 保存操作日志到历史表 str = 'insert into oracle_dg_process_his select *, sysdate() from oracle_dg_process t ' op_status = mysql.ExecuteSQL(mysql_conn, str)
def unlock_tables(p_conn, pri_id): result=-1 logger.info("Unlock tables for database: %s" %(pri_id)) str='''unlock tables; ''' res=mysql.ExecuteSQL(p_conn, str) if res == 1: logger.info("Unlock tables successfully !") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '解锁数据库成功', 0, 2) else: logger.error("Unlock tables failed !") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '解锁数据库失败', 0, 2) return result
def lock_tables(p_conn, pri_id): result=-1 logger.info("Flush tables with read lock for database: %s" %(pri_id)) str='''flush tables with read lock; ''' res=mysql.ExecuteSQL(p_conn, str) if res == 1: logger.info("Flush tables with read lock successfully !") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '锁定数据库成功', 0, 2) else: logger.error("Flush tables with read lock failed !") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '锁定数据库失败', 0, 2) return result
def log_dg_op_process(mysql_conn, dg_id, process_type, process_desc, rate, block_time=0): #logger.info("Log the operate process in oracle_dg_process for dataguard group: %s" %(dg_id)) # get current switch flag str = "insert into oracle_dg_process(group_id, process_type, process_desc, rate) values (%s, '%s', '%s', %s) " % ( dg_id, process_type, process_desc, rate) log_status = mysql.ExecuteSQL(mysql_conn, str) #if log_status == 1: # logger.info("Log the operate process for dataguard group: %s; completed %s." %(dg_id, rate)) #else: # logger.error("Log the operate process for dataguard group: %s failed." %(dg_id)) # time.sleep(block_time)
def log_db_op_process(mysql_conn, db_type, group_id, process_type, process_desc, rate, block_time=0): #logger.info("Log the %s operate process for group: %s" %(db_type, group_id)) # generate process log str = "insert into db_op_process(db_type, group_id, process_type, process_desc, rate) values ('%s', %s, '%s', '%s', %s) " % ( db_type, group_id, process_type, process_desc, rate) log_status = mysql.ExecuteSQL(mysql_conn, str) if log_status == 1: #logger.info("Log the %s operate process for group: %s; completed %s." %(db_type, group_id, rate)) logger.info("Log the %s operate process for group: %s." % (db_type, group_id)) else: logger.error("Log the %s operate process for group: %s failed." % (db_type, group_id)) time.sleep(block_time)
def switch2master(mysql_conn, db_type, group_id, p_conn, s_conn, sta_id): result=-1 logger.info("Switchover database to master in progress...") # get database role role=mysql.IsSlave(s_conn) common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '获取数据库角色成功', 0, 2) logger.info("The current database role is: %s (0:MASTER; 1:SLAVE)" %(role)) # get database version if role==1: common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '验证从库数据库角色成功', 0, 2) # get master status m_binlog_file="" m_binlog_pos=-1 master_info = mysql.GetSingleRow(p_conn, 'show master status;') if master_info: m_binlog_file=master_info[0] m_binlog_pos=master_info[1] logger.debug("Master: master_binlog_file: %s" %(m_binlog_file)) logger.debug("Master: master_binlog_pos: %s" %(m_binlog_pos)) # check slave status slave_info=mysql.GetSingleRow(s_conn, 'show slave status;') if slave_info: current_binlog_file=slave_info[9] current_binlog_pos=slave_info[21] master_binlog_file=slave_info[5] master_binlog_pos=slave_info[6] logger.debug("Slave: current_binlog_file: %s" %(current_binlog_file)) logger.debug("Slave: current_binlog_pos: %s" %(current_binlog_pos)) logger.debug("Slave: master_binlog_file: %s" %(master_binlog_file)) logger.debug("Slave: master_binlog_pos: %s" %(master_binlog_pos)) if (current_binlog_file == master_binlog_file and m_binlog_file==master_binlog_file and current_binlog_pos==master_binlog_pos and master_binlog_pos==m_binlog_pos): # can switch now logger.info("Now we are going to switch database %s to master." %(sta_id)) common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '正在将从库切换成主库...', 0, 0) str='''stop slave io_thread; ''' res=mysql.ExecuteSQL(s_conn, str) logger.debug("Stop slave io_thread.") str='''stop slave; ''' res=mysql.ExecuteSQL(s_conn, str) logger.debug("Stop slave.") str='''reset slave all; ''' res=mysql.ExecuteSQL(s_conn, str) logger.debug("Reset slave all.") logger.info("Switchover slave to master successfully.") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '从库已经成功切换成主库', 0, 2) result=0 else: logger.error("Check binlog position failed.") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '验证数据库binlog复制位置失败', 0, 2) result=-1 else: logger.info("Check slave status failed.") common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '从库切换主库失败', 0, 2) result=-1 else: common.update_db_op_reason(mysql_conn, db_type, group_id, 'SWITCHOVER', '验证数据库角色失败,当前数据库不是从库,不能切换到主库') common.log_db_op_process(mysql_conn, db_type, group_id, 'SWITCHOVER', '验证数据库角色失败,当前数据库不是从库,不能切换到主库', 0, 2) logger.error("You can not switchover a master database to master!") result=-1 return result
def flashback_db(mysql_conn, server_id, conn, conn_str, restore_str): result = -1 logger.info("Check the target database role. server_id is %s" % (server_id)) # get database role str = 'select database_role from v$database' role = oracle.GetSingleValue(conn, str) logger.info("The current database role is: " + role) # get mrp process status str = """select count(1) from gv$session where program like '%(MRP0)' """ mrp_process = oracle.GetSingleValue(conn, str) if role == "PHYSICAL STANDBY": if (mrp_process > 0): logger.info( "The mrp process is already active, should to stop it first. ") sqlplus = Popen(["sqlplus", "-S", conn_str, "as", "sysdba"], stdout=PIPE, stdin=PIPE) sqlplus.stdin.write( bytes( "alter database recover managed standby database cancel;" + os.linesep)) out, err = sqlplus.communicate() logger.debug(out) if 'ORA-' in out: pass else: str = """update oracle_dg_s_status set mrp_status='1' where server_id=%s """ % ( server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) sqlplus = Popen(["sqlplus", "-S", conn_str, "as", "sysdba"], stdout=PIPE, stdin=PIPE) sqlplus.stdin.write(bytes(restore_str + os.linesep)) out, err = sqlplus.communicate() logger.debug(out) if 'ORA-' in out: rea_str = out[out.index("ORA-"):] logger.info("Flashback failed.") str = """update oracle_fb_process set result='0', reason='%s' where server_id=%s """ % ( rea_str, server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) else: # 开启数据库到OPEN状态 sqlplus = Popen(["sqlplus", "-S", conn_str, "as", "sysdba"], stdout=PIPE, stdin=PIPE) sqlplus.stdin.write(bytes("alter database open;" + os.linesep)) out, err = sqlplus.communicate() logger.info("Flashback successfully.") str = """update oracle_fb_process set result='1', reason='' where server_id=%s """ % ( server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) result = 0 else: sqlplus = Popen(["sqlplus", "-S", conn_str, "as", "sysdba"], stdout=PIPE, stdin=PIPE) logger.info(restore_str) sqlplus.stdin.write(bytes(restore_str + os.linesep)) out, err = sqlplus.communicate() logger.debug(out) #logger.error(err) if 'ORA-' in out: rea_str = out[out.index("ORA-"):] logger.info("Flashback failed.") str = """update oracle_fb_process set result='0', reason='%s' where server_id=%s """ % ( rea_str, server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) else: # 开启数据库到OPEN状态 sqlplus = Popen(["sqlplus", "-S", conn_str, "as", "sysdba"], stdout=PIPE, stdin=PIPE) sqlplus.stdin.write(bytes("alter database open;" + os.linesep)) out, err = sqlplus.communicate() logger.info("Flashback successfully.") str = """update oracle_fb_process set result='1', reason='' where server_id=%s """ % ( server_id) op_status = mysql.ExecuteSQL(mysql_conn, str) result = 0 else: logger.info( "The current database role is not PHYSICAL STANDBY, not allow to flashback databaes." ) return result
except Exception, e: print "Move alert to history: " + str(e) sql = "delete from alerts where host='%s' and alert_item='%s' ;" % ( db_host, alert_item) mysql.ExecuteSQL(mysql_conn, sql) else: count_str = "select count(1) from alerts where server_id=%s and db_type='%s' and alert_item='%s';" % ( server_id, db_type, alert_item) alert_count = mysql.GetSingleValue(mysql_conn, count_str) if int(alert_count) > 0: sql = "insert into alerts_his select *,DATE_FORMAT(sysdate(),'%%Y%%m%%d%%H%%i%%s') from alerts where server_id=%s and db_type='%s' and alert_item='%s';" % ( server_id, db_type, alert_item) try: mysql.ExecuteSQL(mysql_conn, sql) except Exception, e: print "Move alert to history: " + str(e) sql = "delete from alerts where server_id=%s and db_type='%s' and alert_item='%s' ;" % ( server_id, db_type, alert_item) mysql.ExecuteSQL(mysql_conn, sql) sql = "insert into alerts(server_id,tags,host,port,create_time,db_type,alert_item,alert_value,level,message,send_mail,send_mail_to_list,send_sms,send_sms_to_list) values(%s,'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % ( server_id, tags, db_host, db_port, create_time, db_type, alert_item, alert_value, level, message, send_mail, send_mail_to_list, send_sms, send_sms_to_list) mysql.ExecuteSQL(mysql_conn, sql) if send_mail == 1: sql = "delete from alerts_temp where server_id='%s' and ip='%s' and db_type='%s' and alert_item='%s' and alert_type='mail';" % (
def init_op_instance(mysql_conn, group_id, op_type): logger.info("Initialize switch instance for group %s." % (group_id)) str = """insert into oracle_dg_opration(group_id, op_type) values('%s', '%s') """ % ( group_id, op_type) is_succ = mysql.ExecuteSQL(mysql_conn, str)