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
3f552d10
Commit
3f552d10
authored
3 months ago
by
OskarStenberg
Browse files
Options
Downloads
Patches
Plain Diff
Enforce non-empty hostnames, get fqdn and base fqdn on ip name-tag if applicable
parent
fc4f1175
Branches
Branches containing commit
No related tags found
1 merge request
!4
Added option --nettools FILE to generate bulk upload CSV for nettools
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/hostinfo/nettools.py
+24
-18
24 additions, 18 deletions
src/hostinfo/nettools.py
with
24 additions
and
18 deletions
src/hostinfo/nettools.py
+
24
−
18
View file @
3f552d10
import
sys
import
os
import
datetime
import
hostinfo.util
as
util
# File syntax is according to nettools manual:
# IP-adress;hostnamn;kommasepareradeMAC-adresser;DHCP-grupp;LucatID;kommentar
...
...
@@ -36,7 +35,8 @@ def generate_row_tup(host):
h
=
list
(
host
)
# Ensure proper length of tuple to unpack
h
=
h
+
[
""
]
*
(
6
-
len
(
h
))
ip
,
hostname
,
maclist
,
dhcp_group
,
owner
,
comment
=
h
ip
,
hostname
,
maclist
,
dhcp_group
,
owner
,
_
=
h
comment
=
datetime
.
datetime
.
now
().
isoformat
(
timespec
=
'
seconds
'
)
return
generate_row
(
ip
,
hostname
,
maclist
,
dhcp_group
,
owner
,
comment
)
def
filter_nets
(
tree
,
options
,
ip
):
...
...
@@ -51,8 +51,16 @@ def emit_hosts(tree, options):
for
iface
in
tree
.
_host_
.
_interface_
:
for
ip
in
iface
.
_ip_
:
if
ip
and
ip
.
address
[
0
]:
try
:
fqdn
=
util
.
fqn
(
iface
,
tree
)[
0
:
-
1
]
if
ip
.
name
[
0
]:
parts
=
fqdn
.
split
(
'
.
'
)
parts
[
0
]
=
ip
.
name
[
0
]
fqdn
=
'
.
'
.
join
(
parts
)
except
:
fqdn
=
iface
.
name
[
1
]
+
"
.control.lth.se
"
result
.
append
((
ip
.
address
[
0
],
iface
.
name
[
1
]
,
fqdn
,
[
iface
.
ethernet
[
0
]
or
""
]))
pass
pass
...
...
@@ -68,20 +76,18 @@ def subnet_hosts(tree, options):
def
generate
(
tree
,
options
):
hosts
=
emit_hosts
(
tree
,
options
)
expected_hosts
=
subnet_hosts
(
tree
,
options
)
for
eh
in
expected_hosts
:
exists
=
False
for
h
in
hosts
:
if
h
[
0
]
==
eh
:
exists
=
True
break
pass
if
not
exists
:
hosts
.
append
((
eh
,
""
))
#print("Appended", eh)
pass
pass
#expected_hosts = subnet_hosts(tree, options)
#for eh in expected_hosts:
# exists = False
# for h in hosts:
# if h[0] == eh:
# exists = True
# break
# pass
# if not exists:
# hosts.append((eh, ""))
# pass
# pass
hosts
.
sort
(
key
=
lambda
e
:
[
int
(
v
)
for
v
in
e
[
0
].
split
(
'
.
'
)])
output
=
[]
...
...
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