Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HPCasCode
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
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
hpc-team
HPCasCode
Commits
bb0841d4
Commit
bb0841d4
authored
9 years ago
by
Shahaan Ayyub
Browse files
Options
Downloads
Patches
Plain Diff
Modified DynamicInventory
parent
797aef3c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dynamicInventory-mcc2
+14
-12
14 additions, 12 deletions
dynamicInventory-mcc2
with
14 additions
and
12 deletions
dynamicInventory-mcc2
+
14
−
12
View file @
bb0841d4
#!/usr/bin/env python
import
sys
,
os
,
string
,
socket
,
re
import
shlex
,
multiprocessing
,
time
,
shutil
,
json
import
novaclient
.v1_1.
client
as
nvclient
from
novaclient
import
client
as
nvclient
import
novaclient.exceptions
as
nvexceptions
import
keystoneclient.v2_0.client
as
ksclient
from
joblib
import
Parallel
,
delayed
from
multiprocessing
import
Process
,
Manager
,
Pool
from
libnmap.process
import
NmapProcess
from
libnmap.parser
import
NmapParser
,
NmapParserException
def
gatherInfo
(
tenantName
,
tenantID
,
userName
,
passwd
,
authUrl
,
inventory
):
## Fetch the Nova Object
projectName
=
os
.
path
.
basename
(
sys
.
argv
[
0
])
nc
=
nvclient
.
Client
(
auth_url
=
authUrl
,
...
...
@@ -16,25 +17,23 @@ def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
api_key
=
passwd
,
project_id
=
tenantName
,
tenant_id
=
tenantID
,
s
er
vice_type
=
"
compute
"
v
er
sion
=
"
2
"
)
for
server
in
nc
.
servers
.
list
():
if
server
.
metadata
and
\
'
ansible_host_groups
'
in
server
.
metadata
and
\
'
project_name
'
in
server
.
metadata
:
if
server
.
metadata
[
'
project_name
'
]
!=
projectName
.
strip
():
continue
if
server
.
metadata
[
'
project_name
'
]
.
strip
()
!=
projectName
.
strip
():
continue
unwantedChars
=
"""
][
"
)(
"""
rgx
=
re
.
compile
(
'
[%s]
'
%
unwantedChars
)
ansible_groups
=
rgx
.
sub
(
''
,
server
.
metadata
[
'
ansible_host_groups
'
]).
split
(
'
,
'
)
hostname
=
socket
.
gethostbyaddr
(
server
.
networks
.
values
()[
0
][
0
])[
0
]
closed
=
True
while
closed
:
hostSocket
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
if
not
hostSocket
.
connect_ex
((
hostname
,
22
)):
closed
=
False
break
time
.
sleep
(
5
)
hostSocket
.
close
()
novaVolumes
=
nc
.
volumes
.
get_server_volumes
(
server
.
id
)
# Let's do some port scanning using nmap
nmproc
=
NmapProcess
(
hostname
,
"
-p 22 -sV -Pn
"
)
rc
=
nmproc
.
run
()
if
rc
!=
0
:
continue
parsed
=
NmapParser
.
parse
(
nmproc
.
stdout
)
# Set Ansible Host Group
for
group
in
ansible_groups
:
groupName
=
group
.
strip
()
...
...
@@ -44,6 +43,9 @@ def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
for
key
,
value
in
server
.
metadata
.
iteritems
():
if
key
not
in
(
'
project_name
'
,
'
ansible_host_groups
'
):
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
]
=
{
key
:
value
}
if
novaVolumes
:
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
][
'
volumeList
'
]
=
[
volume
.
id
for
volume
in
novaVolumes
]
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
][
'
status
'
]
=
parsed
.
hosts
[
0
].
status
else
:
continue
#print inventory
...
...
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