def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_apply_packet_filter)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            mgmt_name = management_interface(device_name)
            acl_names = acl_list(device_name)
            if not acl_names:
                print('Skip device with no ACLs: ', device_name)
                continue
            else:
                random.shuffle(acl_names)
                acl_name = acl_names[0]
            for ic in interface_configuration_tuple(device_name):
                if ic.name == mgmt_name:
                    continue
                print('Consider %s %s in=%s, out=%s' % (device_name, ic.name, ic.packet_filter_inbound, ic.packet_filter_outbound))
                if not ic.packet_filter_outbound:
                    demonstrate(device_name, ic.name, 'outbound', acl_name)
                    return EX_OK
                if not ic.packet_filter_inbound:
                    demonstrate(device_name, ic.name, 'inbound', acl_name)
                    return EX_OK
        print('There are no network interfaces available to apply an ACL. Demonstration cancelled.')
    return EX_TEMPFAIL
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_apply_packet_filter)))
    inventory = inventory_acl()
    if not inventory:
        print(
            'There are no ACL capable devices to examine. Demonstration cancelled.'
        )
    else:
        for device_name in inventory:
            mgmt_name = management_interface(device_name)
            acl_names = acl_list(device_name)
            if not acl_names:
                print('Skip device with no ACLs: ', device_name)
                continue
            else:
                random.shuffle(acl_names)
                acl_name = acl_names[0]
            for ic in interface_configuration_tuple(device_name):
                if ic.name == mgmt_name:
                    continue
                print('Consider %s %s in=%s, out=%s' %
                      (device_name, ic.name, ic.packet_filter_inbound,
                       ic.packet_filter_outbound))
                if not ic.packet_filter_outbound:
                    demonstrate(device_name, ic.name, 'outbound', acl_name)
                    return os.EX_OK
                if not ic.packet_filter_inbound:
                    demonstrate(device_name, ic.name, 'inbound', acl_name)
                    return os.EX_OK
        print(
            'There are no network interfaces available to apply an ACL. Demonstration cancelled.'
        )
    return os.EX_TEMPFAIL
Ejemplo n.º 3
0
def demonstrate(device_name):
    ''' Apply function 'acl_list' to the specified device.
    
        Return True if an ACL was found.
    '''
    print('acl_list(' + device_name, end=')\n')
    result = acl_list(device_name)
    print(result)
    return bool(result)
Ejemplo n.º 4
0
def demonstrate(device_name):
    ''' Apply function 'acl_list' to the specified device.
    
        Return True if an ACL was found.
    '''
    print('acl_list(' + device_name, end=')\n')
    result = acl_list(device_name)
    print(result)
    return bool(result)
Ejemplo n.º 5
0
def demonstrate(device_name):
    url_suffix = _url_template % quote_plus(device_name)
    contentType = 'application/json'
    accept = contentType
    expected_status_code = [204, 409]
    source_address = '1.0.0.0'
    source_wild_card_bits = '0.255.255.255'
    next_hop = '4.3.2.1'
    access_list_name = quote_plus('policy-route-http')
    content = _acl_route_request_content % (access_list_name, source_wild_card_bits, source_address, next_hop)
    print('acl_next_hop(%s)'%device_name)
    response = odl_http_post(url_suffix, contentType, content, accept, expected_status_code)
    if response.status_code != 204:
        print(response)
    else:
        print('ACLs:', acl_list(device_name))
        print(json.dumps(acl_json(device_name, access_list_name), indent=2))
Ejemplo n.º 6
0
def demonstrate(device_name):
    url_suffix = _url_template % quote_plus(device_name)
    contentType = 'application/json'
    accept = contentType
    expected_status_code = [204, 409]
    source_address = '1.0.0.0'
    source_wild_card_bits = '0.255.255.255'
    next_hop = '4.3.2.1'
    access_list_name = quote_plus('policy-route-http')
    content = _acl_route_request_content % (
        access_list_name, source_wild_card_bits, source_address, next_hop)
    print('acl_next_hop(%s)' % device_name)
    response = odl_http_post(url_suffix, contentType, content, accept,
                             expected_status_code)
    if response.status_code != 204:
        print(response)
    else:
        print('ACLs:', acl_list(device_name))
        print(json.dumps(acl_json(device_name, access_list_name), indent=2))
Ejemplo n.º 7
0
def find_acls_on_device(device_name):
    return acl_list(device_name);