def generate_cache(cacheFile, authCredFile, authKeyFile): import paramiko username = None password = None hostKey = None ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) if len(authCredFile): try: fd = open(authCredFile, 'r') except: errMsg("generate_cache: failed to open auth credentials file") return False for line in fd.readlines(): name, value = line.strip().split(':') if name == "username": username = value elif name == "password": password = value fd.close() if len(authKeyFile) and not os.path.exists(authKeyFile): errMsg("generate_cache: key file specified does not exist") return False elif len(authKeyFile): try: if config.auth_key_type == 'dsa': hostKey = paramiko.DSSKey(filename=authKeyFile, password=password) else: hostKey = paramiko.RSAKey(filename=authKeyFile, password=password) except Exception, e: msg = str(e) if msg.count("encrypt"): errMsg("generate_cache: key specified is encrypted " + "(use --authcred): %s" % msg) elif msg.count("RSA private"): errMsg("generate_cache: key specified is type DSA " + "(use --authkeydsa): %s" % msg) else: errMsg(msg) return False # if no auth credentials are specified default to root for username if len(username) == 0: username = "******"
def generate_cache(cacheFile, authCredFile, authKeyFile): import socket import libssh2 username = None password = None hostKey = None if len(authCredFile): try: fd = open(authCredFile, 'r') except: errMsg("generate_cache: failed to open auth credentials file") return False for line in fd.readlines(): name, value = line.strip().split(':') if name == "username": username = value elif name == "password": password = value fd.close() if len(authKeyFile) and not os.path.exists(authKeyFile): errMsg("generate_cache: key file specified does not exist") return False elif len(authKeyFile): try: if config.auth_key_type == 'dsa': #hostKey = paramiko.DSSKey(filename=authKeyFile, password=password) pass else: #hostKey = paramiko.RSAKey(filename=authKeyFile, password=password) pass except Exception, e: msg = str(e) if msg.count("encrypt"): errMsg("generate_cache: key specified is encrypted " + "(use --authcred): %s" % msg) elif msg.count("RSA private"): errMsg("generate_cache: key specified is type DSA " + "(use --authkeydsa): %s" % msg) else: errMsg(msg) return False
if len(username) == 0: username = "******" try: ssh.connect( config.ssh_hostname, timeout=config.ssh_timeout, port=config.ssh_port, username=username, password=password, pkey=hostKey, allow_agent=config.auth_auto_keylookup, look_for_keys=config.auth_auto_keylookup ) except Exception, e: errMsg("generate_cache: failed to connect to remote host" + " - reason: %s" % str(e)) return False # build the command to execute remotely cmd_list = [] output_marker_end = "%s-end-%s" % \ (config.output_marker[1], config.output_marker[0]) for plugin in config.active_plugins: if not len(cmd_list) == 0: cmd_list.append(" && ") cmd_list.append("echo '%s%s%s' && %s && echo '%s'" % (config.output_marker[0], plugin.shortname, config.output_marker[1], plugin.command, output_marker_end)) command = ''.join(cmd_list)
# if no auth credentials are specified default to root for username if len(username) == 0: username = "******" try: ssh.connect(config.ssh_hostname, timeout=config.ssh_timeout, port=config.ssh_port, username=username, password=password, pkey=hostKey, allow_agent=config.auth_auto_keylookup, look_for_keys=config.auth_auto_keylookup) except Exception, e: errMsg("generate_cache: failed to connect to remote host" + " - reason: %s" % str(e)) return False # build the command to execute remotely cmd_list = [] output_marker_end = "%s-end-%s" % \ (config.output_marker[1], config.output_marker[0]) for plugin in config.active_plugins: if not len(cmd_list) == 0: cmd_list.append(" && ") cmd_list.append( "echo '%s%s%s' && %s && echo '%s'" % (config.output_marker[0], plugin.shortname, config.output_marker[1], plugin.command, output_marker_end))