def __stop_command(self): try: self.orig_master_host = getattr(self, "orig_master_host") self.orig_master_config = ConfigHelper(self.orig_master_host) except Exception as e: print("Failed to read configuration for original master: %s" % str(e)) return False # Original master try: orig_master_ip = getattr(self, "orig_master_ip", self.orig_master_host) orig_master_mysql_port = getattr(self, "orig_master_port", None) orig_master_ssh_ip = getattr(self, "orig_master_ssh_ip", orig_master_ip) orig_master_ssh_port = getattr(self, "orig_master_ssh_port", None) orig_master_ssh_user = getattr(self, "orig_master_ssh_user", None) orig_master_mysql_user = self.__unescape_from_shell(getattr(self, "orig_master_user")) orig_master_mysql_pass = self.__unescape_from_shell(getattr(self, "orig_master_password")) except AttributeError as e: print("Failed to read one or more required original master parameter(s): %s" % str(e)) return False # Setup MySQL connections mysql_orig_master = MySQLHelper(orig_master_ip, orig_master_mysql_port, orig_master_mysql_user, orig_master_mysql_pass) try: print("Connecting to mysql on the original master '%s'" % self.orig_master_host) if not mysql_orig_master.connect(): return False if self.orig_master_config.get_manage_vip(): vip_type = self.orig_master_config.get_vip_type() print("Removing the vip using the '%s' provider from the original master '%s'" % (vip_type, self.orig_master_host)) if not self.__remove_vip_from_host(vip_type, self.orig_master_host, orig_master_ssh_ip, orig_master_ssh_user, orig_master_ssh_port, self.FAILOVER_TYPE_ONLINE): return False if self.orig_master_config.get_super_read_only() and mysql_orig_master.super_read_only_supported(): print("Setting super_read_only to '1' on the original master '%s'" % self.orig_master_host) if not mysql_orig_master.set_super_read_only() or not mysql_orig_master.is_super_read_only(): return False else: print("Setting read_only to '1' on the original master '%s'" % self.orig_master_host) if not mysql_orig_master.set_read_only() or not mysql_orig_master.is_read_only(): return False if not self.__mysql_kill_threads(self.orig_master_host, mysql_orig_master): return False except Exception as e: print("Unexpected error: %s" % str(e)) return False finally: print("Disconnecting from mysql on the original master '%s'" % self.orig_master_host) mysql_orig_master.disconnect() return True
def __rollback_stop_command(self): try: self.orig_master_host = getattr(self, "orig_master_host") self.orig_master_config = ConfigHelper(self.orig_master_host) except Exception as e: print("Failed to read configuration for original master: %s" % str(e)) return False # Original master try: orig_master_ip = getattr(self, "orig_master_ip", self.orig_master_host) orig_master_mysql_port = getattr(self, "orig_master_port", None) orig_master_mysql_user = self.__unescape_from_shell(getattr(self, "orig_master_user")) orig_master_mysql_pass = self.__unescape_from_shell(getattr(self, "orig_master_password")) orig_master_ssh_ip = getattr(self, "orig_master_ssh_ip", orig_master_ip) orig_master_ssh_port = getattr(self, "orig_master_ssh_port", None) orig_master_ssh_user = getattr(self, "orig_master_ssh_user", None) orig_master_ssh_options = getattr(self, "ssh_options", None) except AttributeError as e: print("Failed to read one or more required original master parameter(s): %s" % str(e)) return False # Setup MySQL connections mysql_orig_master = MySQLHelper(orig_master_ip, orig_master_mysql_port, orig_master_mysql_user, orig_master_mysql_pass) print("Rolling back the failover changes on the original master '%s'" % self.orig_master_host) try: if not mysql_orig_master.connect(): print("Failed to connect to mysql on the original master '%s'" % self.orig_master_host) return False if not mysql_orig_master.unset_read_only() or mysql_orig_master.is_read_only(): print("Failed to reset read_only to '0' on the original master '%s'" % self.orig_master_host) return False print("Set read_only back to '0' on the original master '%s'" % self.orig_master_host) if self.orig_master_config.get_manage_vip(): vip_type = self.orig_master_config.get_vip_type() if not self.__add_vip_to_host(vip_type, self.orig_master_host, orig_master_ssh_ip, orig_master_ssh_user, orig_master_ssh_port, orig_master_ssh_options): print("Failed to add back the vip using the '%s' provider to the original master '%s'" % (vip_type, self.orig_master_host)) return False print("Added back the vip to the original master '%s'" % self.orig_master_host) except Exception as e: print("Unexpected error: %s" % str(e)) return False finally: mysql_orig_master.disconnect() return True
def __start_command(self): try: self.orig_master_host = getattr(self, "orig_master_host") self.orig_master_config = ConfigHelper(self.orig_master_host) except Exception as e: print("Failed to read configuration for original master: %s" % str(e)) return False try: self.new_master_host = getattr(self, "new_master_host") self.new_master_config = ConfigHelper(self.new_master_host) except Exception as e: print("Failed to read configuration for new master: %s" % str(e)) return False # New master try: new_master_ip = getattr(self, "new_master_ip", self.new_master_host) new_master_mysql_port = getattr(self, "new_master_port", None) new_master_mysql_user = self.__unescape_from_shell(getattr(self, "new_master_user")) new_master_mysql_pass = self.__unescape_from_shell(getattr(self, "new_master_password")) new_master_ssh_ip = getattr(self, "new_master_ssh_ip", new_master_ip) new_master_ssh_port = getattr(self, "new_master_ssh_port", None) new_master_ssh_options = getattr(self, "ssh_options", None) if self.failover_type == self.FAILOVER_TYPE_HARD: new_master_ssh_user = getattr(self, "ssh_user", None) else: new_master_ssh_user = getattr(self, "new_master_ssh_user", None) except AttributeError as e: print("Failed to read one or more required new master parameter(s): %s" % str(e)) return False # Setup MySQL connection mysql_new_master = MySQLHelper(new_master_ip, new_master_mysql_port, new_master_mysql_user, new_master_mysql_pass) try: print("Connecting to mysql on the new master '%s'" % self.new_master_host) if not mysql_new_master.connect(): return False print("Setting read_only to '0' on the new master '%s'" % self.new_master_host) if not mysql_new_master.unset_read_only() or mysql_new_master.is_read_only(): return False if self.new_master_config.get_manage_vip(): vip_type = self.new_master_config.get_vip_type() print("Adding the vip using the '%s' provider to the new master '%s'" % (vip_type, self.new_master_host)) if not self.__add_vip_to_host(vip_type, self.new_master_host, new_master_ssh_ip, new_master_ssh_user, new_master_ssh_port, new_master_ssh_options): return False except Exception as e: print("Unexpected error: %s" % str(e)) return False finally: print("Disconnecting from mysql on the new master '%s'" % self.new_master_host) mysql_new_master.disconnect() return True
def __stop_command(self): try: self.orig_master_host = getattr(self, "orig_master_host") self.orig_master_config = ConfigHelper(self.orig_master_host) except Exception as e: print("Failed to read configuration for original master: %s" % str(e)) return False # Original master try: orig_master_ip = getattr(self, "orig_master_ip", self.orig_master_host) orig_master_mysql_port = getattr(self, "orig_master_port", None) orig_master_ssh_ip = getattr(self, "orig_master_ssh_ip", orig_master_ip) orig_master_ssh_port = getattr(self, "orig_master_ssh_port", None) orig_master_ssh_user = getattr(self, "orig_master_ssh_user", None) orig_master_mysql_user = self.__unescape_from_shell( getattr(self, "orig_master_user")) orig_master_mysql_pass = self.__unescape_from_shell( getattr(self, "orig_master_password")) except AttributeError as e: print( "Failed to read one or more required original master parameter(s): %s" % str(e)) return False # Setup MySQL connections mysql_orig_master = MySQLHelper(orig_master_ip, orig_master_mysql_port, orig_master_mysql_user, orig_master_mysql_pass) try: print("Connecting to mysql on the original master '%s'" % self.orig_master_host) if not mysql_orig_master.connect(): return False if self.orig_master_config.get_manage_vip(): vip_type = self.orig_master_config.get_vip_type() print( "Removing the vip using the '%s' provider from the original master '%s'" % (vip_type, self.orig_master_host)) if not self.__remove_vip_from_host( vip_type, self.orig_master_host, orig_master_ssh_ip, orig_master_ssh_user, orig_master_ssh_port, self.FAILOVER_TYPE_ONLINE): return False if self.orig_master_config.get_super_read_only( ) and mysql_orig_master.super_read_only_supported(): print( "Setting super_read_only to '1' on the original master '%s'" % self.orig_master_host) if not mysql_orig_master.set_super_read_only( ) or not mysql_orig_master.is_super_read_only(): return False else: print("Setting read_only to '1' on the original master '%s'" % self.orig_master_host) if not mysql_orig_master.set_read_only( ) or not mysql_orig_master.is_read_only(): return False if not self.__mysql_kill_threads(self.orig_master_host, mysql_orig_master): return False except Exception as e: print("Unexpected error: %s" % str(e)) return False finally: print("Disconnecting from mysql on the original master '%s'" % self.orig_master_host) mysql_orig_master.disconnect() return True
def __rollback_stop_command(self): try: self.orig_master_host = getattr(self, "orig_master_host") self.orig_master_config = ConfigHelper(self.orig_master_host) except Exception as e: print("Failed to read configuration for original master: %s" % str(e)) return False # Original master try: orig_master_ip = getattr(self, "orig_master_ip", self.orig_master_host) orig_master_mysql_port = getattr(self, "orig_master_port", None) orig_master_mysql_user = self.__unescape_from_shell( getattr(self, "orig_master_user")) orig_master_mysql_pass = self.__unescape_from_shell( getattr(self, "orig_master_password")) orig_master_ssh_ip = getattr(self, "orig_master_ssh_ip", orig_master_ip) orig_master_ssh_port = getattr(self, "orig_master_ssh_port", None) orig_master_ssh_user = getattr(self, "orig_master_ssh_user", None) except AttributeError as e: print( "Failed to read one or more required original master parameter(s): %s" % str(e)) return False # Setup MySQL connections mysql_orig_master = MySQLHelper(orig_master_ip, orig_master_mysql_port, orig_master_mysql_user, orig_master_mysql_pass) print("Rolling back the failover changes on the original master '%s'" % self.orig_master_host) try: if not mysql_orig_master.connect(): print( "Failed to connect to mysql on the original master '%s'" % self.orig_master_host) return False if not mysql_orig_master.unset_read_only( ) or mysql_orig_master.is_read_only(): print( "Failed to reset read_only to '0' on the original master '%s'" % self.orig_master_host) return False print("Set read_only back to '0' on the original master '%s'" % self.orig_master_host) if self.orig_master_config.get_manage_vip(): vip_type = self.orig_master_config.get_vip_type() if not self.__add_vip_to_host( vip_type, self.orig_master_host, orig_master_ssh_ip, orig_master_ssh_user, orig_master_ssh_port): print( "Failed to add back the vip using the '%s' provider to the original master '%s'" % (vip_type, self.orig_master_host)) return False print("Added back the vip to the original master '%s'" % self.orig_master_host) except Exception as e: print("Unexpected error: %s" % str(e)) return False finally: mysql_orig_master.disconnect() return True
def __start_command(self): try: self.orig_master_host = getattr(self, "orig_master_host") self.orig_master_config = ConfigHelper(self.orig_master_host) except Exception as e: print("Failed to read configuration for original master: %s" % str(e)) return False try: self.new_master_host = getattr(self, "new_master_host") self.new_master_config = ConfigHelper(self.new_master_host) except Exception as e: print("Failed to read configuration for new master: %s" % str(e)) return False # New master try: new_master_ip = getattr(self, "new_master_ip", self.new_master_host) new_master_mysql_port = getattr(self, "new_master_port", None) new_master_mysql_user = self.__unescape_from_shell( getattr(self, "new_master_user")) new_master_mysql_pass = self.__unescape_from_shell( getattr(self, "new_master_password")) new_master_ssh_ip = getattr(self, "new_master_ssh_ip", new_master_ip) new_master_ssh_port = getattr(self, "new_master_ssh_port", None) if self.failover_type == self.FAILOVER_TYPE_HARD: new_master_ssh_user = getattr(self, "ssh_user", None) else: new_master_ssh_user = getattr(self, "new_master_ssh_user", None) except AttributeError as e: print( "Failed to read one or more required new master parameter(s): %s" % str(e)) return False # Setup MySQL connection mysql_new_master = MySQLHelper(new_master_ip, new_master_mysql_port, new_master_mysql_user, new_master_mysql_pass) try: print("Connecting to mysql on the new master '%s'" % self.new_master_host) if not mysql_new_master.connect(): return False print("Setting read_only to '0' on the new master '%s'" % self.new_master_host) if not mysql_new_master.unset_read_only( ) or mysql_new_master.is_read_only(): return False if self.new_master_config.get_manage_vip(): vip_type = self.new_master_config.get_vip_type() print( "Adding the vip using the '%s' provider to the new master '%s'" % (vip_type, self.new_master_host)) if not self.__add_vip_to_host( vip_type, self.new_master_host, new_master_ssh_ip, new_master_ssh_user, new_master_ssh_port): return False except Exception as e: print("Unexpected error: %s" % str(e)) return False finally: print("Disconnecting from mysql on the new master '%s'" % self.new_master_host) mysql_new_master.disconnect() return True