Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hostinfo
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Redmine
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Anders Blomdell
hostinfo
Commits
27479691
Commit
27479691
authored
9 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Added possibility to have DHCP and static addresses
parent
57581457
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/hostinfo/ifconfig.py
+52
-40
52 additions, 40 deletions
src/hostinfo/ifconfig.py
with
52 additions
and
40 deletions
src/hostinfo/ifconfig.py
+
52
−
40
View file @
27479691
...
...
@@ -17,25 +17,36 @@ def get_uuid(device):
pass
def
is_static
(
i
nterface
):
if
i
nterface
.
_static_
:
def
interface_
is_static
(
i
):
if
i
.
_static_
:
return
True
if
i
nterface
.
_ip_
.
_dhcpserver_
:
if
i
.
_ip_
.
_dhcpserver_
:
return
True
if
interface
.
_ipv6_
.
_dhcpserver_
:
if
i
.
_ipv6_
.
_dhcpserver_
:
return
True
return
False
def
address_is_static
(
a
):
if
interface_is_static
(
a
.
_parent
):
return
True
if
a
.
static
[
0
]
!=
None
and
a
.
static
[
0
].
lower
()
in
[
'
yes
'
,
'
1
'
]:
return
True
return
False
def
generate_ifcfgv4
(
tree
,
interface
,
search
,
nameservers
):
config
=
[]
if
not
is_static
(
interface
):
if
not
interface_
is_static
(
interface
):
config
.
append
(
'
BOOTPROTO=dhcp
'
)
pass
else
:
config
.
append
(
'
BOOTPROTO=none
'
)
pass
index
=
''
for
ip
in
filter
(
util
.
address
,
interface
.
_ip_
):
if
not
address_is_static
(
ip
):
continue
a
=
util
.
address
(
ip
)
netmask
=
None
network
=
None
...
...
@@ -48,6 +59,7 @@ def generate_ifcfgv4(tree, interface, search, nameservers):
network
=
n
.
network
broadcast
=
n
.
broadcast
gateway
=
s
.
gateway
[
0
]
if
interface_is_static
(
interface
):
if
s
.
name_servers
[
0
]:
nameservers
.
extend
(
re
.
split
(
'
[, ]+
'
,
s
.
name_servers
[
0
]))
pass
...
...
@@ -56,6 +68,7 @@ def generate_ifcfgv4(tree, interface, search, nameservers):
pass
pass
pass
pass
if
ip
.
netmask
[
0
]:
netmask
=
ip
.
netmask
[
0
]
if
ip
.
network
[
0
]:
network
=
ip
.
network
[
0
]
if
ip
.
broadcast
[
0
]:
broadcast
=
ip
.
broadcast
[
0
]
...
...
@@ -76,13 +89,12 @@ def generate_ifcfgv4(tree, interface, search, nameservers):
pass
index
=
int
(
'
0%s
'
%
index
)
+
1
pass
pass
return
config
def
generate_ifcfgv6
(
tree
,
interface
,
search
,
nameservers
):
config
=
[]
if
not
is_static
(
interface
):
if
not
interface_
is_static
(
interface
):
config
.
append
(
'
IPV6INIT=yes
'
)
config
.
append
(
'
IPV6_AUTOCONF=yes
'
)
config
.
append
(
'
IPV6_DEFROUTE=yes
'
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment