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
09959fb2
Commit
09959fb2
authored
10 years ago
by
Shahaan Ayyub
Browse files
Options
Downloads
Patches
Plain Diff
New Dynamic Inventory from Chris
parent
3a2a2650
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dynamicInventory
+0
-50
0 additions, 50 deletions
dynamicInventory
with
0 additions
and
50 deletions
dynamicInventory
deleted
100755 → 0
+
0
−
50
View file @
3a2a2650
#!/usr/bin/env python
import
sys
,
os
,
string
,
subprocess
,
socket
,
re
import
copy
,
shlex
,
uuid
,
random
,
multiprocessing
,
time
,
shutil
,
json
import
novaclient.v1_1.client
as
nvclient
import
novaclient.exceptions
as
nvexceptions
class
Authenticate
:
def
__init__
(
self
,
username
,
passwd
):
self
.
username
=
username
self
.
passwd
=
passwd
self
.
tenantName
=
os
.
environ
[
'
OS_TENANT_NAME
'
]
self
.
tenantID
=
os
.
environ
[
'
OS_TENANT_ID
'
]
self
.
authUrl
=
"
https://keystone.rc.nectar.org.au:5000/v2.0
"
def
gatherInfo
(
self
):
## Fetch the Nova Object
nc
=
nvclient
.
Client
(
auth_url
=
self
.
authUrl
,
username
=
self
.
username
,
api_key
=
self
.
passwd
,
project_id
=
self
.
tenantName
,
tenant_id
=
self
.
tenantID
,
service_type
=
"
compute
"
)
inventory
=
{}
inventory
[
'
_meta
'
]
=
{
'
hostvars
'
:
{}
}
for
server
in
nc
.
servers
.
list
():
if
server
.
metadata
:
hostname
=
socket
.
gethostbyaddr
(
server
.
networks
.
values
()[
0
][
0
])[
0
]
# Set Ansible Host Group
if
server
.
metadata
[
'
ansible_host_group
'
]
in
inventory
:
inventory
[
server
.
metadata
[
'
ansible_host_group
'
]].
append
(
hostname
)
else
:
inventory
[
server
.
metadata
[
'
ansible_host_group
'
]]
=
[
hostname
]
# Set the other host variables
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
]
=
{}
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
][
'
ansible_ssh_user
'
]
=
server
.
metadata
[
'
ansible_ssh_user
'
]
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
][
'
ansible_ssh_private_key_file
'
]
=
server
.
metadata
[
'
ansible_ssh_private_key_file
'
]
else
:
continue
print
json
.
dumps
(
inventory
)
if
__name__
==
"
__main__
"
:
username
=
os
.
environ
[
'
OS_USERNAME
'
]
passwd
=
os
.
environ
[
'
OS_PASSWORD
'
]
auth
=
Authenticate
(
username
,
passwd
)
auth
.
gatherInfo
()
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