Skip to content

Commit

Permalink
Create pyats_addvlan.py
Browse files Browse the repository at this point in the history
  • Loading branch information
emomeni authored Jul 15, 2024
1 parent 467bd48 commit 8d71975
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions pyats_addvlan.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from pyats import aetest
from pyats.topology import loader
from genie.libs.conf.interface import Interface

class AddVlanToTrunk(aetest.Testcase):
@aetest.setup
def setup(self, testbed):
self.testbed = loader.load(testbed)
self.device = self.testbed.devices['switch']
self.device.connect()

@aetest.test
def add_vlan(self):
vlan_id = 10
interface_name = 'GigabitEthernet0/1'
trunk_interface = Interface(name=interface_name, device=self.device)

# Add the VLAN to the trunk interface
trunk_interface.build_config(apply=False)
self.device.configure(f'''
interface {interface_name}
switchport mode trunk
switchport trunk allowed vlan add {vlan_id}
''')

@aetest.test
def verify_vlan(self):
vlan_id = 10
interface_name = 'GigabitEthernet0/1'

# Verify the VLAN is added to the trunk interface
output = self.device.execute(f'show interfaces {interface_name} switchport')
if f'Trunking VLANs Enabled: {vlan_id}' in output:
self.passed(f'VLAN {vlan_id} successfully added to trunk interface {interface_name}')
else:
self.failed(f'Failed to add VLAN {vlan_id} to trunk interface {interface_name}')

@aetest.cleanup
def cleanup(self):
self.device.disconnect()

if __name__ == '__main__':
import argparse
from pyats import topology

parser = argparse.ArgumentParser()
parser.add_argument('--testbed', dest='testbed', type=topology.loader.load, required=True)
args, unknown = parser.parse_known_args()

aetest.main(testbed=args.testbed)

0 comments on commit 8d71975

Please sign in to comment.