def get_local_ip(): try: ip = "" if platform.system() == "Linux": (res,error, retcode)= cmd.docmd("/sbin/ifconfig | grep -E 'eth0|em2' -A3 | grep -v eth1 | grep 'inet addr' | awk '{print $2;}' | cut -d: -f2") ip = res[0] elif platform.system() == "Windows": (res,error, retcode) = cmd.docmd("ipconfig|grep 'IP Address'|awk -F: '{print \$2}'|sed \"s/ //g\"|grep -E '^172|^10|^192\.168'") ip = res[0] except Exception,data: print data
def execute(sshbin, login_info, cmdstr="", pattern="", timeout=120, debug=False, raw=True): """ log_info = {ip:ip, user:user, passwd:passwd, port:port} return: {"last_stdo":last_stdo, "stdo":stdo, "stde":stde, "retcode":retcode} """ try: sshbin = bin_path + "/../tools/ssh.exp" login_info["sshbin"] = sshbin login_info["cmd"] = cmdstr cmdstr = "%(sshbin)s %(ip)s %(user)s %(passwd)s %(port)s '%(cmd)s' " % login_info (stdo, stde, retcode) = cmd.docmd(cmdstr, timeout=timeout, debug=debug, raw=raw) last_stdo = [] for so in stdo: if not re.search(pattern, str.strip(so)): last_stdo.append(so) return { "last_stdo": last_stdo, "stdo": stdo, "stde": stde, "retcode": retcode } except Exception, data: common.print_traceback_detail()
def send(scpbin, login_info, src, dest, direction="push", pattern="", timeout=120, debug=False, raw=True): """ log_info = {ip:ip, user:user, passwd:passwd, port:port} return: {"last_stdo":last_stdo, "stdo":stdo, "stde":stde, "retcode":retcode} """ try: login_info["scpbin"] = scpbin login_info["src"] = src login_info["dest"] = dest login_info["direction"] = direction cmdstr = "%(scpbin)s %(ip)s %(user)s %(passwd)s %(port)s %(src)s %(dest)s %(direction)s" % login_info (stdo, stde, retcode) = cmd.docmd(cmdstr, timeout=timeout, debug=debug, raw=raw) dolog((stdo, stde, retcode)) last_stdo = [] for so in stdo: if not re.search(pattern, str.strip(so)): last_stdo.append(so) return {"last_stdo":last_stdo, "stdo":stdo, "stde":stde, "retcode":retcode} except Exception,data: dolog(data) common.print_traceback_detail()