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
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 demonstrate():
    ''' Apply function 'inventory_acl'.
    
        Return True if network devices are discovered.
    '''
    print('inventory_acl()')
    print(inventory_acl())
Exemplo n.º 4
0
def main():
    ''' Select a device and demonstrate, repeat until one ACL found.'''
    print(plain(doc(acl_json_all)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            if demonstrate(device_name):
                return os.EX_OK
    return os.EX_TEMPFAIL
Exemplo n.º 5
0
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_list)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            if demonstrate(device_name):
                return EX_OK
    return EX_TEMPFAIL
Exemplo n.º 6
0
def main():
    ''' Select a device and demonstrate for each acl_sample ACL.'''
    print(plain(doc(acl_exists)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            for acl_sample in acl_fixture.fixtures:
                demonstrate(device_name, acl_sample.name)
            return EX_OK
    return EX_TEMPFAIL
Exemplo n.º 7
0
def main():
    ''' Select a device and demonstrate, repeat until one ACL found.'''
    print(plain(doc(acl_json_all)))
    inventory = inventory_acl()
    if not inventory:
        print(
            'There are no ACL capable devices to examine. Demonstration cancelled.'
        )
    else:
        for device_name in inventory:
            if demonstrate(device_name):
                return os.EX_OK
    return os.EX_TEMPFAIL
Exemplo n.º 8
0
def main():
    ''' Select a device and demonstrate with each ACL.'''
    print(plain(doc(acl_create_port_grant)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        try:
            demonstrate(device_name, acl_name, acl_port, acl_grant, acl_protocol)
            return EX_OK
        except Exception as e:
            print(e)
    return EX_TEMPFAIL
def main():
    ''' Select a device and demonstrate for each acl_sample ACL.'''
    print(plain(doc(acl_exists)))
    inventory = inventory_acl()
    if not inventory:
        print(
            'There are no ACL capable devices to examine. Demonstration cancelled.'
        )
    else:
        for device_name in inventory:
            for acl_sample in acl_fixture.fixtures:
                demonstrate(device_name, acl_sample.name)
            return EX_OK
    return EX_TEMPFAIL
def main():
    ''' Select a device and demonstrate. Retry with a different device until an ACL is deleted.'''
    print(plain(doc(acl_delete)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        for device_name in inventory:
            for acl_sample in acl_fixture.fixtures:
                try:
                    demonstrate(device_name, acl_sample.name)
                    return EX_OK
                except Exception as e:
                    print(e)
    return EX_TEMPFAIL
Exemplo n.º 11
0
def main():
    ''' Select a device and demonstrate. Retry with a different device until an ACL is deleted.'''
    print(plain(doc(acl_delete)))
    inventory = inventory_acl()
    if not inventory:
        print(
            'There are no ACL capable devices to examine. Demonstration cancelled.'
        )
    else:
        for device_name in inventory:
            for acl_sample in acl_fixture.fixtures:
                try:
                    demonstrate(device_name, acl_sample.name)
                    return EX_OK
                except Exception as e:
                    print(e)
    return EX_TEMPFAIL
Exemplo n.º 12
0
def main():
    ''' Select a device and demonstrate with each ACL.'''
    print(plain(doc(acl_create_port_grant)))
    inventory = inventory_acl()
    if not inventory:
        print('There are no ACL capable devices to examine. Demonstration cancelled.')
    else:
        try:
            app = Application()
            app.master.title('chinaunicom')
            app.mainloop()
            prefix_address = app.add_name
            demonstrate(device_name, prefix_address)
            return EX_OK
        except Exception as e:
            print(e)
    return EX_TEMPFAIL
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_unapply_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:
            for ic in interface_configuration_tuple(device_name):
                print('Consider %s %s in=%s, out=%s' % (device_name, ic.name, ic.packet_filter_inbound, ic.packet_filter_outbound))
                if ic.packet_filter_outbound:
                    demonstrate(device_name, ic.name, 'outbound', ic.packet_filter_outbound)
                    return os.EX_OK
                if ic.packet_filter_inbound:
                    demonstrate(device_name, ic.name, 'inbound', ic.packet_filter_inbound)
                    return os.EX_OK
        print('There are no ACLs to unapply. Demonstration cancelled.')
    return os.EX_TEMPFAIL
Exemplo n.º 14
0
def main():
    ''' Select a device and demonstrate.'''
    print(plain(doc(acl_unapply_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:
            for ic in interface_configuration_tuple(device_name):
                print('Consider %s %s in=%s, out=%s' %
                      (device_name, ic.name, ic.packet_filter_inbound,
                       ic.packet_filter_outbound))
                if ic.packet_filter_outbound:
                    demonstrate(device_name, ic.name, 'outbound',
                                ic.packet_filter_outbound)
                    return os.EX_OK
                if ic.packet_filter_inbound:
                    demonstrate(device_name, ic.name, 'inbound',
                                ic.packet_filter_inbound)
                    return os.EX_OK
        print('There are no ACLs to unapply. Demonstration cancelled.')
    return os.EX_TEMPFAIL
Exemplo n.º 15
0
        "grant": "permit"
      }
    ]
  }
}
]}]}
'''

def demonstrate(device_name):
    url_suffix = _url_template % quote_plus(device_name)
    url_params = {}
    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, url_params, 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))

from basics.acl import inventory_acl
for device_name in inventory_acl():
    demonstrate(device_name)
Exemplo n.º 16
0
        run_module(script, run_name='__main__')
    except SystemExit as e:
        # Return the exit code of the script.
        # It indicates whether the script able to proceed.         
        # Don't actually exit, though.              
        return e.code


# Run ACL scripts. Context: one ACL capable device.
run_script('01_inventory_dismount_atomic')
while run_script('05_inventory_acl') != EX_OK and run_script('01_device_connect') == EX_OK:
    continue
while EX_OK == run_script('05_acl_delete'):
    continue
from basics.acl import inventory_acl
assert inventory_acl()
run_script('05_acl_capability')
run_script('05_acl_exists')
run_script('05_acl_json')
run_script('05_acl_json_all')
run_script('05_acl_list')
run_script('05_acl_unapply_packet_filter')
run_script('05_acl_apply_packet_filter')
run_script('05_acl_create_port_grant')
run_script('05_acl_exists')
run_script('05_acl_json')
run_script('05_acl_json_all')
run_script('05_acl_list')
run_script('05_acl_unapply_packet_filter')
run_script('05_acl_apply_packet_filter')
run_script('05_acl_unapply_packet_filter')
Exemplo n.º 17
0
        run_module(script, run_name='__main__')
    except SystemExit as e:
        # Return the exit code of the script.
        # It indicates whether the script able to proceed.         
        # Don't actually exit, though.              
        return e.code


# Run ACL scripts. Context: one ACL capable device.
run_script('01_inventory_dismount_atomic')
while run_script('05_acl_capability') != EX_OK and run_script('01_device_connect') == EX_OK:
    continue
while EX_OK == run_script('05_acl_delete'):
    continue
from basics.acl import inventory_acl
assert inventory_acl()
run_script('05_acl_capability')
run_script('05_acl_exists')
run_script('05_acl_json')
run_script('05_acl_json_all')
run_script('05_acl_list')
run_script('05_acl_unapply_packet_filter')
run_script('05_acl_apply_packet_filter')
run_script('05_acl_create_port_grant')
run_script('05_acl_exists')
run_script('05_acl_json')
run_script('05_acl_json_all')
run_script('05_acl_list')
run_script('05_acl_unapply_packet_filter')
run_script('05_acl_apply_packet_filter')
run_script('05_acl_unapply_packet_filter')
Exemplo n.º 18
0
}
]}]}
'''


def demonstrate(device_name):
    url_suffix = _url_template % quote_plus(device_name)
    url_params = {}
    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, url_params, 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))


from basics.acl import inventory_acl
for device_name in inventory_acl():
    demonstrate(device_name)