Skip to content

Commit cbb1111

Browse files
authored
Update updateip.py
make management interface a command-line option w/default
1 parent 291fcbc commit cbb1111

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

restconf_update_ipaddress/updateip.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@
3333
# Disable SSL Warnings
3434
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
3535

36-
# Identifies the interface on the device used for management access
37-
# Used to ensure the script isn't used to update the IP leveraged to manage device
38-
MANAGEMENT_INTERFACE = "GigabitEthernet1"
39-
4036
# Identify yang+json as the data formats
4137
headers = {'Content-Type': 'application/yang-data+json',
4238
'Accept': 'application/yang-data+json'}
@@ -130,15 +126,15 @@ def print_interface_details(url_base, interface, username, password):
130126

131127
# Ask the user to select an interface to configure. Ensures input is valid and
132128
# NOT the management interface
133-
def interface_selection(interfaces):
129+
def interface_selection(interfaces, mgmt_if):
134130
# Ask User which interface to configure
135131
sel = input("Which Interface do you want to configure? ")
136132

137133
# Validate interface input
138134
# Must be an interface on the device AND NOT be the Management Interface
139-
while sel == MANAGEMENT_INTERFACE or not sel in [intf["name"] for intf in interfaces]:
135+
while sel == mgmt_if or not sel in [intf["name"] for intf in interfaces]:
140136
print("INVALID: Select an available interface.")
141-
print(" " + MANAGEMENT_INTERFACE + " is used for management.")
137+
print(" " + mgmt_if + " is used for management.")
142138
print(" Choose another Interface")
143139
sel = input("Which Interface do you want to configure? ")
144140

@@ -166,6 +162,11 @@ def main():
166162
default='ios-xe-mgmt.cisco.com')
167163
parser.add_argument('--username', '-u', type=str,
168164
help='sandbox username', default='developer')
165+
# Identifies the interface on the device used for management access
166+
# Used to ensure the script isn't used to update the IP leveraged to manage
167+
# device
168+
parser.add_argument('--management_if', '-m', type=str,
169+
help='management interface', default='GigabitEthernet1')
169170
parser.add_argument('--port', '-P', type=int,
170171
help='sandbox web port', default=443)
171172
args = parser.parse_args()
@@ -186,7 +187,7 @@ def main():
186187
print("")
187188

188189
# Ask User which interface to configure
189-
selected_interface = interface_selection(interfaces)
190+
selected_interface = interface_selection(interfaces, args.management_if)
190191
print(selected_interface)
191192

192193
# Print Starting Interface Details

0 commit comments

Comments
 (0)