creating teaming from user input
<p>I'm trying to create a centos 7 a networking teaming (bonding) using a user input in a python script. C</p>

<pre><code>import socket

# IP Address
IPADDR = socket.gethostbyname(socket.gethostname())
print IPADDR
# Netmask
NETMASK = raw_input("Enter Netmask address: ")
PREFIX = sum([bin(int(x)).count("1") for x in NETMASK.split(".")])
print NETMASK
# Gateway
GATEWAY = raw_input("Enter Gateway address: ")
print GATEWAY
# Run command and substitution
os.system("nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "activebackup"}}'")
os.system("nmcli con mod team0 ipv4.addresses IPDDR/PREFIX")
os.system("nmcli con mod team0 ipv4.gateway GATEWAY")
os.system("nmcli con mod team0 connection.autoconnect yes")
os.system("nmcli con mod team0 ipv4.method manual")
os.system("nmcli con mod team0 ipv6.method ignore")
</code></pre>

<p>When I run the script I get this errors:</p>

<pre><code> File "team0.py", line 16
    os.system("nmcli con add type team con-name team0 ifname team0 config '{"runner":{"name": "activebackup"}}'")
                                                                                  ^
SyntaxError: invalid syntax
</code></pre>

<p>Can someone help to find what I'm doing wrong.
Thanks</p>

<p>Sure -- you terminated the string, as shown by the colouring of the text.  It starts at <strong>"nmcli</strong>.  Use a pair of double quotation marks to have them as a literal within the outer string.</p>

<pre><code>os.system("nmcli con add type team con-name team0 ifname team0 config '{""runner"":
</code></pre>

<p>... and so on.  Alternately, put the dictionary value into a variable and append it to the larger string later:</p>

<pre><code>my_dict = '{"runner":{"name": "activebackup"}}'
os.system("nmcli con add type team con-name team0 ifname team0 config '"
         + my_dict) + "'"
</code></pre>

python