Write network address in file
This commit is contained in:
parent
763624dcd3
commit
7c397e4245
@ -1,7 +1,9 @@
|
||||
__author__ = 'RemiZOffAlex'
|
||||
__email__ = 'remizoffalex@mail.ru'
|
||||
|
||||
import yaml
|
||||
import npyscreen
|
||||
|
||||
from pyroute2 import NDB
|
||||
|
||||
|
||||
@ -18,7 +20,8 @@ def network_config(ip, mask, gateway):
|
||||
# em1.add_ip('{ip}/{mask}'.format(ip=ip, mask=mask))
|
||||
# ip.release()
|
||||
with ndb.interfaces['br0'] as br0:
|
||||
br0.add_ip('{ip}/{mask}'.format(ip=ip, mask=mask)).commit()
|
||||
address = '{ip}/{mask}'.format(ip=ip, mask=mask)
|
||||
br0.add_ip(address).commit()
|
||||
|
||||
ndb.routes.create(dst='0.0.0.0/0', gateway=gateway).commit()
|
||||
|
||||
@ -26,17 +29,20 @@ def network_config(ip, mask, gateway):
|
||||
def TestApp(*args):
|
||||
# These lines create the form and populate it with widgets.
|
||||
# A fairly complex screen in only 8 or so lines of code - a line for each control.
|
||||
F = npyscreen.Form(name = "SaaS",)
|
||||
ip = F.add(npyscreen.TitleText, name = "IP:",)
|
||||
mask = F.add(npyscreen.TitleText, name = "Netmask:",)
|
||||
gateway = F.add(npyscreen.TitleText, name = "Gateway:",)
|
||||
NetworkView = npyscreen.ActionForm(name = "SaaS",)
|
||||
ip = NetworkView.add(npyscreen.TitleText, name = "IP:",)
|
||||
mask = NetworkView.add(npyscreen.TitleText, name = "Netmask:",)
|
||||
gateway = NetworkView.add(npyscreen.TitleText, name = "Gateway:",)
|
||||
|
||||
# This lets the user interact with the Form.
|
||||
F.edit()
|
||||
NetworkView.edit()
|
||||
|
||||
network_config(ip, mask, gateway)
|
||||
return {
|
||||
data = {
|
||||
'ip': ip.value,
|
||||
'mask': mask.value,
|
||||
'gateway': gateway.value,
|
||||
'gateway': gateway.value
|
||||
}
|
||||
with open('/root/network.yaml', 'w') as fd:
|
||||
yaml.dump(data, fd)
|
||||
network_config(**data)
|
||||
return data
|
||||
|
||||
Loading…
Reference in New Issue
Block a user