Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
verktoy
kindnavsync
Commits
34d9fbcd
Commit
34d9fbcd
authored
Aug 21, 2018
by
Morten Brekkevold
Browse files
Silence many messages about devices that aren't in production, according to Kind
parent
3c5b21ce
Changes
1
Hide whitespace changes
Inline
Side-by-side
bin/kindnavsync
View file @
34d9fbcd
...
...
@@ -184,21 +184,28 @@ def clean_data(kind_data):
invalid_names
=
{
device
for
device
in
kind_devices
if
not
device_name_is_okay
(
device
.
name
)}
if
invalid_names
:
if
production_devices_by_name
(
invalid_names
)
:
LOG
.
error
(
"Ignorerer følgende utstyr som ikke har gyldige navn i Kind:"
"
\n
%s"
,
sorted
(
invalid_names
,
key
=
attrgetter
(
'name'
)))
"
\n
%s"
,
production_devices_by_name
(
invalid_names
))
for
device
in
invalid_names
:
device
.
ignore_insert
=
True
no_nettinstallasjon
=
{
device
for
device
in
kind_devices
if
not
device
.
room
}
if
no_nettinstallasjon
:
if
not
device
.
room
and
not
device
.
ignore_insert
}
if
production_devices_by_name
(
no_nettinstallasjon
)
:
LOG
.
error
(
"Ignorerer følgende utstyr som ikke har nettinstallasjon "
"satt i Kind:
\n
%s"
,
sorted
(
no_nettinstallasjon
,
key
=
attrgetter
(
'name'
)
))
production_devices_by_name
(
no_nettinstallasjon
))
return
{
device
.
name
:
device
for
device
in
kind_devices
if
device
not
in
(
invalid_names
|
no_nettinstallasjon
)}
def
production_devices_by_name
(
kind_devices
):
return
sorted
((
dev
for
dev
in
kind_devices
if
dev
.
is_in_production
()),
key
=
attrgetter
(
'name'
))
def
device_name_is_okay
(
name
):
return
'.'
in
name
and
' '
not
in
name
...
...
@@ -230,9 +237,9 @@ def lookup_addresses(kind_devices):
else
:
kind_device
.
loopback
=
addrs
[
0
]
if
with_missing_dns
:
if
production_devices_by_name
(
with_missing_dns
)
:
LOG
.
error
(
"Ignorerer utstyr som mangler DNS-innslag:
\n
%s"
,
with_missing_dns
)
production_devices_by_name
(
with_missing_dns
)
)
def
lookup_dns
(
names
):
...
...
@@ -453,12 +460,13 @@ def can_be_deleted(netbox):
class
KindDevice
(
object
):
def
__init__
(
self
,
id
,
name
,
serial
,
room
,
type
):
def
__init__
(
self
,
id
,
name
,
serial
,
room
,
type
,
status
=
None
):
self
.
id
=
id
self
.
name
=
name
self
.
serial
=
serial
self
.
room
=
room
self
.
type
=
type
self
.
status
=
status
self
.
loopback
=
None
self
.
ipaddrs
=
set
()
...
...
@@ -473,6 +481,7 @@ class KindDevice(object):
record
.
get
(
'serienummer'
,
None
),
record
.
get
(
'nettinstallasjon'
,
None
),
record
.
get
(
'type'
,
None
),
status
=
record
.
get
(
'status_tekst'
,
None
),
)
def
__repr__
(
self
):
...
...
@@ -491,6 +500,9 @@ class KindDevice(object):
if
self
.
id
:
return
KIND_UTSTYR_URL
.
format
(
id
=
self
.
id
)
def
is_in_production
(
self
):
return
self
.
status
==
"Installert"
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
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