packetcoders / aerleon_acl_gen_demo Goto Github PK
View Code? Open in Web Editor NEWDemo scripts using Aerleon for ACL generation
License: Apache License 2.0
Demo scripts using Aerleon for ACL generation
License: Apache License 2.0
Thank you for the blog and demo code !
Multiprocessing reports an EOF error in the build_acl.py.
I am not a programmer, but keen network engineer learning python and modules for networks.
Looks like Multiprocessing doesn't like the functions of the API being called before the main function test
On a Mac with python3.11, demo installed with git and poetry I get:
python3 build_acl.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 120, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 129, in _main
prepare(preparation_data)
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 240, in prepare
_fixup_main_from_path(data['init_main_from_path'])
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 291, in _fixup_main_from_path
main_content = runpy.run_path(main_path,
^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen runpy>", line 291, in run_path
File "<frozen runpy>", line 98, in _run_module_code
File "<frozen runpy>", line 88, in _run_code
File "/Users/steveh/dev/ip-tools/aerleon_acl_gen_demo/build_acl.py", line 107, in <module>
configs = api.Generate([cisco_asa_policy], definitions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/steveh/Library/Caches/pypoetry/virtualenvs/aerleon-demo-zxD1BcZm-py3.11/lib/python3.11/site-packages/aerleon/api.py", line 233, in Generate
return _Generate(
^^^^^^^^^^
File "/Users/steveh/Library/Caches/pypoetry/virtualenvs/aerleon-demo-zxD1BcZm-py3.11/lib/python3.11/site-packages/aerleon/api.py", line 256, in _Generate
manager: multiprocessing.managers.SyncManager = context.Manager()
^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/context.py", line 57, in Manager
m.start()
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/managers.py", line 563, in start
self._process.start()
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/context.py", line 288, in _Popen
return Popen(process_obj)
^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/popen_spawn_posix.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 158, in get_preparation_data
_check_not_importing_main()
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/spawn.py", line 138, in _check_not_importing_main
raise RuntimeError('''
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "/Users/steveh/dev/ip-tools/aerleon_acl_gen_demo/build_acl.py", line 107, in <module>
configs = api.Generate([cisco_asa_policy], definitions)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/steveh/Library/Caches/pypoetry/virtualenvs/aerleon-demo-zxD1BcZm-py3.11/lib/python3.11/site-packages/aerleon/api.py", line 233, in Generate
return _Generate(
^^^^^^^^^^
File "/Users/steveh/Library/Caches/pypoetry/virtualenvs/aerleon-demo-zxD1BcZm-py3.11/lib/python3.11/site-packages/aerleon/api.py", line 256, in _Generate
manager: multiprocessing.managers.SyncManager = context.Manager()
^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/context.py", line 57, in Manager
m.start()
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/managers.py", line 567, in start
self._address = reader.recv()
^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/connection.py", line 249, in recv
buf = self._recv_bytes()
^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/connection.py", line 413, in _recv_bytes
buf = self._recv(4)
^^^^^^^^^^^^^
File "/usr/local/Cellar/[email protected]/3.11.1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/multiprocessing/connection.py", line 382, in _recv
raise EOFError
EOFError
Wrapping the API functions in a function and then calling from the main function solves the problem.
...
def makeAsaAcl():
# Create an instance of the Naming class
definitions = naming.Naming()
# Use the ParseDefinitionsObject method to parse the "networks" object
definitions.ParseDefinitionsObject(networks, "networks")
# Use the ParseDefinitionsObject method to parse the "services" object
definitions.ParseDefinitionsObject(services, "services")
# Use the Generate method from the api module to generate configurations
# from the "cisco_asa_policy" object, passing in the definitions object
# as an argument
configs = api.Generate([cisco_asa_policy], definitions)
# Render the the ASA configuration from the configs object
acl = configs["cisco_asa_policy.asa"]
# Remove additional blank lines from rendered ACLs
acl = re.sub("\n\n\n", "\n", acl)
return(acl)
if __name__ == "__main__":
# Print the ACL
print(makeAsaAcl()) # no qa
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.