Example #1
0
def main():

    # Create instance using default hosts.yaml and groups.yaml
    brg = InitBrigade()

    # print(dir(brg))
    print("Hosts derived from the Inventory file are: \t{}".format(
        brg.inventory.hosts))
    print("Groups derived from the Inventory file are: \t{}".format(
        brg.inventory.groups))

    print("\nDecomposing Groups...")
    my_groups = brg.inventory.groups
    group_keys = list(my_groups.keys())
    print("Group keys = {} of type {} ".format(group_keys, type(group_keys)))
    for i in group_keys:
        print(i)

    print("\nDecomposing Hosts...")
    my_hosts = brg.inventory.hosts
    print("Type of my_hosts is {}".format(type(my_hosts)))

    host_keys = list(my_hosts.keys())
    print("Host keys = {} of type {} ".format(host_keys, type(host_keys)))
    for i in host_keys:
        print(i)

    print("\n")

    result = brg.run(napalm_get, getters=['get_facts'])

    print("\nDecomposing Result Object...")

    x = dict(result)
    for i in x:

        li = list(x[i])

        li_keys = li[0].result['get_facts'].keys()
        # dict_keys(['uptime', 'vendor', 'os_version', 'serial_number', 'model', 'hostname', 'fqdn', 'interface_list'])
        #
        print("\tDecomposing Result Object for hostname {}...".format(
            li[0].result['get_facts']['hostname']))
        for k in li_keys:
            print("\t\tKey {} \t : Value = {}".format(
                k, li[0].result['get_facts'][k]))

        print("\n")

    print(
        "Print run results with the print_result module (this is an Ansible like run status)..."
    )
    print_result(result)
Example #2
0
# Example from Patrick Ogenstad at Networklore
# https://networklore.com/introducing-brigade/
from brigade.core import InitBrigade
from brigade.plugins.tasks.networking import napalm_get
from brigade.plugins.functions.text import print_result

brg = InitBrigade()

result = brg.run(napalm_get, getters=['get_facts'])

print_result(result)
Example #3
0
 def test_print_failed_with_severity(self, brigade):
     result = brigade.run(read_data)
     print_result(result, vars=["exception", "output"], severity_level=logging.ERROR)
Example #4
0
    config += r.result

    r = task.run(
        name="OSPF Configuration",
        task=template_file,
        template="ospf.js",
        path=f"templates",
    )
    config += r.result

    task.run(
        name="Loading Configuration on the device",
        task=napalm_configure,
        replace=False,
        configuration=config,
    )


# Initialize brigade
brg = InitBrigade(dry_run=True, num_workers=20)

# Let's just filter the hosts we want to operate on
target = brg.filter(type="router")

# Let's call the grouped tasks defined above
results = target.run(task=configure)

# Let's show everything on screen
print_title("Playbook to configure the network")
print_result(results)
Example #5
0
 def test_print_changed_host(self, brigade):
     filter = brigade.filter(site="site1")
     result = filter.run(read_data, severity_level=logging.WARN)
     print_result(result)
Example #6
0
 def test_print_multiple_tasks(self, brigade):
     result = brigade.run(data_with_greeting)
     print_title("Behold the data!")
     print_result(result)
Example #7
0
 def test_print_basic_inventory_one_task(self, brigade):
     result = brigade.run(data_with_greeting)
     print_result(result["dev2.group_1"][1])
Example #8
0
 def test_print_basic_inventory(self, brigade):
     result = brigade.run(echo_task)
     print_result(result)
Example #9
0
 def test_print_basic(self, brigade):
     filter = brigade.filter(name="dev1.group_1")
     result = filter.run(echo_task)
     print_result(result, vars="result")