0
我正在编写一个基本上登录到远程服务器(Linux)并执行少量命令的程序。为此,我需要从命令行获取“服务器IP”,“用户名”和“密码”等输入。我正在使用模块。我的代码看起来是这样的:如何将argparser参数的输入传递给另一个函数的参数?
import sys
import argparse
import getpass
import re
from time import gmtime, strftime
import paramiko
try:
import interactive
except ImportError:
from . import interactive
def do_connect(esxi):
"""Connect to host in the esxi host"""
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='DEV Installer App')
parser.add_argument("--esxiIP", help="Mention the Esxi Host IP", required=True)
parser.add_argument("--userName", help="Enter the UserName of the Host", required=True)
parser.add_argument("--password", help="Enter the Password", required=True)
args = parser.parse_args()
我想在这里做的是,我有一个连接到远程服务器,我得到的main()
功能使用的输入功能。我需要将这些输入参数传递给do_connect
函数。我怎样才能做到这一点?
上'do_connect的'self'参数()'看起来不合适在这里;它不是一种方法,你根本不使用参数。 –