def _check_instance_profile(self): self.server_profile = ServerProfile(self.connection, self.instance_profile, False) # if no instance info exists, try to auto-detect them if self.instance_profile is None: if self.server_profile.is_local: if autoDetectLocalInstance(self.connection): grt.log_info("Admin", "Auto-created instance profile for connection %s\n" % self.connection.name) # Retry self.server_profile = ServerProfile(self.connection, self.instance_profile, False) else: if autoDetectRemoteInstance(self.connection): grt.log_info("Admin", "Auto-created dummy instance profile for remote connection %s\n" % self.connection.name) # Retry self.server_profile = ServerProfile(self.connection, self.instance_profile, False)
def __init__(self, server_instance_settings): AppView.__init__(self, False, "admin", True) server_profile = ServerProfile(server_instance_settings, False) self.ctrl_be = wb_admin_control.WbAdminControl(server_profile, connect_sql=True) self.ctrl_be.init() version = self.ctrl_be.get_server_version() if type(version) is tuple: valid_versions = ((4, 0), (4, 1), (5, 0), (5, 1), (5, 2), (5, 4), (5, 5), (5, 6), (6, 0)) if version[:2] not in valid_versions: print version, "UNSUPPORTED" log_warning( _this_file, "%s: Server version %s is NOT supported\n" % (self.__class__.__name__, str(version))) else: log_info( _this_file, "%s: Server version %s is supported\n" % (self.__class__.__name__, str(version))) self.on_close(wb_admin_utils.weakcb(self, "handle_on_close")) # Create sections and add them to the admin page. self.configuration = wb_admin_main.WbAdminMainView( server_profile, self.ctrl_be, self.monitor) self.add(self.configuration, True, True)
def checkConnectionForRemoteAdmin(conn): the_instance = None for instance in grt.root.wb.rdbmsMgmt.storedInstances: if instance.connection == conn: the_instance = instance break profile = ServerProfile(conn, the_instance) return profile.is_local or profile.remote_admin_enabled
def testInstanceSettingByName(what, server_instance): global test_ssh_connection profile = ServerProfile(server_instance) if what == "connect_to_host": if test_ssh_connection: test_ssh_connection = None print "Connecting to %s" % profile.ssh_hostname try: test_ssh_connection = wb_admin_control.WbAdminControl( profile, connect_sql=False) test_ssh_connection.init() grt.send_info("connected.") except Exception, exc: import traceback traceback.print_exc() return "ERROR " + str(exc) except:
def testInstanceSettingByName(what, connection, server_instance): global test_ssh_connection log_debug("Test %s in %s\n" % (what, connection.name)) profile = ServerProfile(connection, server_instance) if what == "connect_to_host": if test_ssh_connection: test_ssh_connection = None log_info("Instance test: Connecting to %s\n" % profile.ssh_hostname) try: test_ssh_connection = wb_admin_control.WbAdminControl(profile, None, connect_sql=False, test_only=True) test_ssh_connection.init() grt.send_info("connected.") except Exception, exc: log_error("Exception: %s\n" % exc.message) import traceback log_debug2("Backtrace was: ", traceback.format_stack()) return "ERROR "+str(exc) except:
def testInstanceSettingByName(what, connection, server_instance): global test_ssh_connection log_debug(_this_file, "Test %s in %s\n" % (what, connection.name)) profile = ServerProfile(connection, server_instance) if what == "connect_to_host": if test_ssh_connection: test_ssh_connection = None log_info(_this_file, "Instance test: Connecting to %s\n" % profile.ssh_hostname) try: test_ssh_connection = wb_admin_control.WbAdminControl(profile, connect_sql=False) test_ssh_connection.init() grt.send_info("connected.") except Exception, exc: import traceback traceback.print_exc() return "ERROR "+str(exc) except:
def openRemoteFileSelector(connection, serverInstance): profile = ServerProfile(connection, serverInstance) return wba_ssh_ui.remote_file_selector(profile, PasswordHandler(profile))
def testInstanceSettingByName(what, connection, server_instance): global test_ssh_connection log_debug("Test %s in %s\n" % (what, connection.name)) profile = ServerProfile(connection, server_instance) if what == "connect_to_host": if test_ssh_connection: test_ssh_connection = None log_info("Instance test: Connecting to %s\n" % profile.ssh_hostname) try: test_ssh_connection = wb_admin_control.WbAdminControl( profile, None, connect_sql=False, test_only=True) test_ssh_connection.init() grt.send_info("connected.") except Exception as exc: log_error("Exception: %s\n" % str(exc)) import traceback log_debug2("Backtrace was: ", traceback.format_stack()) return "ERROR " + str(exc) except: return "ERROR" try: test_ssh_connection.acquire_admin_access() except Exception as exc: log_error("Exception: %s\n" % str(exc)) import traceback log_debug2("Backtrace was: " % traceback.format_stack()) return "ERROR " + str(exc) os_info = test_ssh_connection.detect_operating_system_version() if os_info: os_type, os_name, os_variant, os_version = os_info log_info("Instance test: detected remote OS: %s (%s), %s, %s\n" % (os_info)) # check if the admin access error was because of wrong OS set if os_type != profile.target_os: return "ERROR Wrong Remote OS configured for connection. Set to %s, but was detected as %s" % ( profile.target_os, os_type) else: log_warning( "Instance test: could not determine OS version information\n") return "ERROR Could not determine remote OS details" return "OK" elif what == "disconnect": if test_ssh_connection: test_ssh_connection = None return "OK" elif what == "check_privileges": return "ERROR" elif what in ("find_config_file", "check_config_path", "check_config_section"): config_file = profile.config_file_path print("Check if %s exists in remote host" % config_file) try: if not test_ssh_connection.ssh.fileExists(config_file): return "ERROR File %s doesn't exist" % config_file else: print("File was found in expected location") except IOError: return 'ERROR Could not verify the existence of the file %s' % config_file if what == "check_config_path": return "OK" section = profile.config_file_section cfg_file_content = "" print("Check if %s section exists in %s" % (section, config_file)) try: #local_file = test_ssh_connection.fetch_file(config_file) cfg_file_content = test_ssh_connection.server_helper.get_file_content( path=config_file) except Exception as exc: import traceback traceback.print_exc() return "ERROR " + str(exc) if ("[" + section + "]") in cfg_file_content: return "OK" return "ERROR Couldn't find section %s in the remote config file %s" % ( section, config_file) elif what in ("find_config_file/local", "check_config_path/local", "check_config_section/local"): config_file = profile.config_file_path config_file = wb_admin_control.WbAdminControl( profile, None, connect_sql=False).expand_path_variables(config_file) print("Check if %s can be accessed" % config_file) if os.path.exists(config_file): print("File was found at the expected location") else: return "ERROR File %s doesn't exist" % config_file if what == "check_config_path/local": return "OK" section = profile.config_file_section print("Check if section for instance %s exists in %s" % (section, config_file)) if check_if_config_file_has_section(open(config_file, "r"), section): print("[%s] section found in configuration file" % section) return "OK" return "ERROR Couldn't find section [%s] in the config file %s" % ( section, config_file) elif what == "find_error_files": return "ERROR" elif what == "check_admin_commands": path = profile.start_server_cmd cmd_start = None if path.startswith("/"): cmd_start = path.split()[0] if not test_ssh_connection.ssh.fileExists(cmd_start): return "ERROR %s is invalid" % path path = profile.stop_server_cmd if path.startswith("/"): cmd = path.split()[0] if cmd != cmd_start and not test_ssh_connection.ssh.fileExists( cmd): return "ERROR %s is invalid" % path return "OK" elif what == "check_admin_commands/local": path = profile.start_server_cmd cmd_start = None if path.startswith("/"): cmd_start = path.split()[0] if not os.path.exists(cmd_start): return "ERROR %s is invalid" % path path = profile.stop_server_cmd if path.startswith("/"): cmd = path.split()[0] if cmd != cmd_start and not os.path.exists(cmd): return "ERROR %s is invalid" % path return "OK" return "ERROR bad command"