Skip to content

Commit 2c94e38

Browse files
committed
Added support for resetting router configuration on sandbox
1 parent d219736 commit 2c94e38

4 files changed

Lines changed: 154 additions & 137 deletions

File tree

Lines changed: 58 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,58 @@
1-
!! IOS XR Configuration version = 6.4.1
2-
!! Last configuration change at Sat Jul 28 02:39:47 2018 by ZTP
3-
!
4-
hostname r1
5-
banner motd ;
6-
--------------------------------------------------------------------------
7-
Router 1 (Cisco IOS XR Sandbox)
8-
--------------------------------------------------------------------------
9-
;
10-
service timestamps log datetime msec
11-
service timestamps debug datetime msec
12-
username admin
13-
group root-lr
14-
group cisco-support
15-
secret 5 $1$A4C9$oaNorr6BXDruE4gDd086L.
16-
!
17-
line console
18-
timestamp disable
19-
exec-timeout 0 0
20-
!
21-
vty-pool default 0 4 line-template VTY-TEMPLATE
22-
call-home
23-
service active
24-
contact smart-licensing
25-
profile CiscoTAC-1
26-
active
27-
destination transport-method http
28-
!
29-
!
30-
interface MgmtEth0/RP0/CPU0/0
31-
description *** MANAGEMENT INTERFACE ***
32-
ipv4 address dhcp
33-
!
34-
interface GigabitEthernet0/0/0/0
35-
shutdown
36-
!
37-
interface GigabitEthernet0/0/0/1
38-
shutdown
39-
!
40-
interface GigabitEthernet0/0/0/2
41-
shutdown
42-
!
43-
interface GigabitEthernet0/0/0/3
44-
shutdown
45-
!
46-
interface GigabitEthernet0/0/0/4
47-
shutdown
48-
!
49-
router static
50-
address-family ipv4 unicast
51-
0.0.0.0/0 192.168.122.1
52-
!
53-
!
54-
netconf-yang agent
55-
ssh
56-
!
57-
ssh server v2
58-
ssh server netconf vrf default
59-
end
1+
!
2+
hostname r1
3+
banner motd ;
4+
--------------------------------------------------------------------------
5+
Router 1 (Cisco IOS XR Sandbox)
6+
--------------------------------------------------------------------------
7+
;
8+
service timestamps log datetime msec
9+
service timestamps debug datetime msec
10+
username admin
11+
group root-lr
12+
group cisco-support
13+
secret 5 $1$A4C9$oaNorr6BXDruE4gDd086L.
14+
!
15+
line console
16+
timestamp disable
17+
exec-timeout 0 0
18+
!
19+
vty-pool default 0 4 line-template VTY-TEMPLATE
20+
call-home
21+
service active
22+
contact smart-licensing
23+
profile CiscoTAC-1
24+
active
25+
destination transport-method http
26+
!
27+
!
28+
interface MgmtEth0/RP0/CPU0/0
29+
description *** MANAGEMENT INTERFACE ***
30+
ipv4 address dhcp
31+
!
32+
interface GigabitEthernet0/0/0/0
33+
shutdown
34+
!
35+
interface GigabitEthernet0/0/0/1
36+
shutdown
37+
!
38+
interface GigabitEthernet0/0/0/2
39+
shutdown
40+
!
41+
interface GigabitEthernet0/0/0/3
42+
shutdown
43+
!
44+
interface GigabitEthernet0/0/0/4
45+
shutdown
46+
!
47+
router static
48+
address-family ipv4 unicast
49+
0.0.0.0/0 192.168.122.1
50+
!
51+
!
52+
netconf-yang agent
53+
ssh
54+
!
55+
ssh server v2
56+
ssh server netconf vrf default
57+
end
58+
Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,57 @@
1-
!! IOS XR Configuration version = 6.4.1
2-
!! Last configuration change at Sat Jul 28 02:38:41 2018 by ZTP
3-
!
4-
hostname r2
5-
banner motd ;
6-
--------------------------------------------------------------------------
7-
Router 2 (Cisco IOS XR Sandbox)
8-
--------------------------------------------------------------------------
9-
;
10-
service timestamps log datetime msec
11-
service timestamps debug datetime msec
12-
username admin
13-
group root-lr
14-
group cisco-support
15-
secret 5 $1$A4C9$oaNorr6BXDruE4gDd086L.
16-
!
17-
line console
18-
timestamp disable
19-
exec-timeout 0 0
20-
!
21-
call-home
22-
service active
23-
contact smart-licensing
24-
profile CiscoTAC-1
25-
active
26-
destination transport-method http
27-
!
28-
!
29-
interface MgmtEth0/RP0/CPU0/0
30-
description *** MANAGEMENT INTERFACE ***
31-
ipv4 address dhcp
32-
!
33-
interface GigabitEthernet0/0/0/0
34-
shutdown
35-
!
36-
interface GigabitEthernet0/0/0/1
37-
shutdown
38-
!
39-
interface GigabitEthernet0/0/0/2
40-
shutdown
41-
!
42-
interface GigabitEthernet0/0/0/3
43-
shutdown
44-
!
45-
interface GigabitEthernet0/0/0/4
46-
shutdown
47-
!
48-
router static
49-
address-family ipv4 unicast
50-
0.0.0.0/0 192.168.122.1
51-
!
52-
!
53-
netconf-yang agent
54-
ssh
55-
!
56-
ssh server v2
57-
ssh server netconf vrf default
58-
end
1+
!
2+
hostname r2
3+
banner motd ;
4+
--------------------------------------------------------------------------
5+
Router 2 (Cisco IOS XR Sandbox)
6+
--------------------------------------------------------------------------
7+
;
8+
service timestamps log datetime msec
9+
service timestamps debug datetime msec
10+
username admin
11+
group root-lr
12+
group cisco-support
13+
secret 5 $1$A4C9$oaNorr6BXDruE4gDd086L.
14+
!
15+
line console
16+
timestamp disable
17+
exec-timeout 0 0
18+
!
19+
call-home
20+
service active
21+
contact smart-licensing
22+
profile CiscoTAC-1
23+
active
24+
destination transport-method http
25+
!
26+
!
27+
interface MgmtEth0/RP0/CPU0/0
28+
description *** MANAGEMENT INTERFACE ***
29+
ipv4 address dhcp
30+
!
31+
interface GigabitEthernet0/0/0/0
32+
shutdown
33+
!
34+
interface GigabitEthernet0/0/0/1
35+
shutdown
36+
!
37+
interface GigabitEthernet0/0/0/2
38+
shutdown
39+
!
40+
interface GigabitEthernet0/0/0/3
41+
shutdown
42+
!
43+
interface GigabitEthernet0/0/0/4
44+
shutdown
45+
!
46+
router static
47+
address-family ipv4 unicast
48+
0.0.0.0/0 192.168.122.1
49+
!
50+
!
51+
netconf-yang agent
52+
ssh
53+
!
54+
ssh server v2
55+
ssh server netconf vrf default
56+
end
57+

reset_setup/connection_details.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
r1_user="admin"
4+
r1_password="admin"
5+
r1_port=2222
6+
r1_ip="10.10.20.170"
7+
8+
r2_user="admin"
9+
r2_password="admin"
10+
r2_port=2232
11+
r2_ip="10.10.20.170"

reset_setup/reset_setup.sh

100644100755
Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
#!/bin/bash
2-
3-
r1_user="admin"
4-
r1_port=2222
5-
r1_ip="10.10.20.170"
6-
7-
r2_user="admin"
8-
r2_port=2232
9-
r2_ip="10.10.20.170"
2+
source ./connection_details.sh
103

114
function reset_config() {
125

136
router=$1
147
r_user=$2
15-
r_port=$3
16-
r_ip=$4
8+
r_password=$3
9+
r_port=$4
10+
r_ip=$5
1711

12+
echo -ne "\nStarting Reset process for Router $router....\n"
1813
# Transfer file to the router
19-
scp -P $r_port -o StrictHostKeyChecking=no ./configs/router_reset_$router.conf ${r_user}@$r_ip:/home/admin/router_reset.conf
20-
14+
sshpass -p $r_password scp -P $r_port -o StrictHostKeyChecking=no ./configs/router_reset_$router.conf ${r_user}@$r_ip:/home/admin/router_reset.conf 2>&1 >/dev/null
15+
sleep 2
2116
source_library="source /pkg/bin/ztp_helper.sh"
22-
bash_cmd="$source_library && xrapply /home/admin/router_reset.conf"
17+
bash_cmd="$source_library && xrreplace /home/admin/router_reset.conf"
2318
priv_escalate="sudo -i /bin/bash -c"
2419

25-
timeout 45 ssh -t -o StrictHostKeyChecking=no -p $r_port ${r_user}@$r_ip "$priv_escalate '$bash_cmd'"
26-
20+
timeout 45 sshpass -p $r_password ssh -t -o StrictHostKeyChecking=no -p $r_port ${r_user}@$r_ip "$priv_escalate '$bash_cmd'" 2>&1 > /dev/null
21+
sleep 2
2722
echo "Configuration done!"
2823

2924
xrcmd_cmd="show running-config"
3025
bash_cmd="$source_library && xrcmd $xrcmd_cmd"
3126

32-
echo "Verifying loopback1 configuration..."
33-
ssh -t -o StrictHostKeyChecking=no -p $r_port ${r_user}@$r_ip "$priv_escalate '$bash_cmd'"
27+
echo "Verifying running configuration..."
28+
running_config=`sshpass -p $r_password ssh -t -o StrictHostKeyChecking=no -p $r_port ${r_user}@$r_ip "$priv_escalate '$bash_cmd'"`
29+
running_config=`echo "$running_config" | tail -n +4`
30+
echo "$running_config" > current_running_config_$router
31+
32+
#expected_config=`cat ./configs/router_reset_$router.conf`
33+
34+
compare_result=`cmp --silent ./current_running_config_$router ./configs/router_reset_$router.conf`
35+
if ! [[ "$compare_result" ]]; then
36+
echo -ne "Configuration Successful!\n\n"
37+
rm -f current_running_config_$router
38+
else
39+
echo "Failed to apply configuration"
40+
echo "Current configuration: "
41+
echo -ne "$running_config\n\n\n"
42+
fi
3443

3544
}
3645

3746

3847
# Reset Configuration
39-
reset_config "r1" $r1_user $r1_port $r1_ip
40-
41-
reset_config "r2" $r2_user $r2_port $r2_ip
48+
reset_config "r1" $r1_user $r1_password $r1_port $r1_ip
4249

50+
reset_config "r2" $r2_user $r2_password $r2_port $r2_ip

0 commit comments

Comments
 (0)