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
ae271078
Commit
ae271078
authored
8 years ago
by
Anders Blomdell
Browse files
Options
Downloads
Patches
Plain Diff
Add TTL support for individual named/BIND records
parent
8867ff1b
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/hostinfo/named.py
+27
-24
27 additions, 24 deletions
src/hostinfo/named.py
with
27 additions
and
24 deletions
src/hostinfo/named.py
+
27
−
24
View file @
ae271078
...
...
@@ -139,22 +139,24 @@ class DomainDict:
self
.
host
=
{}
pass
def
add_host
(
self
,
name
,
kind
,
value
):
def
add_host
(
self
,
name
,
ttl
,
kind
,
value
):
if
not
re
.
match
(
'
^[0-9a-zA-Z.-]+$
'
,
name
):
raise
Exception
(
'
Invalid host name
"
%s
"'
%
name
)
if
not
name
in
self
.
host
:
self
.
host
[
name
]
=
set
()
pass
self
.
host
[
name
].
add
((
kind
,
value
))
if
not
ttl
:
ttl
=
''
self
.
host
[
name
].
add
((
kind
,
value
,
ttl
))
pass
def
value
(
self
,
cmp
=
None
):
result
=
util
.
StringArray
()
result
+=
self
.
header
for
name
in
sorted
(
self
.
host
,
cmp
):
for
kind
,
value
in
sorted
(
self
.
host
[
name
]):
result
+=
(
'
%(name)-18s
IN
%(kind)-7s %(value)s
'
%
dict
(
name
=
name
,
kind
=
kind
,
value
=
value
))
for
kind
,
value
,
ttl
in
sorted
(
self
.
host
[
name
]):
result
+=
(
'
%(name)-18s
%(ttl)-8s IN
%(kind)-7s %(value)s
'
%
dict
(
name
=
name
,
ttl
=
ttl
,
kind
=
kind
,
value
=
value
))
pass
pass
return
result
...
...
@@ -185,8 +187,9 @@ def generate_forward(tree, hosts):
for
mx
in
[
m
for
m
in
tree
.
_host_
.
_interface_
.
_mailhost_
if
m
.
domain
[
0
]
==
domain
]:
pri
=
int
(
mx
.
priority
[
0
]
or
0
)
result
+=
(
'
IN MX %d %s
'
%
(
pri
,
util
.
fqn
(
tree
,
mx
.
_parent
)))
ttl
=
mx
.
ttl
[
0
]
or
''
result
+=
(
'
%-8s IN MX %d %s
'
%
(
ttl
,
pri
,
util
.
fqn
(
tree
,
mx
.
_parent
)))
pass
for
txt
in
[
t
for
t
in
tree
.
_subnet_
.
_txt_
if
t
.
domain
[
1
]
==
domain
]:
result
+=
(
'
IN TXT
"
%s
"'
%
(
txt
.
value
[
0
]))
...
...
@@ -200,31 +203,31 @@ def generate_forward(tree, hosts):
# Add cname hosts
for
c
in
tree
.
_subnet_
.
_cname_
:
result
[
c
.
domain
[
1
]].
add_host
(
c
.
alias
[
0
],
'
CNAME
'
,
c
.
name
[
0
])
result
[
c
.
domain
[
1
]].
add_host
(
c
.
alias
[
0
],
c
.
ttl
[
0
],
'
CNAME
'
,
c
.
name
[
0
])
pass
# Add numbered hosts
def
add_host
(
domain
,
name
,
address
):
def
add_host
(
domain
,
name
,
ttl
,
address
):
if
address
.
version
==
4
:
result
[
domain
].
add_host
(
name
,
'
A
'
,
str
(
address
.
exploded
))
result
[
domain
].
add_host
(
name
,
ttl
,
'
A
'
,
str
(
address
.
exploded
))
pass
elif
address
.
version
==
6
:
result
[
domain
].
add_host
(
name
,
'
AAAA
'
,
str
(
address
.
exploded
))
result
[
domain
].
add_host
(
name
,
ttl
,
'
AAAA
'
,
str
(
address
.
exploded
))
pass
for
domain
,
net
in
[
(
s
.
domain
[
0
],
util
.
network
(
s
))
for
s
in
tree
.
_subnet_
if
s
.
domain
[
0
]
and
util
.
network
(
s
)]:
for
name
,
address
in
hosts
:
for
name
,
address
,
ttl
in
hosts
:
try
:
if
name
.
endswith
(
'
.
'
):
d
=
'
.
'
.
join
(
name
.
split
(
'
.
'
)[
1
:
-
1
])
n
=
name
.
split
(
'
.
'
)[
0
]
add_host
(
d
,
n
,
address
)
add_host
(
d
,
n
,
ttl
,
address
)
continue
except
Exception
,
e
:
pass
if
address
in
net
:
add_host
(
domain
,
name
,
address
)
add_host
(
domain
,
name
,
ttl
,
address
)
pass
pass
pass
...
...
@@ -247,14 +250,14 @@ def generate_reverse(tree, hosts):
for
net
in
net_to_origin
:
origin
=
net_to_origin
[
net
]
domain
=
origin_to_domain
[
origin
]
for
name
,
address
in
hosts
:
for
name
,
address
,
ttl
in
hosts
:
if
address
in
net
:
reverse
=
reverse_addr
(
address
).
replace
(
'
.%s
'
%
origin
,
''
)
fqn
=
name
if
fqn
[
-
1
]
!=
'
.
'
:
fqn
+=
'
.
'
+
domain
+
'
.
'
pass
result
[
origin
].
add_host
(
reverse
,
'
PTR
'
,
fqn
)
result
[
origin
].
add_host
(
reverse
,
ttl
,
'
PTR
'
,
fqn
)
pass
pass
pass
...
...
@@ -267,7 +270,7 @@ def generate_reverse(tree, hosts):
def
get_hosts
(
tree
,
with_alias
=
True
):
result
=
[]
seen
=
{}
def
add
(
name
,
address
,
check
=
None
):
def
add
(
name
,
address
,
ttl
,
check
=
None
):
if
check
and
address
in
seen
:
old_name
=
seen
[
address
][
0
]
old_check
=
seen
[
address
][
1
]
...
...
@@ -277,14 +280,14 @@ def get_hosts(tree, with_alias=True):
where
=
[
old_check
,
check
])
pass
seen
[
address
]
=
(
name
,
check
)
result
.
append
((
name
,
address
))
result
.
append
((
name
,
address
,
ttl
))
pass
# IPv4 static addresses
for
i
in
filter
(
util
.
address
,
tree
.
_host_
.
_interface_
.
_ip_
):
add
(
i
.
name
[
0
:],
util
.
address
(
i
),
check
=
i
)
add
(
i
.
name
[
0
:],
util
.
address
(
i
),
i
.
ttl
[
0
:
2
],
check
=
i
)
if
with_alias
:
for
a
in
i
.
_alias_
:
add
(
a
.
name
[
0
:],
util
.
address
(
i
))
add
(
a
.
name
[
0
:],
util
.
address
(
i
)
,
a
.
ttl
[
0
:
3
]
)
pass
pass
pass
...
...
@@ -295,17 +298,17 @@ def get_hosts(tree, with_alias=True):
a
=
util
.
address
(
d
.
first
[
0
])
while
a
<=
last
:
name
=
'
-
'
.
join
([
'
dynamic
'
]
+
a
.
exploded
.
split
(
'
.
'
))
add
(
name
,
a
,
check
=
d
)
add
(
name
,
a
,
d
.
ttl
[
0
],
check
=
d
)
a
=
a
+
1
pass
pass
# IPv6 static addresses
for
i
in
filter
(
util
.
address
,
tree
.
_host_
.
_interface_
.
_ipv6_
):
add
(
i
.
name
[
0
:],
util
.
address
(
i
),
check
=
i
)
add
(
i
.
name
[
0
:],
util
.
address
(
i
),
i
.
ttl
[
0
:
2
],
check
=
i
)
if
with_alias
:
for
a
in
i
.
_alias_
:
add
(
a
.
name
[
0
:],
util
.
address
(
i
))
add
(
a
.
name
[
0
:],
util
.
address
(
i
)
,
a
.
ttl
[
0
:
3
]
)
pass
pass
pass
...
...
@@ -316,7 +319,7 @@ def get_hosts(tree, with_alias=True):
a
=
util
.
address
(
d
.
first
[
0
])
while
a
<=
last
:
name
=
'
-
'
.
join
([
'
dynamic
'
]
+
a
.
exploded
.
split
(
'
:
'
))
add
(
name
,
a
,
check
=
d
)
add
(
name
,
a
,
d
.
ttl
[
0
],
check
=
d
)
a
=
a
+
1
pass
pass
...
...
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