Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
settingsd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
settingsd
Commits
654d94e5
Commit
654d94e5
authored
Feb 26, 2019
by
Дмитрий Никулин
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Network: support for setting DNS list and hostname
parent
4b300714
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
5 deletions
+32
-5
fmod_network.py
plugins/functions/fmod_network.py
+32
-5
No files found.
plugins/functions/fmod_network.py
View file @
654d94e5
# -*- coding: utf-8 -*-
import
socket
import
os
from
pyroute2
import
IPDB
from
pyroute2.netlink.rtnl.ifinfmsg
import
IFF_UP
from
ipaddress
import
IPv4Address
from
yaml
import
dump
from
yaml
import
dump
,
safe_load
from
settingsd
import
const
from
settingsd
import
config
...
...
@@ -13,7 +14,7 @@ from settingsd import shared
from
settingsd
import
logger
import
settingsd.tools
as
tools
import
settingsd.tools.p
rocess
from
settingsd.tools.process
import
execP
rocess
import
settingsd.tools.editors
##### Private constants #####
...
...
@@ -39,6 +40,16 @@ class Network(service.FunctionObject) :
with
open
(
filename
,
'w+'
)
as
network_config
:
network_config
.
write
(
dump
(
settings
))
@service.functionMethod
(
NETWORK_METHODS_NAMESPACE
,
in_signature
=
"s"
)
def
reloadNetworkConfig
(
self
,
filename
):
with
open
(
filename
,
'r'
)
as
network_config
:
settings
=
safe_load
(
network_config
.
read
())
if
settings
.
get
(
'hostname'
)
is
not
None
:
self
.
_set_hostname
(
settings
[
'hostname'
])
if
settings
.
get
(
'dns'
)
is
not
None
:
self
.
_set_dns_servers
(
settings
[
'dns'
])
def
_dump_interfaces
(
self
):
interfaces
=
{}
...
...
@@ -57,9 +68,9 @@ class Network(service.FunctionObject) :
def
_get_dns_servers
(
self
):
with
open
(
'/etc/resolv.conf'
,
'r'
)
as
resolv_conf
:
return
[
line
.
split
(
' '
)[
1
]
for
line
in
resolv_conf
.
readlines
()
if
line
.
startswith
(
'nameserver'
)
line
.
s
trip
()
.
s
plit
(
' '
)[
1
]
for
line
in
resolv_conf
.
read
()
.
split
lines
()
if
line
.
st
rip
()
.
st
artswith
(
'nameserver'
)
]
def
_prefix_to_netmask
(
self
,
prefix
):
...
...
@@ -67,6 +78,22 @@ class Network(service.FunctionObject) :
(
0xffffffff
<<
(
32
-
prefix
))
&
0xffffffff
))
def
_set_dns_servers
(
self
,
dns_list
):
with
open
(
'/etc/resolv.conf'
,
'r+'
)
as
resolv_conf
:
lines
=
[
line
for
line
in
resolv_conf
.
read
()
.
splitlines
()
if
not
line
.
strip
()
.
startswith
(
'nameserver'
)
]
lines
+=
[
'nameserver '
+
dns
for
dns
in
dns_list
]
resolv_conf
.
seek
(
0
,
os
.
SEEK_SET
)
resolv_conf
.
write
(
'
\n
'
.
join
(
lines
))
resolv_conf
.
truncate
()
def
_set_hostname
(
self
,
hostname
):
with
open
(
'/etc/hostname'
,
'w'
)
as
etc_hostname
:
etc_hostname
.
write
(
hostname
)
execProcess
([
'hostname'
,
hostname
],
shell
=
True
)
##### Public classes #####
class
Service
(
service
.
Service
)
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment