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
66cad764
Commit
66cad764
authored
Dec 13, 2013
by
jctanner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5028 from retr0h/correct-nova-api-auth-check
Nova doesn't attempt to auth on obj instantiation
parents
53c5b1d9
15613de6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
21 deletions
+36
-21
library/cloud/nova_compute
+22
-16
library/cloud/nova_keypair
+14
-5
No files found.
library/cloud/nova_compute
View file @
66cad764
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#coding: utf-8 -*-
#coding: utf-8 -*-
# (c) 2013, Benno Joy <benno@ansibleworks.com>
# (c) 2013, Benno Joy <benno@ansibleworks.com>
# (c) 2013, John Dewey <john@dewey.ws>
#
#
# This module is free software: you can redistribute it and/or modify
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# it under the terms of the GNU General Public License as published by
...
@@ -18,6 +19,7 @@
...
@@ -18,6 +19,7 @@
try
:
try
:
from
novaclient.v1_1
import
client
as
nova_client
from
novaclient.v1_1
import
client
as
nova_client
from
novaclient
import
exceptions
import
time
import
time
except
ImportError
:
except
ImportError
:
print
(
"failed=True msg='novaclient is required for this module'"
)
print
(
"failed=True msg='novaclient is required for this module'"
)
...
@@ -87,7 +89,7 @@ options:
...
@@ -87,7 +89,7 @@ options:
default: None
default: None
nics:
nics:
description:
description:
- A list of network id's to which the VM's interface should be attached
- A list of network id's to which the VM's interface should be attached
required: false
required: false
default: None
default: None
meta:
meta:
...
@@ -177,7 +179,7 @@ def _create_server(module, nova):
...
@@ -177,7 +179,7 @@ def _create_server(module, nova):
if
server
.
status
==
'ERROR'
:
if
server
.
status
==
'ERROR'
:
module
.
fail_json
(
msg
=
"Error in creating the server, please check logs"
)
module
.
fail_json
(
msg
=
"Error in creating the server, please check logs"
)
time
.
sleep
(
2
)
time
.
sleep
(
2
)
module
.
fail_json
(
msg
=
"Timeout waiting for the server to come up.. Please check manually"
)
module
.
fail_json
(
msg
=
"Timeout waiting for the server to come up.. Please check manually"
)
if
server
.
status
==
'ERROR'
:
if
server
.
status
==
'ERROR'
:
module
.
fail_json
(
msg
=
"Error in creating the server.. Please check manually"
)
module
.
fail_json
(
msg
=
"Error in creating the server.. Please check manually"
)
...
@@ -185,7 +187,7 @@ def _create_server(module, nova):
...
@@ -185,7 +187,7 @@ def _create_server(module, nova):
public
=
[
x
[
'addr'
]
for
x
in
getattr
(
server
,
'addresses'
)
.
itervalues
()
.
next
()
if
x
[
'OS-EXT-IPS:type'
]
==
'floating'
]
public
=
[
x
[
'addr'
]
for
x
in
getattr
(
server
,
'addresses'
)
.
itervalues
()
.
next
()
if
x
[
'OS-EXT-IPS:type'
]
==
'floating'
]
module
.
exit_json
(
changed
=
True
,
id
=
info
[
'id'
],
private_ip
=
''
.
join
(
private
),
public_ip
=
''
.
join
(
public
),
status
=
server
.
status
,
info
=
server
.
_info
)
module
.
exit_json
(
changed
=
True
,
id
=
info
[
'id'
],
private_ip
=
''
.
join
(
private
),
public_ip
=
''
.
join
(
public
),
status
=
server
.
status
,
info
=
server
.
_info
)
def
_get_server_state
(
module
,
nova
):
def
_get_server_state
(
module
,
nova
):
server
=
None
server
=
None
try
:
try
:
...
@@ -199,15 +201,15 @@ def _get_server_state(module, nova):
...
@@ -199,15 +201,15 @@ def _get_server_state(module, nova):
module
.
fail_json
(
msg
=
"The VM is available but not Active. state:"
+
server
.
status
)
module
.
fail_json
(
msg
=
"The VM is available but not Active. state:"
+
server
.
status
)
private
=
[
x
[
'addr'
]
for
x
in
getattr
(
server
,
'addresses'
)
.
itervalues
()
.
next
()
if
'OS-EXT-IPS:type'
in
x
and
x
[
'OS-EXT-IPS:type'
]
==
'fixed'
]
private
=
[
x
[
'addr'
]
for
x
in
getattr
(
server
,
'addresses'
)
.
itervalues
()
.
next
()
if
'OS-EXT-IPS:type'
in
x
and
x
[
'OS-EXT-IPS:type'
]
==
'fixed'
]
public
=
[
x
[
'addr'
]
for
x
in
getattr
(
server
,
'addresses'
)
.
itervalues
()
.
next
()
if
'OS-EXT-IPS:type'
in
x
and
x
[
'OS-EXT-IPS:type'
]
==
'floating'
]
public
=
[
x
[
'addr'
]
for
x
in
getattr
(
server
,
'addresses'
)
.
itervalues
()
.
next
()
if
'OS-EXT-IPS:type'
in
x
and
x
[
'OS-EXT-IPS:type'
]
==
'floating'
]
module
.
exit_json
(
changed
=
False
,
id
=
server
.
id
,
public_ip
=
''
.
join
(
public
),
private_ip
=
''
.
join
(
private
),
info
=
server
.
_info
)
module
.
exit_json
(
changed
=
False
,
id
=
server
.
id
,
public_ip
=
''
.
join
(
public
),
private_ip
=
''
.
join
(
private
),
info
=
server
.
_info
)
if
server
and
module
.
params
[
'state'
]
==
'absent'
:
if
server
and
module
.
params
[
'state'
]
==
'absent'
:
return
True
return
True
if
module
.
params
[
'state'
]
==
'absent'
:
if
module
.
params
[
'state'
]
==
'absent'
:
module
.
exit_json
(
changed
=
False
,
result
=
"not present"
)
module
.
exit_json
(
changed
=
False
,
result
=
"not present"
)
return
True
return
True
def
main
():
def
main
():
module
=
AnsibleModule
(
module
=
AnsibleModule
(
argument_spec
=
dict
(
argument_spec
=
dict
(
...
@@ -217,7 +219,7 @@ def main():
...
@@ -217,7 +219,7 @@ def main():
auth_url
=
dict
(
default
=
'http://127.0.0.1:35357/v2.0/'
),
auth_url
=
dict
(
default
=
'http://127.0.0.1:35357/v2.0/'
),
region_name
=
dict
(
default
=
None
),
region_name
=
dict
(
default
=
None
),
name
=
dict
(
required
=
True
),
name
=
dict
(
required
=
True
),
image_id
=
dict
(
default
=
None
),
image_id
=
dict
(
default
=
None
),
flavor_id
=
dict
(
default
=
1
),
flavor_id
=
dict
(
default
=
1
),
key_name
=
dict
(
default
=
None
),
key_name
=
dict
(
default
=
None
),
security_groups
=
dict
(
default
=
'default'
),
security_groups
=
dict
(
default
=
'default'
),
...
@@ -228,15 +230,19 @@ def main():
...
@@ -228,15 +230,19 @@ def main():
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
])
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
])
),
),
)
)
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
try
:
try
:
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
nova
.
authenticate
()
module
.
params
[
'login_password'
],
except
exc
.
Unauthorized
as
e
:
module
.
params
[
'login_tenant_name'
],
module
.
fail_json
(
msg
=
"Invalid OpenStack Nova credentials.:
%
s"
%
e
.
message
)
module
.
params
[
'auth_url'
],
except
exc
.
AuthorizationFailure
as
e
:
service_type
=
'compute'
)
module
.
fail_json
(
msg
=
"Unable to authorize user:
%
s"
%
e
.
message
)
except
Exception
as
e
:
module
.
fail_json
(
msg
=
"Error in authenticating to nova:
%
s"
%
e
.
message
)
if
module
.
params
[
'state'
]
==
'present'
:
if
module
.
params
[
'state'
]
==
'present'
:
if
not
module
.
params
[
'image_id'
]:
if
not
module
.
params
[
'image_id'
]:
module
.
fail_json
(
msg
=
"Parameter 'image_id' is required if state == 'present'"
)
module
.
fail_json
(
msg
=
"Parameter 'image_id' is required if state == 'present'"
)
...
@@ -246,7 +252,7 @@ def main():
...
@@ -246,7 +252,7 @@ def main():
if
module
.
params
[
'state'
]
==
'absent'
:
if
module
.
params
[
'state'
]
==
'absent'
:
_get_server_state
(
module
,
nova
)
_get_server_state
(
module
,
nova
)
_delete_server
(
module
,
nova
)
_delete_server
(
module
,
nova
)
# this is magic, see lib/ansible/module.params['common.py
# this is magic, see lib/ansible/module.params['common.py
from
ansible.module_utils.basic
import
*
from
ansible.module_utils.basic
import
*
main
()
main
()
...
...
library/cloud/nova_keypair
View file @
66cad764
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
#coding: utf-8 -*-
#coding: utf-8 -*-
# (c) 2013, Benno Joy <benno@ansibleworks.com>
# (c) 2013, Benno Joy <benno@ansibleworks.com>
# (c) 2013, John Dewey <john@dewey.ws>
#
#
# This module is free software: you can redistribute it and/or modify
# This module is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# it under the terms of the GNU General Public License as published by
...
@@ -18,6 +19,7 @@
...
@@ -18,6 +19,7 @@
try
:
try
:
from
novaclient.v1_1
import
client
from
novaclient.v1_1
import
client
from
novaclient
import
exceptions
import
time
import
time
except
ImportError
:
except
ImportError
:
print
(
"failed=True msg='novaclient is required for this module to work'"
)
print
(
"failed=True msg='novaclient is required for this module to work'"
)
...
@@ -97,12 +99,19 @@ def main():
...
@@ -97,12 +99,19 @@ def main():
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
])
state
=
dict
(
default
=
'present'
,
choices
=
[
'absent'
,
'present'
])
),
),
)
)
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
try
:
try
:
nova
=
client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
nova
.
authenticate
()
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
except
exc
.
Unauthorized
as
e
:
except
Exception
as
e
:
module
.
fail_json
(
msg
=
"Invalid OpenStack Nova credentials.:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
" Error in authenticating to nova:
%
s"
%
e
.
message
)
except
exc
.
AuthorizationFailure
as
e
:
module
.
fail_json
(
msg
=
"Unable to authorize user:
%
s"
%
e
.
message
)
if
module
.
params
[
'state'
]
==
'present'
:
if
module
.
params
[
'state'
]
==
'present'
:
for
key
in
nova
.
keypairs
.
list
():
for
key
in
nova
.
keypairs
.
list
():
if
key
.
name
==
module
.
params
[
'name'
]:
if
key
.
name
==
module
.
params
[
'name'
]:
...
...
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