0% found this document useful (0 votes)
4 views3 pages

SSH Command Execution for BGP Configuration

The document outlines an implementation and backout plan using Python and the Paramiko library to execute SSH commands on two hosts. The implementation plan includes commands to modify BGP configurations, while the backout plan provides commands to revert those changes. Both plans define the hosts and credentials, and utilize a function to execute the commands remotely.

Uploaded by

sallauddin7640
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

SSH Command Execution for BGP Configuration

The document outlines an implementation and backout plan using Python and the Paramiko library to execute SSH commands on two hosts. The implementation plan includes commands to modify BGP configurations, while the backout plan provides commands to revert those changes. Both plans define the hosts and credentials, and utilize a function to execute the commands remotely.

Uploaded by

sallauddin7640
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

Implementation plan

import paramiko

def execute_commands(host, username, password, commands):


ssh = [Link]()
ssh.set_missing_host_key_policy([Link]())
[Link](host, username=username, password=password)

for command in commands:


stdin, stdout, stderr = ssh.exec_command(command)
print([Link]().decode())
print([Link]().decode())

[Link]()

# Define the hosts and credentials


hosts = [
{"host": "ENS-LF001-UK3", "username": "your_username", "password":
"your_password"},
{"host": "ENS-LF002-UK3", "username": "your_username", "password":
"your_password"}
]

# Define the commands for each host


commands_1 = [
"sh ip bgp vrf ens_mo_core su",
"configure terminal",
"router bgp 65400",
"vrf ens_mo_core",
"no neighbor [Link]",
"end",
"copy run start"
]

commands_2 = [
"sh ip bgp vrf ens_mo_core su",
"configure terminal",
"router bgp 65400",
"vrf ens_mo_core",
"no neighbor [Link]",
"end",
"copy run start"
]

# Execute the commands on each host


execute_commands(hosts[0]["host"], hosts[0]["username"], hosts[0]["password"],
commands_1)
execute_commands(hosts[1]["host"], hosts[1]["username"], hosts[1]["password"],
commands_2)

-----------------------------------------------

Backout plan

import paramiko
def execute_commands(host, username, password, commands):
ssh = [Link]()
ssh.set_missing_host_key_policy([Link]())
[Link](host, username=username, password=password)

for command in commands:


stdin, stdout, stderr = ssh.exec_command(command)
print([Link]().decode())
print([Link]().decode())

[Link]()

# Define the hosts and credentials


hosts = [
{"host": "ENS-LF001-UK3", "username": "your_username", "password":
"your_password"},
{"host": "ENS-LF002-UK3", "username": "your_username", "password":
"your_password"}
]

# Define the commands for each host


commands_1 = [
"configure terminal",
"router bgp 65400",
"vrf ens_mo_core",
"neighbor [Link]",
"remote-as 64850",
"description BGP Session to MO Core NSX_T0",
"password 7 0230294C0A140A700D78240E0405175A4D",
"ebgp-multihop 5",
"address-family ipv4 unicast",
"send-community",
"route-map ENS_MO_CORE_NSX-T_IN in",
"route-map ENS_MO_CORE_NSX-T_OUT out",
"maximum-prefix 100 90",
"end",
"sh ip bgp vrf ens_mo_core su",
"copy run start"
]

commands_2 = [
"configure terminal",
"router bgp 65400",
"vrf ens_mo_core",
"neighbor [Link]",
"remote-as 64850",
"description BGP Session to MO Core NSX_T0",
"password 7 0230294C0A140A700D78240E0405175A4D",
"ebgp-multihop 5",
"address-family ipv4 unicast",
"send-community",
"route-map ENS_MO_CORE_NSX-T_IN in",
"route-map ENS_MO_CORE_NSX-T_OUT out",
"maximum-prefix 100 90",
"end",
"sh ip bgp vrf ens_mo_core su",
"copy run start"
]
# Execute the commands on each host
execute_commands(hosts[0]["host"], hosts[0]["username"], hosts[0]["password"],
commands_1)
execute_commands(hosts[1]["host"], hosts[1]["username"], hosts[1]["password"],
commands_2)
-----------------------------------

You might also like