コード例 #1
0
def compare_bgp_peer_states(connection, store):
    ''' Compares the current BGP peer state with that gathered in previous module '''

    current_bgp_peer_state = execute_device_operation('juniper_get_bgp_peers',
                                                      connection)

    if current_bgp_peer_state["result"] == "fail":
        return ModuleResult.fail

    peers_with_changed_state = []

    for current_peer in current_bgp_peer_state["stdout"]["peers"]:
        for previous_peer in store["previous_bgp_peer_state"]:
            if current_peer["peer_ip"] == previous_peer["peer_ip"]:
                if all([
                        current_peer["peering_state"] !=
                        previous_peer["peering_state"],
                        current_peer["peering_state"] != "Established"
                ]):
                    peers_with_changed_state.append(current_peer)

    if len(peers_with_changed_state) > 0:
        store["peers_with_changed_state"] = peers_with_changed_state
        return ModuleResult.branch("monitor_bgp_peer_state", delay=45)

    store["previous_bgp_peer_state"] = current_bgp_peer_state["stdout"][
        "peers"]
    return ModuleResult.retry(delay=10)
コード例 #2
0
ファイル: test_module_1.py プロジェクト: syynack/moss
def test_module_1(connection, store):
    output = execute_device_operation('cisco_ios_ping',
                                      connection,
                                      destination='8.8.8.8')
    if output["stdout"]["echo_replies"] != output["stdout"]["echo_requests"]:
        return ModuleResult.fail

    return ModuleResult.success
コード例 #3
0
def test_module_1(connection, store):
    config_statements = [
        'ip ssh version 2', 'ip address 192.168.253.130 255.255.255.0',
        'router eigrp 1', 'router ospf 1'
    ]
    output = execute_device_operation('cisco_ios_check_configuration',
                                      connection,
                                      config_statements=config_statements)
    return ModuleResult.success
コード例 #4
0
ファイル: get_bgp_peer_states.py プロジェクト: syynack/moss
def get_bgp_peer_states(connection, store):
    ''' Gathers the current status of all BGP peers '''

    current_bgp_peer_state = execute_device_operation('juniper_get_bgp_peers', connection)

    if current_bgp_peer_state["result"] == "fail":
        return ModuleResult.fail

    store["previous_bgp_peer_state"] = current_bgp_peer_state["stdout"]["peers"]
    return ModuleResult.success(delay = 10)
コード例 #5
0
ファイル: test_module_1.py プロジェクト: syynack/moss
def test_module_1(connection, store):
    config_statements = [
        'router ospf 1', 'router-id 1.1.1.1',
        'network 192.168.253.129 255.255.255.0 area 0'
    ]

    output = execute_device_operation(
        'cisco_ios_apply_configuration',
        connection,
        config_statements=config_statements,
        #write_config = True
    )

    return ModuleResult.success
コード例 #6
0
def post_check_current_bgp_peers(connection, store):
    ''' Checks current BGP peers for updated entry '''

    current_bgp_peers = execute_device_operation('cisco_ios_get_bgp_summary',
                                                 connection)

    if current_bgp_peers["result"] == "fail":
        return ModuleResult.fail

    for peer in current_bgp_peers["stdout"]["peers"]:
        if (store["arguments"]["peer_ip"] == peer["peer_ip"]) and (int(
                store["arguments"]["peer_as"]) == peer["as_number"]):
            return ModuleResult.success
        else:
            return ModuleResult.fail
コード例 #7
0
def apply_disable_statement(connection, store):
    ''' If the interface was found to be up it will be disabled '''

    deactivate_configuration = [
        'set interfaces {} disable'.format(store["arguments"]["interface"])
    ]
    deactivation_output = execute_device_operation(
        'juniper_apply_configuration',
        connection,
        config_statements=deactivate_configuration)

    if deactivation_output["result"] == "fail":
        return ModuleResult.fail

    return ModuleResult.success(delay=5)
コード例 #8
0
def post_check_interface_status(connection, store):
    ''' Gets the output of show interfaces terse for an interface '''

    current_interface_status = execute_device_operation(
        'juniper_show_interfaces_terse',
        connection,
        interface=store["arguments"]["interface"])

    if current_interface_status["result"] == "fail":
        return ModuleResult.fail

    for interface in current_interface_status["stdout"]["interfaces"]:
        if interface["link_status"] != "down":
            return ModuleResult.fail

    return ModuleResult.success
コード例 #9
0
ファイル: apply_new_ospf_cost.py プロジェクト: syynack/moss
def apply_new_ospf_cost(connection, store):
    ''' Applies new cost configuration to interfaces. '''

    for operational_interface in store["operational_interfaces"]:
        config_statements = ['interface {}'.format(operational_interface)
                             ] + store["config_statements"]

        apply_config_output = execute_device_operation(
            'cisco_ios_apply_configuration',
            connection,
            config_statements=config_statements)

        if apply_config_output["result"] == "fail":
            return ModuleResult.fail

    return ModuleResult.success
コード例 #10
0
def pre_check_interface_status(connection, store):
    ''' Gets the output of show interfaces terse for an interface '''

    current_interface_status = execute_device_operation(
        'juniper_show_interfaces_terse', 
        connection,
        interface = store["arguments"]["interface"]
    )

    if current_interface_status["result"] == "fail":
        return ModuleResult.fail

    for interface in current_interface_status["stdout"]["interfaces"]:
        if interface["name"] == store["arguments"]["interface"] and interface["link_status"] == "down":
            return ModuleResult.branch('apply_delete_disable_statement')

    return ModuleResult.end
コード例 #11
0
def post_check_bgp_peer_config(connection, store):
    ''' Post checks that BGP neighbour config has been applied '''

    config_statements = ['neighbor {} remote-as {}'.format(store["arguments"]["peer_ip"], store["arguments"]["peer_as"])]

    current_config = execute_device_operation(
        'cisco_ios_check_configuration',
        connection,
        config_statements = config_statements,
        area = 'router bgp {}'.format(store["arguments"]["local_as"])
    )

    if current_config["result"] == "fail":
        return ModuleResult.fail

    if current_config["stdout"]["present_config_statements"]:
        return ModuleResult.success
コード例 #12
0
def add_bgp_peer(connection, store):
    ''' Adds configuration for BGP peer '''

    config_statements = [
        'router bgp {}'.format(store["arguments"]["local_as"]),
        'neighbor {} remote-as {}'.format(store["arguments"]["peer_ip"],
                                          store["arguments"]["peer_as"])
    ]

    applied_configuration = execute_device_operation(
        'cisco_ios_apply_configuration',
        connection,
        config_statements=config_statements)

    if applied_configuration["result"] == "fail":
        return ModuleResult.fail

    return ModuleResult.success
コード例 #13
0
def post_check_delete_disable_statement(connection, store):
    ''' Checks configuration to make sure the deactivation config has been applied '''

    configuration_check_output = execute_device_operation(
        'juniper_check_configuration',
        connection,
        config_statements=["disable"],
        area='interfaces {}'.format(store["arguments"]["interface"]))

    if configuration_check_output["result"] == "fail":
        return ModuleResult.fail

    for statement in configuration_check_output["stdout"][
            "present_config_statements"]:
        if "disable;" in statement:
            return ModuleResult.fail

    return ModuleResult.success
コード例 #14
0
def get_operational_interfaces(connection, store):
    ''' Finds currently up/up interfaces on the target device and stores interface names. '''

    current_interfaces = execute_device_operation('cisco_ios_show_interfaces', connection)

    if current_interfaces["result"] == "fail":
        return ModuleResult.fail

    operational_interfaces = []

    for interface in current_interfaces["stdout"]:
        if interface["operational_status"] == "up" and interface["line_status"] == "up":
            operational_interfaces.append(interface["name"])

    if len(operational_interfaces) == 0:
        return ModuleResult.end

    store["operational_interfaces"] = operational_interfaces
    return ModuleResult.success
コード例 #15
0
def postcheck_configured_ospf_cost(connection, store):
    ''' Checks if the correct OSPF hello and dead intervals are configured on stored interfaces. '''

    successful_interfaces = []

    for operational_interface in store['operational_interfaces']:
        current_ospf_timers_output = execute_device_operation(
            'cisco_ios_check_configuration',
            connection,
            config_statements=store["config_statements"],
            area='interface {}'.format(operational_interface))

        if current_ospf_timers_output["result"] == "fail":
            return ModuleResult.fail

        if current_ospf_timers_output["stdout"][
                "present_config_statements"] == store['config_statements']:
            successful_interfaces.append(operational_interface)

    if successful_interfaces == store['operational_interfaces']:
        return ModuleResult.success

    return ModuleResult.fail
コード例 #16
0
def precheck_configured_ospf_cost(connection, store):
    ''' Checks if the correct OSPF cost is configured on stored interfaces. '''

    store["config_statements"] = ['ip ospf cost 65535']

    updated_interfaces = store["operational_interfaces"]

    for operational_interface in store["operational_interfaces"]:
        current_ospf_timers_output = execute_device_operation(
            'cisco_ios_check_configuration',
            connection,
            config_statements=store["config_statements"],
            area='interface {}'.format(operational_interface))

        if current_ospf_timers_output["result"] == "fail":
            return ModuleResult.fail

        if current_ospf_timers_output["stdout"][
                "present_config_statements"] == store['config_statements']:
            updated_interfaces.remove(operational_interface)

    store["operational_interfaces"] = updated_interfaces
    return ModuleResult.success
コード例 #17
0
def test_module_1(connection, store):
    output = execute_device_operation('cisco_ios_get_bgp_summary', connection)
    return ModuleResult.success
コード例 #18
0
def test_module_1(connection, store):
    output = execute_device_operation('cisco_ios_show_interfaces', connection)
    return ModuleResult.success