Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
06f72ca3
Commit
06f72ca3
authored
Jul 08, 2014
by
James Cammarata
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'bug/8057' of
https://github.com/ericwb/ansible
into ericwb-bug/8057
parents
33cfdc4c
cdedb0f8
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
16 deletions
+28
-16
library/cloud/glance_image
+28
-16
No files found.
library/cloud/glance_image
View file @
06f72ca3
...
...
@@ -104,6 +104,12 @@ options:
- The path to the file which has to be uploaded, mutually exclusive with copy_from
required: false
default: None
endpoint_type:
description:
- endpoint URL type
choices: [publicURL, internalURL]
required: false
default: publicURL
requirements: ["glanceclient", "keystoneclient"]
'''
...
...
@@ -127,6 +133,7 @@ try:
except
ImportError
:
print
(
"failed=True msg='glanceclient and keystone client are required'"
)
def
_get_ksclient
(
module
,
kwargs
):
try
:
client
=
ksclient
.
Client
(
username
=
kwargs
.
get
(
'login_username'
),
...
...
@@ -134,30 +141,32 @@ def _get_ksclient(module, kwargs):
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error authenticating to the keystone:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error authenticating to the keystone:
%
s "
%
e
.
message
)
return
client
def
_get_endpoint
(
module
,
client
):
def
_get_endpoint
(
module
,
client
,
endpoint_type
):
try
:
endpoint
=
client
.
service_catalog
.
url_for
(
service_type
=
'image'
,
endpoint_type
=
'publicURL'
)
endpoint
=
client
.
service_catalog
.
url_for
(
service_type
=
'image'
,
endpoint_type
=
endpoint_type
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting endpoint for glance:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting endpoint for glance:
%
s"
%
e
.
message
)
return
endpoint
def
_get_glance_client
(
module
,
kwargs
):
_ksclient
=
_get_ksclient
(
module
,
kwargs
)
token
=
_ksclient
.
auth_token
endpoint
=
_get_endpoint
(
module
,
_ksclient
)
endpoint
=
_get_endpoint
(
module
,
_ksclient
,
kwargs
.
get
(
'endpoint_type'
)
)
kwargs
=
{
'token'
:
token
,
}
try
:
client
=
glanceclient
.
Client
(
'1'
,
endpoint
,
**
kwargs
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in connecting to glance:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in connecting to glance:
%
s"
%
e
.
message
)
return
client
def
_glance_image_present
(
module
,
params
,
client
):
try
:
for
image
in
client
.
images
.
list
():
...
...
@@ -165,7 +174,8 @@ def _glance_image_present(module, params, client):
return
image
.
id
return
None
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in fetching image list:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in fetching image list:
%
s"
%
e
.
message
)
def
_glance_image_create
(
module
,
params
,
client
):
kwargs
=
{
...
...
@@ -188,11 +198,12 @@ def _glance_image_create(module, params, client):
break
time
.
sleep
(
5
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in creating image:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in creating image:
%
s"
%
e
.
message
)
if
image
.
status
==
'active'
:
module
.
exit_json
(
changed
=
True
,
result
=
image
.
status
,
id
=
image
.
id
)
module
.
exit_json
(
changed
=
True
,
result
=
image
.
status
,
id
=
image
.
id
)
else
:
module
.
fail_json
(
msg
=
" The module timed out, please check manually "
+
image
.
status
)
module
.
fail_json
(
msg
=
" The module timed out, please check manually "
+
image
.
status
)
def
_glance_delete_image
(
module
,
params
,
client
):
try
:
...
...
@@ -200,8 +211,9 @@ def _glance_delete_image(module, params, client):
if
image
.
name
==
params
[
'name'
]:
client
.
images
.
delete
(
image
)
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in deleting image:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
"Deleted"
)
module
.
fail_json
(
msg
=
"Error in deleting image:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
"Deleted"
)
def
main
():
...
...
@@ -222,28 +234,28 @@ def main():
copy_from
=
dict
(
default
=
None
),
timeout
=
dict
(
default
=
180
),
file
=
dict
(
default
=
None
),
endpoint_type
=
dict
(
default
=
'publicURL'
,
choices
=
[
'publicURL'
,
'internalURL'
]),
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
])
),
mutually_exclusive
=
[[
'file'
,
'copy_from'
]],
)
if
module
.
params
[
'state'
]
==
'present'
:
if
not
module
.
params
[
'file'
]
and
not
module
.
params
[
'copy_from'
]:
module
.
fail_json
(
msg
=
"Either file or copy_from variable should be set to create the image"
)
module
.
fail_json
(
msg
=
"Either file or copy_from variable should be set to create the image"
)
client
=
_get_glance_client
(
module
,
module
.
params
)
id
=
_glance_image_present
(
module
,
module
.
params
,
client
)
if
not
id
:
_glance_image_create
(
module
,
module
.
params
,
client
)
module
.
exit_json
(
changed
=
False
,
id
=
id
,
result
=
"success"
)
module
.
exit_json
(
changed
=
False
,
id
=
id
,
result
=
"success"
)
if
module
.
params
[
'state'
]
==
'absent'
:
client
=
_get_glance_client
(
module
,
module
.
params
)
id
=
_glance_image_present
(
module
,
module
.
params
,
client
)
if
not
id
:
module
.
exit_json
(
changed
=
False
,
result
=
"Success"
)
module
.
exit_json
(
changed
=
False
,
result
=
"Success"
)
else
:
_glance_delete_image
(
module
,
module
.
params
,
client
)
# this is magic, see lib/ansible/module.params['common.py
from
ansible.module_utils.basic
import
*
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