def find_repos(source_connection): """ Args: source_connection (RemoteConnection): The connection associated with the remote environment to run repository discovery Returns: Object of RepositoryDefinition class """ try: binary_paths = helper_lib.find_binary_path(source_connection) repositories = [] for binary_path in binary_paths.split(';'): if helper_lib.check_dir_present(source_connection, binary_path): install_path = helper_lib.find_install_path( source_connection, binary_path) shell_path = helper_lib.find_shell_path( source_connection, binary_path) version = helper_lib.find_version(source_connection, install_path) pretty_name = "Couchbase ({})".format(version) repository_definition = RepositoryDefinition( cb_install_path=install_path, cb_shell_path=shell_path, version=version, pretty_name=pretty_name) repositories.append(repository_definition) return repositories except RepositoryDiscoveryError as err: err.to_user_error(), None, sys.exc_info()[2] except Exception as err: logger.debug("find_repos: Caught unexpected exception!" + err.message) raise
def find_repos(source_connection): logger = setupLogger._setup_logger(__name__) env = {"DLPX_TOOLKIT_NAME": "Oracle on Windows"} delphixToolkitPath = executeScript.execute_powershell( source_connection, 'writeLibrary.ps1', env).strip('"') logger.debug("Delphix Toolkit path: {}".format(delphixToolkitPath)) env = { "DLPX_TOOLKIT_NAME": "Oracle on Windows", "DLPX_TOOLKIT_WORKFLOW": "repository_discovery", "DLPX_TOOLKIT_PATH": delphixToolkitPath } repoDiscovery = executeScript.execute_powershell(source_connection, 'repoDiscovery.ps1', env) logger.debug("Repository discovered: {}".format(repoDiscovery)) parsedRepositories = json.loads(repoDiscovery) logger.debug("parsedRepositories: {}".format(parsedRepositories)) return [ RepositoryDefinition( toolkit_name=installedRepository["toolkitName"], delphix_tookit_path=installedRepository["delphixToolkitPath"], pretty_name=installedRepository["prettyName"], ora_base=installedRepository["oraBase"], ora_edition=installedRepository["oraEdition"], ora_home=installedRepository["oraHome"]) for installedRepository in parsedRepositories ]
def find_mysql_binaries(connection): logger.debug("operations.find_mysql_binaries()") baseName = "" version = "" dirName = "" prettyName = "" try: bashresult = runbash(connection, CommandFactory.find_binary_path(), None) repoList = bashresult.stdout.strip() stderr = bashresult.stderr.strip() exitcode = bashresult.exit_code logger.debug("find_mysql_binaries>_repoList > \n " + repoList) repositories = [] if exitcode != 0: logger.debug("find_mysql_binaries > exit code > " + str(exitcode)) raise RepositoryDiscoveryError(stderr) elif (repoList == "" or repoList is None): logger.debug("find_mysql_binaries > No MySQL repositories found") else: for repoPath in repoList.splitlines(): logger.debug("Parsing repository at " + repoPath) if not utils.validate_repository(repoPath): logger.debug("Invalid repository path. Skipping") continue baseName = os.path.basename(repoPath) dirName = os.path.dirname(repoPath) bashresult = runbash(connection, CommandFactory.get_version(repoPath), None) versionStr = bashresult.stdout.strip() versionArr = versionStr.split(" ") version = versionArr[3] if (version != "" and baseName == "mysqld"): prettyName = versionStr[versionStr.index("(MySQL" ):len(versionStr)] prettyName = prettyName + " {}".format(version) repository = RepositoryDefinition(name=prettyName, install_path=dirName, version=version) repositories.append(repository) except RepositoryDiscoveryError as err: raise RepositoryDiscoveryError( err.message).to_user_error(), None, sys.exc_info()[2] except Exception as err: raise return repositories
def repository_discovery(source_connection): common.add_debug_heading_block("Start Repository Discovery") helpers._record_hook("repository_discovery", source_connection) env = { "DELPHIX_DIR": source_connection.environment.host.binary_path, "DLPX_PLUGIN_WORKFLOW": 'repoDiscovery', "DLPX_TOOLKIT_WORKFLOW": 'repoDiscovery' } logger.debug("env: {}".format(env)) repositories = [] script_content = pkgutil.get_data('resources', 'discover_repos.sh') #logger.debug("discover_repos_repository_script: {}".format(script_content)) res = libs.run_bash(source_connection, script_content, env) logger.debug("res = {}".format(res)) logger.debug("res.stdout = {}".format(res.stdout)) repodiscovery = json.loads(res.stdout) logger.debug(repodiscovery) for item in repodiscovery: logger.debug("item:{}".format(item)) repository = RepositoryDefinition( version=item['version'], mongo_install_path=item['mongo_install_path'], mongo_shell_path=item['mongo_shell_path'], pretty_name=item['pretty_name']) repositories.append(repository) # # Write library file for future use # env = { # "DELPHIX_DIR": source_connection.environment.host.binary_path, # "DLPX_PLUGIN_WORKFLOW": 'sourceConfigDiscovery', # "MONGO_LIBRARY_SOURCE": pkgutil.get_data('resources', 'library.sh') # } # script_content = pkgutil.get_data('resources', 'write_library.sh') # res = libs.run_bash(source_connection, script_content, env) # data = json.loads(res.stdout) # logger.debug(data) common.add_debug_heading_block("End Repository Discovery") return repositories
def repository_discovery(source_connection): # This is an object generated from the repositoryDefinition schema. # In order to use it locally you must run the 'build -g' command provided # by the SDK tools from the plugin's root directory. repositories = [] binary_path = source_connection.environment.host.binary_path library_script = pkgutil.get_data('resources', 'library.sh') environment_vars = { "DLPX_LIBRARY_SOURCE": library_script, "DLPX_BIN": binary_path } find_mysql_binary = pkgutil.get_data('resources', 'repoDiscovery.sh') result = libs.run_bash(source_connection, find_mysql_binary, environment_vars, check=True) output = result.stdout.strip() error = result.stderr.strip() exit_code = result.exit_code if exit_code != 0: logger.debug("Error is : " + error) raise RepositoryDiscoveryError("Exception while discovering:" + error) else: logger.debug("Output: " + output) #process repository json repos_js = json.loads(output) # print the keys and values for repo_js in repos_js: #logger.debug("Adding repository:"+repo_js+" to list") path = repo_js['installPath'] version = repo_js['version'] prettyName = repo_js['prettyName'].split("/bin")[1] repository = RepositoryDefinition(name=prettyName, install_path=path, version=version) repositories.append(repository) logger.debug("output:" + output) return repositories