Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
agent
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
7
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5b6838d4
authored
Nov 08, 2018
by
Czémán Arnold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More dns support
Solves issue:
#19
parent
26858401
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
28 additions
and
16 deletions
+28
-16
freebsd/_freebsdcontext.py
+2
-1
freebsd/network.py
+3
-2
linux/_linuxcontext.py
+3
-2
linux/network.py
+12
-7
windows/_win32context.py
+2
-1
windows/network.py
+6
-3
No files found.
freebsd/_freebsdcontext.py
View file @
5b6838d4
...
@@ -102,7 +102,8 @@ class Context(BaseContext):
...
@@ -102,7 +102,8 @@ class Context(BaseContext):
@staticmethod
@staticmethod
def
change_ip
(
interfaces
,
dns
):
def
change_ip
(
interfaces
,
dns
):
change_ip_freebsd
(
interfaces
,
dns
)
nameservers
=
dns
.
replace
(
' '
,
''
)
.
split
(
','
)
change_ip_freebsd
(
interfaces
,
nameservers
)
@staticmethod
@staticmethod
def
set_time
(
time
):
def
set_time
(
time
):
...
...
freebsd/network.py
View file @
5b6838d4
...
@@ -33,7 +33,7 @@ def remove_interfaces_freebsd(devices):
...
@@ -33,7 +33,7 @@ def remove_interfaces_freebsd(devices):
"unable to remove interface configuration: "
+
if_file
)
"unable to remove interface configuration: "
+
if_file
)
def
change_ip_freebsd
(
interfaces
,
dn
s
):
def
change_ip_freebsd
(
interfaces
,
nameserver
s
):
data
=
list
(
get_interfaces_freebsd
(
interfaces
))
data
=
list
(
get_interfaces_freebsd
(
interfaces
))
for
ifname
,
conf
in
data
:
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'stop'
,
ifname
))
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'stop'
,
ifname
))
...
@@ -69,7 +69,8 @@ def change_ip_freebsd(interfaces, dns):
...
@@ -69,7 +69,8 @@ def change_ip_freebsd(interfaces, dns):
f
.
write
(
"defaultrouter=
\"
"
+
str
(
conf
[
'gw4'
])
+
"
\"\n
"
)
f
.
write
(
"defaultrouter=
\"
"
+
str
(
conf
[
'gw4'
])
+
"
\"\n
"
)
with
open
(
"/etc/resolv.conf"
,
"w"
)
as
f
:
with
open
(
"/etc/resolv.conf"
,
"w"
)
as
f
:
f
.
write
(
"nameserver "
+
dns
)
for
ns
in
nameservers
:
f
.
write
(
"nameserver
%
s
\n
"
%
ns
)
for
ifname
,
conf
in
data
:
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'start'
,
ifname
))
subprocess
.
call
((
'/usr/sbin/service'
,
'netif'
,
'start'
,
ifname
))
...
...
linux/_linuxcontext.py
View file @
5b6838d4
...
@@ -89,10 +89,11 @@ class Context(BaseContext):
...
@@ -89,10 +89,11 @@ class Context(BaseContext):
@staticmethod
@staticmethod
def
change_ip
(
interfaces
,
dns
):
def
change_ip
(
interfaces
,
dns
):
nameservers
=
dns
.
replace
(
' '
,
''
)
.
split
(
','
)
if
distro
==
'debian'
:
if
distro
==
'debian'
:
change_ip_ubuntu
(
interfaces
,
dn
s
)
change_ip_ubuntu
(
interfaces
,
nameserver
s
)
elif
distro
==
'rhel'
:
elif
distro
==
'rhel'
:
change_ip_rhel
(
interfaces
,
dn
s
)
change_ip_rhel
(
interfaces
,
nameserver
s
)
@staticmethod
@staticmethod
def
set_time
(
time
):
def
set_time
(
time
):
...
...
linux/network.py
View file @
5b6838d4
...
@@ -52,7 +52,7 @@ def remove_interfaces_ubuntu(devices):
...
@@ -52,7 +52,7 @@ def remove_interfaces_ubuntu(devices):
print
line
print
line
def
change_ip_ubuntu
(
interfaces
,
dn
s
):
def
change_ip_ubuntu
(
interfaces
,
nameserver
s
):
data
=
list
(
get_interfaces_linux
(
interfaces
))
data
=
list
(
get_interfaces_linux
(
interfaces
))
for
ifname
,
conf
in
data
:
for
ifname
,
conf
in
data
:
...
@@ -91,7 +91,7 @@ def change_ip_ubuntu(interfaces, dns):
...
@@ -91,7 +91,7 @@ def change_ip_ubuntu(interfaces, dns):
'ip'
:
ip
,
'ip'
:
ip
,
'prefixlen'
:
prefixlen
,
'prefixlen'
:
prefixlen
,
'gw'
:
conf
[
'gw6'
if
ip
.
version
==
6
else
'gw4'
],
'gw'
:
conf
[
'gw6'
if
ip
.
version
==
6
else
'gw4'
],
'dns'
:
dns
})
'dns'
:
' '
.
join
(
nameservers
)
})
for
ifname
,
conf
in
data
:
for
ifname
,
conf
in
data
:
subprocess
.
call
((
'/sbin/ifup'
,
ifname
))
subprocess
.
call
((
'/sbin/ifup'
,
ifname
))
...
@@ -106,19 +106,24 @@ def change_ip_ubuntu(interfaces, dns):
...
@@ -106,19 +106,24 @@ def change_ip_ubuntu(interfaces, dns):
# '8.8.8.8')
# '8.8.8.8')
def
change_ip_rhel
(
interfaces
,
dn
s
):
def
change_ip_rhel
(
interfaces
,
nameserver
s
):
for
ifname
,
conf
in
get_interfaces_linux
(
interfaces
):
for
ifname
,
conf
in
get_interfaces_linux
(
interfaces
):
subprocess
.
call
((
'/sbin/ifdown'
,
ifname
))
subprocess
.
call
((
'/sbin/ifdown'
,
ifname
))
subprocess
.
call
((
'/sbin/ip'
,
'addr'
,
'flush'
,
'dev'
,
ifname
))
subprocess
.
call
((
'/sbin/ip'
,
'addr'
,
'flush'
,
'dev'
,
ifname
))
subprocess
.
call
((
'/sbin/ip'
,
'link'
,
'set'
,
'dev'
,
ifname
,
'down'
))
subprocess
.
call
((
'/sbin/ip'
,
'link'
,
'set'
,
'dev'
,
ifname
,
'down'
))
with
open
(
ifcfg_template
%
ifname
,
'w'
)
as
f
:
with
open
(
ifcfg_template
%
ifname
,
'w'
)
as
f
:
f
.
write
(
'DEVICE=
%
s
\n
'
f
.
write
(
'DEVICE=
%
s
\n
'
'DNS1=
%
s
\n
'
'BOOTPROTO=none
\n
'
'BOOTPROTO=none
\n
'
'NM_CONTROLLED=no
\n
'
'NM_CONTROLLED=no
\n
'
'USERCTL=no
\n
'
'USERCTL=no
\n
'
'ONBOOT=yes
\n
'
%
(
ifname
,
dns
))
'ONBOOT=yes
\n
'
%
ifname
)
if
len
(
nameservers
)
==
0
:
f
.
write
(
'PEERDNS=no'
)
if
len
(
nameservers
)
>=
1
:
f
.
write
(
'DNS1=
%
s
\n
'
%
nameservers
[
0
])
if
len
(
nameservers
)
>=
2
:
f
.
write
(
'DNS2=
%
s
\n
'
%
nameservers
[
1
])
for
i
in
conf
[
'addresses'
]:
for
i
in
conf
[
'addresses'
]:
ip_with_prefix
=
IPNetwork
(
i
)
ip_with_prefix
=
IPNetwork
(
i
)
ip
=
ip_with_prefix
.
ip
ip
=
ip_with_prefix
.
ip
...
...
windows/_win32context.py
View file @
5b6838d4
...
@@ -39,7 +39,8 @@ class Context(BaseContext):
...
@@ -39,7 +39,8 @@ class Context(BaseContext):
@staticmethod
@staticmethod
def
change_ip
(
interfaces
,
dns
):
def
change_ip
(
interfaces
,
dns
):
change_ip_windows
(
interfaces
,
dns
)
nameservers
=
dns
.
replace
(
' '
,
''
)
.
split
(
','
)
change_ip_windows
(
interfaces
,
nameservers
)
@staticmethod
@staticmethod
def
set_time
(
time
):
def
set_time
(
time
):
...
...
windows/network.py
View file @
5b6838d4
...
@@ -43,7 +43,7 @@ def get_interfaces_windows(interfaces):
...
@@ -43,7 +43,7 @@ def get_interfaces_windows(interfaces):
yield
nic
,
conf
yield
nic
,
conf
def
change_ip_windows
(
interfaces
,
dn
s
):
def
change_ip_windows
(
interfaces
,
nameserver
s
):
for
nic
,
conf
in
get_interfaces_windows
(
interfaces
):
for
nic
,
conf
in
get_interfaces_windows
(
interfaces
):
link_local
=
IPNetwork
(
'fe80::/16'
)
link_local
=
IPNetwork
(
'fe80::/16'
)
new_addrs
=
set
([
IPAddress2
(
ip
)
for
ip
in
conf
[
'addresses'
]])
new_addrs
=
set
([
IPAddress2
(
ip
)
for
ip
in
conf
[
'addresses'
]])
...
@@ -103,6 +103,9 @@ def change_ip_windows(interfaces, dns):
...
@@ -103,6 +103,9 @@ def change_ip_windows(interfaces, dns):
%
(
nic
.
InterfaceIndex
,
conf
.
get
(
'gw6'
)),
shell
=
True
)
%
(
nic
.
InterfaceIndex
,
conf
.
get
(
'gw6'
)),
shell
=
True
)
# DNS
# DNS
index
=
1
for
ns
in
nameservers
:
check_output2
(
'netsh interface ipv4 add dnsserver
%
s '
check_output2
(
'netsh interface ipv4 add dnsserver
%
s '
'address=
%
s index=1'
'address=
%
s index=
%
i'
%
(
nic
.
InterfaceIndex
,
dns
),
shell
=
True
)
%
(
nic
.
InterfaceIndex
,
ns
,
index
),
shell
=
True
)
index
+=
1
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