Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Anders Blomdell
hostinfo
Commits
0900dcb3
Commit
0900dcb3
authored
Aug 11, 2017
by
Anders Blomdell
Browse files
Add current firewall zone to ifconfig file
parent
9a90513f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/hostinfo/ifconfig.py
View file @
0900dcb3
...
...
@@ -3,19 +3,45 @@ import subprocess
import
re
import
ipaddr
def
get_uuid
(
device
):
def
get_nm_extra
(
device
):
result
=
""
try
:
import
dbus
obj
=
dbus
.
SystemBus
().
get_object
(
'com.redhat.ifcfgrh1'
,
'/com/redhat/ifcfgrh1'
)
interface
=
dbus
.
Interface
(
obj
,
"com.redhat.ifcfgrh1"
)
path
=
'/etc/sysconfig/network-scripts/ifcfg-%s'
%
device
uuid
=
interface
.
GetIfcfgDetails
(
path
)[
0
]
return
uuid
except
:
return
None
pass
bus
=
dbus
.
SystemBus
()
nm_o
=
bus
.
get_object
(
"org.freedesktop.NetworkManager"
,
"/org/freedesktop/NetworkManager"
)
nm_i
=
dbus
.
Interface
(
nm_o
,
"org.freedesktop.DBus.Properties"
)
active
=
nm_i
.
Get
(
"org.freedesktop.NetworkManager"
,
"ActiveConnections"
)
for
active_path
in
active
:
print
active_path
active_o
=
bus
.
get_object
(
"org.freedesktop.NetworkManager"
,
active_path
)
active_i
=
dbus
.
Interface
(
active_o
,
"org.freedesktop.DBus.Properties"
)
conn_path
=
active_i
.
Get
(
"org.freedesktop.NetworkManager.Connection.Active"
,
"Connection"
)
conn_o
=
bus
.
get_object
(
"org.freedesktop.NetworkManager"
,
conn_path
)
conn_i
=
dbus
.
Interface
(
conn_o
,
"org.freedesktop.NetworkManager.Settings.Connection"
)
settings
=
conn_i
.
GetSettings
()
if
not
'id'
in
settings
[
'connection'
]:
continue
if
settings
[
'connection'
][
'id'
]
!=
device
:
continue
connection
=
settings
[
'connection'
]
if
'uuid'
in
connection
:
result
+=
'UUID=%s
\n
'
%
connection
[
'uuid'
]
if
'zone'
in
connection
:
result
+=
'ZONE=%s
\n
'
%
connection
[
'zone'
]
except
:
pass
return
result
def
interface_is_static
(
i
):
if
i
.
_static_
:
...
...
@@ -196,17 +222,13 @@ def generate(tree, host):
if
i
.
_parent
.
name
[
0
]
!=
host
or
not
device
(
i
.
ethernet
[
0
]):
continue
device_name
=
device
(
i
.
ethernet
[
0
])
get_uuid
(
device_name
)
if
i
.
bridge
[
0
]:
config
=
'DEVICE=%s
\n
'
%
i
.
bridge
[
0
]
config
+=
'NAME="%s"
\n
'
%
i
.
bridge
[
0
]
config
+=
'ONBOOT=yes
\n
'
config
+=
'TYPE=Bridge
\n
'
config
+=
'STP=off
\n
'
uuid
=
get_uuid
(
i
.
bridge
[
0
])
if
uuid
:
config
+=
'UUID=%s
\n
'
%
uuid
pass
config
+=
get_nm_extra
(
i
.
bridge
[
0
])
config
+=
generate_ifcfg
(
tree
,
i
)
result
.
append
((
'ifcfg-%s'
%
i
.
bridge
[
0
],
config
))
...
...
@@ -216,10 +238,7 @@ def generate(tree, host):
config
+=
'ONBOOT=yes
\n
'
config
+=
'TYPE=Ethernet
\n
'
config
+=
'BRIDGE=%s
\n
'
%
i
.
bridge
[
0
]
uuid
=
get_uuid
(
device_name
)
if
uuid
:
config
+=
'UUID=%s
\n
'
%
uuid
pass
config
+=
get_nm_extra
(
device_name
)
result
.
append
((
'ifcfg-%s'
%
device_name
,
config
))
pass
elif
i
.
ethernet
[
0
]:
...
...
@@ -228,10 +247,7 @@ def generate(tree, host):
config
+=
'HWADDR=%s
\n
'
%
i
.
ethernet
[
0
].
upper
()
config
+=
'ONBOOT=yes
\n
'
config
+=
'TYPE=Ethernet
\n
'
uuid
=
get_uuid
(
device_name
)
if
uuid
:
config
+=
'UUID=%s
\n
'
%
uuid
pass
config
+=
get_nm_extra
(
device_name
)
config
+=
generate_ifcfg
(
tree
,
i
)
result
.
append
((
'ifcfg-%s'
%
device_name
,
config
))
pass
...
...
Write
Preview
Supports
Markdown
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