Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Ansible
Manage
Activity
Members
Labels
Plan
Issues
3
Issue boards
Milestones
Code
Merge requests
2
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nounous
Ansible
Commits
c2ffc73c
Commit
c2ffc73c
authored
4 years ago
by
Benjamin Graillot
Browse files
Options
Downloads
Patches
Plain Diff
[ldap] Add function to list used ipv4 on a subnet
parent
88407618
No related branches found
Branches containing commit
No related tags found
1 merge request
!54
[ldap] Add function to list used ipv4 on a subnet
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lookup_plugins/ldap.py
+17
-0
17 additions, 0 deletions
lookup_plugins/ldap.py
with
17 additions
and
0 deletions
lookup_plugins/ldap.py
+
17
−
0
View file @
c2ffc73c
...
...
@@ -52,11 +52,28 @@ class LookupModule(LookupBase):
result
=
[
res
.
decode
(
'
utf-8
'
)
for
res
in
result
[
'
ipHostNumber
'
]]
return
result
def
subnet_ipv4
(
self
,
subnet
):
"""
Retrive used IP addresses on a subnet
query(
'
ldap
'
,
'
subnet_ipv4
'
, SUBNET)
"""
network_query_id
=
self
.
base
.
search
(
f
"
cn=
{
subnet
}
,ou=networks,
{
self
.
base_dn
}
"
,
ldap
.
SCOPE_BASE
)
network_result
=
self
.
base
.
result
(
network_query_id
)
network
=
network_result
[
1
][
0
][
1
]
network
,
hostmask
=
network
[
'
ipNetworkNumber
'
][
0
].
decode
(
'
utf-8
'
),
network
[
'
ipNetmaskNumber
'
][
0
].
decode
(
'
utf-8
'
)
subnet
=
ipaddress
.
IPv4Network
(
f
"
{
network
}
/
{
hostmask
}
"
)
query_id
=
self
.
base
.
search
(
f
"
ou=hosts,
{
self
.
base_dn
}
"
,
ldap
.
SCOPE_SUBTREE
,
"
objectClass=ipHost
"
)
result
=
self
.
base
.
result
(
query_id
)
result
=
[
ip
.
decode
(
'
utf-8
'
)
for
dn
,
entry
in
result
[
1
]
for
ip
in
entry
[
'
ipHostNumber
'
]
if
ipaddress
.
ip_address
(
ip
.
decode
(
'
utf-8
'
))
in
subnet
]
return
result
def
run
(
self
,
terms
,
variables
=
None
,
**
kwargs
):
if
terms
[
0
]
==
'
query
'
:
result
=
self
.
query
(
*
terms
[
1
:])
elif
terms
[
0
]
==
'
ip
'
:
result
=
self
.
ip
(
*
terms
[
1
:])
elif
terms
[
0
]
==
'
subnet_ipv4
'
:
result
=
self
.
subnet_ipv4
(
*
terms
[
1
:])
elif
terms
[
0
]
==
'
group
'
:
query_id
=
self
.
base
.
search
(
f
"
ou=group,
{
self
.
base_dn
}
"
,
ldap
.
SCOPE_SUBTREE
,
"
objectClass=posixGroup
"
)
result
=
self
.
base
.
result
(
query_id
)
...
...
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