2424import  json 
2525import  requests 
2626import  sys 
27+ from  argparse  import  ArgumentParser 
2728from  collections  import  OrderedDict 
2829import  urllib3 
2930
@@ -58,7 +59,7 @@ def get_configured_interfaces():
5859 auth = (USER , PASS ),
5960 headers = headers ,
6061 verify = False 
61-  )
62+    )
6263
6364 # return the json as text 
6465 return  response .json ()["ietf-interfaces:interfaces" ]["interface" ]
@@ -78,9 +79,9 @@ def configure_ip_address(interface, ip):
7879 ('ietf-ip:ipv4' ,
7980 OrderedDict ([
8081 ('address' , [OrderedDict ([
81-    ('ip' ,ip ["address" ]),
82-    ('netmask' ,ip ["mask" ])
83-    ])]
82+  ('ip' ,  ip ["address" ]),
83+  ('netmask' ,  ip ["mask" ])
84+  ])]
8485 )
8586 ])
8687 ),
@@ -93,7 +94,7 @@ def configure_ip_address(interface, ip):
9394 headers = headers ,
9495 verify = False ,
9596 json = data 
96-  )
97+    )
9798 print (response .text )
9899
99100
@@ -106,7 +107,7 @@ def print_interface_details(interface):
106107 auth = (USER , PASS ),
107108 headers = headers ,
108109 verify = False 
109-  )
110+    )
110111
111112 intf  =  response .json ()["ietf-interfaces:interface" ]
112113 # return the json as text 
@@ -129,9 +130,9 @@ def interface_selection(interfaces):
129130
130131 # Validate interface input 
131132 # Must be an interface on the device AND NOT be the Management Interface 
132-  while  sel  ==  MANAGEMENT_INTERFACE  or  not  sel  in  [intf ["name" ] for  intf  in  interfaces ]:
133+  while  sel  ==  args . interface  or  not  sel  in  [intf ["name" ] for  intf  in  interfaces ]:
133134 print ("INVALID: Select an available interface." )
134-  print (" "  +  MANAGEMENT_INTERFACE  +  " is used for management." )
135+  print (" "  +  args . interface  +  " is used for management." )
135136 print (" Choose another Interface" )
136137 sel  =  input ("Which Interface do you want to configure? " )
137138
@@ -142,12 +143,14 @@ def interface_selection(interfaces):
142143def  get_ip_info ():
143144 # Ask User for IP and Mask 
144145 ip  =  {}
145-  ip ["address" ] =  input ("What IP address do you want to set? " )
146-  ip ["mask" ] =  input ("What Subnet Mask do you want to set? " )
146+  ip ["address" ] =  do_input ("What IP address do you want to set? " )
147+  ip ["mask" ] =  do_input ("What Subnet Mask do you want to set? " )
147148 return (ip )
148149
149150
150151def  main ():
152+  global  do_input 
153+ 
151154 """ 
152155 Simple main method calling our function. 
153156 """ 
@@ -166,7 +169,7 @@ def main():
166169
167170 # Print Starting Interface Details 
168171 print ("Starting Interface Configuration" )
169-  print_interface_details (selected_interface )
172+  print_interface_details (args ,  selected_interface )
170173
171174 # As User for IP Address to set 
172175 ip  =  get_ip_info ()
0 commit comments