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
064e1825
Commit
064e1825
authored
17 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Version 2008-06-16 19:22
M src/hostinfo/dhcpd.py
parent
0f1cddee
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/dhcpd.py
+125
-88
125 additions, 88 deletions
src/hostinfo/dhcpd.py
with
125 additions
and
88 deletions
src/hostinfo/dhcpd.py
+
125
−
88
View file @
064e1825
...
...
@@ -48,44 +48,79 @@ class "AppleNBI-ppc" {
def
conf
(
tree
,
dhcphost
):
#
# A.
Check if host is a dhcp
serve
r
# A.
Get interfaces to
serve
#
emit
=
False
interface
=
[]
for
ds
in
tree
.
_host_
.
_interface_
.
_dhcpserver_
:
if
dhcphost
in
ds
.
name
[
0
::
1
]:
# Given host is a dhcpserver
dhcphost
=
ds
.
name
[
0
:]
# Host is dhcpserver for this interface
dhcpip
=
ds
.
ip
[
0
:]
emit
=
True
if
not
emit
:
interface
.
append
(
ds
.
_parent
)
if
not
interface
:
raise
Exception
(
"
%s is not a dhcpserver
"
%
dhcphost
)
#
# B. Emit header
#
result
=
"
ddns-update-style none;
\n
"
result
+=
"
authoritative;
\n
"
result
+=
MacOS_NETBOOT
(
dhcpip
)
#
# C. Emit subnet declarations for each interface
#
for
i
in
interface
:
address
=
[]
if
i
.
ip
[
0
]:
# Main address
address
.
append
(
i
.
ip
[
0
])
for
ip
in
i
.
_ip_
:
# Alias addresses
if
ip
.
address
[
0
]:
address
.
append
(
ip
.
address
[
0
])
# Collect subnets for this interface
network
=
{}
for
n
in
tree
.
_subnet_
:
if
not
n
.
network
[
0
]:
continue
netmask
=
aton
(
n
.
netmask
[
0
])
subnet
=
aton
(
n
.
network
[
0
])
&
netmask
for
a
in
address
:
if
aton
(
a
)
&
netmask
==
subnet
:
network
[
ntoa
(
subnet
)]
=
n
# Emit subnet declarations
if
len
(
network
.
keys
())
>
1
:
# Multiple networks served on this interface
result
+=
'
shared-network
"
MAC(%s)
"
{
\n\n
'
%
i
.
ethernet
[
0
]
for
n
in
network
.
values
():
for
l
in
emit_subnet
(
tree
,
n
,
dhcphost
).
split
(
"
\n
"
):
result
+=
"
%s
\n
"
%
l
result
+=
"
}
\n
"
else
:
result
+=
emit_subnet
(
tree
,
network
.
values
()[
0
],
dhcphost
)
return
result
def
emit_subnet
(
tree
,
n
,
dhcphost
):
result
=
""
netmask
=
aton
(
n
.
netmask
[
0
])
subnet
=
aton
(
n
.
network
[
0
])
&
netmask
static
=
{}
dynamic
=
{}
emit
=
None
for
i
in
tree
.
_host_
.
_interface_
:
# Find all hosts that belong to this network
if
i
.
ip
[
0
]:
net
=
aton
(
i
.
ip
[
0
])
&
netmask
if
net
==
subnet
:
if
i
.
name
[
0
:]
==
dhcphost
:
emit
=
i
.
_dhcpserver_
if
i
.
dynamic
[
0
]
==
dhcphost
:
# Dynamic address served by this host
dynamic
[
aton
(
i
.
ip
[
0
])]
=
i
else
:
static
[
i
.
name
[
0
:]]
=
i
if
not
emit
:
continue
result
+=
"
subnet %s netmask %s {
\n
"
%
(
n
.
network
[
0
],
n
.
netmask
[
0
])
result
+=
"
option subnet-mask %s;
\n
"
%
n
.
netmask
[
0
]
...
...
@@ -96,7 +131,8 @@ def conf(tree, dhcphost):
if
n
.
domain
[
0
]:
result
+=
"
option domain-name
\"
%s
\"
;
\n
"
%
n
.
domain
[
0
]
if
n
.
name_servers
[
0
]:
result
+=
"
option domain-name-servers %s;
\n
"
%
n
.
name_servers
[
0
]
result
+=
"
option domain-name-servers %s;
\n
"
%
(
n
.
name_servers
[
0
])
#
# Emit dynamic hosts
...
...
@@ -148,5 +184,6 @@ def conf(tree, dhcphost):
result
+=
"
}
\n
"
result
+=
"
}
\n\n
"
result
+=
"
}
\n
"
return
result
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