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
7da69d7e
Commit
7da69d7e
authored
9 years ago
by
Chris Hines
Browse files
Options
Downloads
Patches
Plain Diff
dynamic inventory to list cinder voluesm in the metadata
parent
dd460625
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
+37
-20
37 additions, 20 deletions
dynamicInventory
with
37 additions
and
20 deletions
dynamicInventory
+
37
−
20
View file @
7da69d7e
#!/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
#
import novaclient.v1_1.client as nvclient
#
import novaclient.exceptions as nvexceptions
from
keystoneclient.auth.identity
import
v2
as
v2_auth
from
heatclient
import
client
as
heat_client
#from heatclient import client as heat_client
#from novaclient import client as nova_client
#from cinderclient import client as cinder_client
import
heatclient
import
novaclient
import
cinderclient
import
heatclient.client
import
novaclient.client
import
cinderclient.client
from
keystoneclient
import
session
as
kssession
...
...
@@ -108,13 +116,13 @@ class OpenStackConnection:
raise
Exception
(
"
You have multiple heat stacks in your OpenStack Project and I
'
m not sure which one to use.
\n
You can select a stack by symlinking to a stack, for example if you have a stack called mycluster do ln -s %s mycluster
\n
"
%
stack
)
def
auth
(
self
):
self
.
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
"
)
#
self.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"
#
)
kwargs
=
{
'
insecure
'
:
False
,
}
...
...
@@ -131,23 +139,28 @@ class OpenStackConnection:
self
.
authUrl
,
**
kwargs
)
endpoint
=
keystone_auth
.
get_endpoint
(
keystone_session
,
service_type
=
'
orchestration
'
,
region_name
=
None
)
endpoint
=
keystone_auth
.
get_endpoint
(
keystone_session
,
service_type
=
'
compute
'
,
region_name
=
None
)
kwargs
=
{
'
auth
'
:
keystone_auth
,
}
api_version
=
'
2
'
self
.
nc
=
novaclient
.
client
.
Client
(
api_version
,
endpoint
,
**
kwargs
)
endpoint
=
keystone_auth
.
get_endpoint
(
keystone_session
,
service_type
=
'
orchestration
'
,
region_name
=
None
)
kwargs
=
{
'
username
'
:
self
.
username
,
'
include_pass
'
:
False
,
'
session
'
:
keystone_session
,
'
auth_url
'
:
self
.
authUrl
,
'
region_name
'
:
''
,
'
endpoint_type
'
:
'
publicURL
'
,
'
service_type
'
:
'
orchestration
'
,
'
password
'
:
self
.
passwd
,
'
auth
'
:
keystone_auth
,
}
api_version
=
1
self
.
hc
=
heatclient
.
client
.
Client
(
api_version
,
endpoint
,
**
kwargs
)
self
.
hc
=
heat_client
.
Client
(
api_version
,
endpoint
,
**
kwargs
)
endpoint
=
keystone_auth
.
get_endpoint
(
keystone_session
,
service_type
=
'
volume
'
,
region_name
=
None
)
kwargs
=
{
# 'session': keystone_session,
'
auth
'
:
keystone_auth
,
}
api_version
=
1
self
.
cc
=
cinderclient
.
client
.
Client
(
api_version
,
endpoint
,
**
kwargs
)
def
recurse_resources
(
self
,
stack
,
resource
):
...
...
@@ -170,6 +183,7 @@ class OpenStackConnection:
instance_ids
.
extend
(
self
.
recurse_resources
(
stack
=
i
,
resource
=
r
))
nc
=
self
.
nc
# cc=self.cc
inventory
=
{}
inventory
[
'
_meta
'
]
=
{
'
hostvars
'
:
{}
}
for
server
in
nc
.
servers
.
list
():
...
...
@@ -190,6 +204,9 @@ class OpenStackConnection:
inventory
[
server
.
metadata
[
'
ansible_host_group
'
]].
append
(
hostname
)
else
:
inventory
[
server
.
metadata
[
'
ansible_host_group
'
]]
=
[
hostname
]
#print dir(server)
if
len
(
server
.
to_dict
()[
'
os-extended-volumes:volumes_attached
'
])
>
0
:
pass
# Set the other host variables
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
]
=
{}
inventory
[
'
_meta
'
][
'
hostvars
'
][
hostname
][
'
ansible_ssh_host
'
]
=
server
.
networks
.
values
()[
0
][
0
]
...
...
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