Hey guys,
I’m new at scripting/coding with python, I am trying to make a script that will automate adding a proxy, proxy whitelist and remove whitelists.
This is what I have so far, but whenever it runs I get an error of “Error: Argument 'http-proxy' is specified multiple times.”
import subprocess
import sys
add_whitelists = "ncli http-proxy add-to-whitelist target-type=IPV4_ADDRESS target="
whitelist_Ip = s"192.168.1.1", "200.200.1.1"]
login = "nutanix@192.168.1.50"
add_pxy = "ncli http-proxy add name=NPX5-proxy address=proxy.npx5.local port=8080 proxy-types=HTTPS"
list_proxy = "ncli http-proxy get-whitelist"
#ssh connection
ssh = subprocess.Popen(s"ssh", "-i .ssh/id_rsa", login],
stdin =subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
bufsize=0)
# Send ssh commands to stdin
ssh.stdin.write(add_pxy)
for ip in whitelist_Ip:
ssh.stdin.write(add_whitelists + ip)
ssh.stdin.close()
# Fetch output
for line in ssh.stdout:
print(line.strip())