#!/usr/bin/env python3
# unit_test/cisco/nxos/unit_test_nxos_bgp_neighbor.py
our_version = 104
 
from ask.common.playbook import Playbook
from ask.common.log import Log
from ask.cisco.nxos.nxos_bgp_neighbor import NxosBgpNeighbor

ansible_module = 'nxos_bgp_neighbor'
ansible_host = 'dc-101' # must be in ansible inventory
log = Log('unit_test_{}'.format(ansible_module), 'INFO', 'DEBUG')

def playbook():
    pb = Playbook(log)
    pb.profile_nxos()
    pb.ansible_password = '******'
    pb.file = '/tmp/{}.yaml'.format(ansible_module)
    pb.name = '{} task'.format(ansible_module)
    pb.add_host(ansible_host)
    return pb

def add_task_name(task):
    task.append_to_task_name('v.{}'.format(our_version))
    task.append_to_task_name(ansible_host)
    for key in sorted(task.properties_set):
        task.append_to_task_name(key)

def ipv4_neighbor(pb):
    task = NxosBgpNeighbor(log)
    task.asn = '12000.0'
    task.neighbor = '10.1.1.1'
Example #2
0
#!/usr/bin/env python3
# unit_test/cisco/nxos/unit_test_nxos_vpc.py
our_version = 105
from ask.common.playbook import Playbook
from ask.common.log import Log
from ask.cisco.nxos.nxos_vpc import NxosVpc

ansible_module = 'nxos_vpc'
ansible_host = 'dc-101'  # must be in ansible inventory
log = Log('unit_test_{}'.format(ansible_module), 'INFO', 'DEBUG')


def playbook():
    pb = Playbook(log)
    pb.ansible_connection = 'httpapi'  # httpapi, network_cli
    pb.ansible_password = '******'
    pb.file = '/tmp/{}.yaml'.format(ansible_module)
    pb.name = '{} task'.format(ansible_module)
    pb.add_host(ansible_host)
    return pb


def add_task_name(task):
    task.append_to_task_name('v{}, {}'.format(our_version, ansible_host))
    for key in sorted(task.scriptkit_properties):
        task.append_to_task_name(key)


def add_task(pb):
    task = NxosVpc(log)
    task.auto_recovery_reload_delay = 120
def task_vtp_password_add(pb):
    task = NxosVtpPassword(log)
    task.vtp_password = '******'
    task.state = 'present'
    add_task_name(task)
    task.commit()
    pb.add_task(task)


def task_vtp_password_remove(pb):
    task = NxosVtpPassword(log)
    task.state = 'absent'
    add_task_name(task)
    task.commit()
    pb.add_task(task)


ansible_module = 'nxos_vtp_password'
ansible_host = 'dc-101'  # must be in ansible inventory
log_level_console = 'INFO'
log_level_file = 'DEBUG'
log = Log('unit_test_{}'.format(ansible_module), log_level_console,
          log_level_file)

pb = playbook()
task_vtp_password_add(pb)
#task_vtp_password_remove(pb)
pb.append_playbook()
pb.write_playbook()
print('wrote playbook {}'.format(pb.file))
#!/usr/bin/env python3
# unit_test/cisco/nxos/unit_test_nxos_gir_profile_management.py
# Status = BETA
our_version = 100
from ask.common.playbook import Playbook
from ask.common.log import Log
from ask.cisco.nxos.nxos_gir_profile_management import NxosGirProfileManagement

log_level_console = 'INFO'
log_level_file = 'DEBUG'
log = Log('my_log', log_level_console, log_level_file)

pb = Playbook(log)
pb.profile_nxos()
pb.ansible_password = '******'
pb.name = 'nxos_gir_profile_management example'
pb.add_host('dc-101')
pb.file = '/tmp/nxos_gir_profile_management.yaml'

commands = list()
commands.append('router ospf 1')
commands.append('isolate')
task = NxosGirProfileManagement(log)
task.commands = commands
task.mode = 'maintenance'
task.state = 'present'
task.task_name = 'gir mode {} state {}'.format(task.mode, task.state)
task.commit()

pb.add_task(task)
pb.append_playbook()
#!/usr/bin/env python3
# unit_test/cisco/nxos/unit_test_nxos_interfaces.py
our_version = 105

from ask.common.playbook import Playbook
from ask.common.log import Log
from ask.cisco.nxos.nxos_interfaces import NxosInterfaces

ansible_module = 'nxos_interfaces'
ansible_host = 'dc-101' # must be in ansible inventory
log_level_console = 'INFO'
log_level_file = 'DEBUG'
log = Log('unit_test_{}'.format(ansible_module), log_level_console, log_level_file)

def playbook():
    pb = Playbook(log)
    pb.profile_nxos()
    pb.ansible_password = '******'
    pb.file = '/tmp/{}.yaml'.format(ansible_module)
    pb.name = '{} 5 ethernet and 5 SVI interfaces'.format(ansible_module)
    pb.add_host(ansible_host)
    return pb

def add_ethernet_interfaces(task):
    for port in range(1,6):
        task.name = 'Ethernet1/{}'.format(port)
        task.description = '{} Vlan{} hosts'.format(task.name, port + 220)
        task.mtu = 9216
        task.mode = 'layer2'
        task.speed = 100000
        task.duplex = 'auto'
Example #6
0
    task.add_interface()
    task.state = 'merged'
    task.commit()
    pb.add_task(task)

def task_nxos_bfd_interfaces(pb):
    task = NxosBfdInterfaces(log)
    task.name = 'Ethernet1/49'
    task.echo = 'enable'
    task.add_interface()
    task.state = 'merged'
    task.task_name = 'enable bfd echo on {}'.format(task.name)
    task.commit()
    pb.add_task(task)

log = Log('test_playbook', 'INFO', 'DEBUG')
pb = Playbook(log)
pb.profile_nxos() # commonly used NXOS settings
pb.ansible_connection = 'network_cli' # profile_nxos() sets this to httpapi
pb.ansible_password = '******'
# write the playbook to a file
pb.file = '/tmp/playbook.yaml'
# Creates a single playbook with two tasks
task_nxos_interfaces(pb)
task_nxos_bfd_interfaces(pb)
pb.add_host('t301')  # host in Ansible inventory
pb.add_environment('no_proxy', '*')
pb.add_vars('my_var1', 'my_var_value1')
pb.add_vars('my_var2', 'my_var_value2')
pb.append_playbook()
pb.write_playbook()
Example #7
0
#!/usr/bin/env python3
# common/unit_test/common_set_none.py
our_version = 100
from ask.common.playbook import Playbook
from ask.cisco.nxos.nxos_aaa_server import NxosAaaServer
from ask.common.log import Log
log = Log('test_common_set_none', 'INFO', 'DEBUG')

def nxos_aaa_server(pb):
    task = NxosAaaServer(log)
    task.directed_request = 'enabled'
    log.info('BEFORE: task.directed request {}'.format(task.directed_request))
    task.directed_request = None # verifies that Common().set_none() is working
    log.info('AFTER: task.directed request {}'.format(task.directed_request))
    if task.directed_request != None:
        log.error('FAIL: task.directed_request = None')
        exit(1)
    task.server_type = 'tacacs'
    task.state = 'present'
    task.update()
    pb.add_task(task)

pb = Playbook(log)
pb.file = '/tmp/unit_test_common_set_none.yaml'
pb.add_host('dc-101')  # host in Ansible inventory

nxos_aaa_server(pb)

pb.append_playbook()
pb.write_playbook()
log.info('wrote {}'.format(pb.file))