pylover / network-interfaces Goto Github PK
View Code? Open in Web Editor NEWPython library for representing and manipulating the /etc/network/interfaces
License: GNU General Public License v3.0
Python library for representing and manipulating the /etc/network/interfaces
License: GNU General Public License v3.0
It would be really convinient if sample, how to add new interface definition to existing file will be provided.
I came to a following solution:
new_iface = Iface
new_iface.name = 'eth4'
new_iface.method = 'static'
new_iface.address_family = 'inet'
new_iface.address = '1.2.3.4'
new_iface.netmask = '255.0.0.0'
new_iface.gateway = '4.3.2.1'
new_iface.startup = Allow
f1 = InterfacesFile('/etc/network/interfaces2')
f1.interfaces.append(new_iface)
f1.save()
Whicth is obviously do not work - there is only <class 'network_interfaces.iface.Iface'>
in result file.
A correct implementation should have been something like:
def find_iface(self, name):
result = [iface for iface in self.interfaces + self.mappings if iface.name == name]
return result[0] if result else None
Validation the interfaces file.
And auto correcting based on ipcalc.
# python ./tests/test_interfaces.py
Traceback (most recent call last):
File "./tests/test_interfaces.py", line 6, in <module>
from network_interfaces import InterfacesFile, Auto, Allow, ValidationError
ImportError: cannot import name ValidationError
Where ValidationError should have been defined?
Traceback (most recent call last):
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/application.py", line 64, in __call__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: response_body = self.__root__(*remaining_paths)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/restfulpy/controllers.py", line 18, in __call__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return super().__call__(*remaining_paths)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 83, in __call__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return self._serve_handler(handler, remaining_paths)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 78, in _serve_handler
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return handler(*remaining_paths, **kwargs)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 83, in __call__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return self._serve_handler(handler, remaining_paths)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 78, in _serve_handler
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return handler(*remaining_paths, **kwargs)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 83, in __call__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return self._serve_handler(handler, remaining_paths)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 78, in _serve_handler
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return handler(*remaining_paths, **kwargs)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 83, in __call__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return self._serve_handler(handler, remaining_paths)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/controllers.py", line 78, in _serve_handler
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return handler(*remaining_paths, **kwargs)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/nanohttp/decorators.py", line 52, in wrapper
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: result = func(*args, **kwargs)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/restfulpy/authorization.py", line 21, in wrapper
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return func(*args, **kwargs)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/ursa/ursa/controllers/interface.py", line 40, in get
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: interface = self.ensure_default_interface()
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/ursa/ursa/controllers/interface.py", line 31, in ensure_default_interface
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: interfaces = interfaces or self.ensure_interfaces()
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/ursa/ursa/controllers/interface.py", line 28, in ensure_interfaces
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: return InterfacesFile(settings.network.interfaces_file)
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/network_interfaces/interface_file.py", line 71, in __init__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: self.sub_files.append(InterfacesFile(subfile[0], source=subfile[1]))
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: File "/usr/local/lib/python3.6/site-packages/network_interfaces/interface_file.py", line 37, in __init__
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: with open(self.absolute_filename) as f:
Feb 1 19:14:58 sandbox-ubuntu gunicorn[1871]: FileNotFoundError: [Errno 2] No such file or directory: '/etc/network/interfaces.d/*'
Feb 1 19:15:01 sandbox-ubuntu CRON[2067]: (root) CMD (command -v debian-sa1 > /dev/null && debian-sa1 1 1)
last published version on pypi.python.org is 0.1.5 (and it isn't working) whereas actual latest version is 2.1.0
Tests fail for revision ee2d666 or the master branch
# python test_interfaces.py
..F
======================================================================
FAIL: test_validate (__main__.NetworkingCase)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test_interfaces.py", line 144, in test_validate
self.assertRaises(ValidationError, eth0.validate)
AssertionError: ValidationError not raised
----------------------------------------------------------------------
Ran 3 tests in 0.013s
FAILED (failures=1)
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.