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
658c1593
Commit
658c1593
authored
Feb 02, 2014
by
Timur Batyrshin
Committed by
James Cammarata
Feb 03, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
reword "except Error as e:" into "except Error, e:" to be compatible with Python 2.5 (#5852)
parent
2d0e9cd7
Hide whitespace changes
Inline
Side-by-side
Showing
27 changed files
with
118 additions
and
118 deletions
+118
-118
lib/ansible/runner/lookup_plugins/csvfile.py
+1
-1
lib/ansible/runner/lookup_plugins/dnstxt.py
+1
-1
lib/ansible/runner/lookup_plugins/password.py
+1
-1
library/cloud/digital_ocean
+3
-3
library/cloud/docker
+2
-2
library/cloud/ec2
+4
-4
library/cloud/ec2_ami
+1
-1
library/cloud/ec2_vpc
+7
-7
library/cloud/gce
+5
-5
library/cloud/gce_lb
+5
-5
library/cloud/gce_net
+6
-6
library/cloud/gce_pd
+7
-7
library/cloud/glance_image
+6
-6
library/cloud/keystone_user
+1
-1
library/cloud/nova_compute
+6
-6
library/cloud/nova_keypair
+4
-4
library/cloud/quantum_floating_ip
+10
-10
library/cloud/quantum_floating_ip_associate
+8
-8
library/cloud/quantum_network
+6
-6
library/cloud/quantum_router
+5
-5
library/cloud/quantum_router_gateway
+8
-8
library/cloud/quantum_router_interface
+8
-8
library/cloud/quantum_subnet
+6
-6
library/database/mongodb_user
+1
-1
library/packaging/apt_repository
+3
-3
plugins/inventory/digital_ocean.py
+1
-1
plugins/inventory/ec2.py
+2
-2
No files found.
lib/ansible/runner/lookup_plugins/csvfile.py
View file @
658c1593
...
@@ -64,7 +64,7 @@ class LookupModule(object):
...
@@ -64,7 +64,7 @@ class LookupModule(object):
name
,
value
=
param
.
split
(
'='
)
name
,
value
=
param
.
split
(
'='
)
assert
(
name
in
paramvals
)
assert
(
name
in
paramvals
)
paramvals
[
name
]
=
value
paramvals
[
name
]
=
value
except
(
ValueError
,
AssertionError
)
as
e
:
except
(
ValueError
,
AssertionError
)
,
e
:
raise
errors
.
AnsibleError
(
e
)
raise
errors
.
AnsibleError
(
e
)
if
paramvals
[
'delimiter'
]
==
'TAB'
:
if
paramvals
[
'delimiter'
]
==
'TAB'
:
...
...
lib/ansible/runner/lookup_plugins/dnstxt.py
View file @
658c1593
...
@@ -61,7 +61,7 @@ class LookupModule(object):
...
@@ -61,7 +61,7 @@ class LookupModule(object):
string
=
'NXDOMAIN'
string
=
'NXDOMAIN'
except
dns
.
resolver
.
Timeout
:
except
dns
.
resolver
.
Timeout
:
string
=
''
string
=
''
except
dns
.
exception
.
DNSException
as
e
:
except
dns
.
exception
.
DNSException
,
e
:
raise
errors
.
AnsibleError
(
"dns.resolver unhandled exception"
,
e
)
raise
errors
.
AnsibleError
(
"dns.resolver unhandled exception"
,
e
)
ret
.
append
(
''
.
join
(
string
))
ret
.
append
(
''
.
join
(
string
))
...
...
lib/ansible/runner/lookup_plugins/password.py
View file @
658c1593
...
@@ -68,7 +68,7 @@ class LookupModule(object):
...
@@ -68,7 +68,7 @@ class LookupModule(object):
paramvals
[
'chars'
]
=
use_chars
paramvals
[
'chars'
]
=
use_chars
else
:
else
:
paramvals
[
name
]
=
value
paramvals
[
name
]
=
value
except
(
ValueError
,
AssertionError
)
as
e
:
except
(
ValueError
,
AssertionError
)
,
e
:
raise
errors
.
AnsibleError
(
e
)
raise
errors
.
AnsibleError
(
e
)
length
=
paramvals
[
'length'
]
length
=
paramvals
[
'length'
]
...
...
library/cloud/digital_ocean
View file @
658c1593
...
@@ -163,7 +163,7 @@ import time
...
@@ -163,7 +163,7 @@ import time
try
:
try
:
import
dopy
import
dopy
from
dopy.manager
import
DoError
,
DoManager
from
dopy.manager
import
DoError
,
DoManager
except
ImportError
as
e
:
except
ImportError
,
e
:
print
"failed=True msg='dopy >= 0.2.2 required for this module'"
print
"failed=True msg='dopy >= 0.2.2 required for this module'"
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -415,9 +415,9 @@ def main():
...
@@ -415,9 +415,9 @@ def main():
try
:
try
:
core
(
module
)
core
(
module
)
except
TimeoutError
as
e
:
except
TimeoutError
,
e
:
module
.
fail_json
(
msg
=
str
(
e
),
id
=
e
.
id
)
module
.
fail_json
(
msg
=
str
(
e
),
id
=
e
.
id
)
except
(
DoError
,
Exception
)
as
e
:
except
(
DoError
,
Exception
)
,
e
:
module
.
fail_json
(
msg
=
str
(
e
))
module
.
fail_json
(
msg
=
str
(
e
))
# import module snippets
# import module snippets
...
...
library/cloud/docker
View file @
658c1593
...
@@ -472,11 +472,11 @@ def main():
...
@@ -472,11 +472,11 @@ def main():
module
.
exit_json
(
failed
=
failed
,
changed
=
changed
,
msg
=
msg
,
ansible_facts
=
_ansible_facts
(
facts
))
module
.
exit_json
(
failed
=
failed
,
changed
=
changed
,
msg
=
msg
,
ansible_facts
=
_ansible_facts
(
facts
))
except
docker
.
client
.
APIError
as
e
:
except
docker
.
client
.
APIError
,
e
:
changed
=
manager
.
has_changed
()
changed
=
manager
.
has_changed
()
module
.
exit_json
(
failed
=
True
,
changed
=
changed
,
msg
=
"Docker API error: "
+
e
.
explanation
)
module
.
exit_json
(
failed
=
True
,
changed
=
changed
,
msg
=
"Docker API error: "
+
e
.
explanation
)
except
RequestException
as
e
:
except
RequestException
,
e
:
changed
=
manager
.
has_changed
()
changed
=
manager
.
has_changed
()
module
.
exit_json
(
failed
=
True
,
changed
=
changed
,
msg
=
repr
(
e
))
module
.
exit_json
(
failed
=
True
,
changed
=
changed
,
msg
=
repr
(
e
))
...
...
library/cloud/ec2
View file @
658c1593
...
@@ -619,7 +619,7 @@ def create_instances(module, ec2):
...
@@ -619,7 +619,7 @@ def create_instances(module, ec2):
try
:
try
:
res
.
connection
.
get_all_instances
(
instids
)
res
.
connection
.
get_all_instances
(
instids
)
break
break
except
boto
.
exception
.
EC2ResponseError
as
e
:
except
boto
.
exception
.
EC2ResponseError
,
e
:
if
"<Code>InvalidInstanceID.NotFound</Code>"
in
str
(
e
):
if
"<Code>InvalidInstanceID.NotFound</Code>"
in
str
(
e
):
# there's a race between start and get an instance
# there's a race between start and get an instance
continue
continue
...
@@ -629,7 +629,7 @@ def create_instances(module, ec2):
...
@@ -629,7 +629,7 @@ def create_instances(module, ec2):
if
instance_tags
:
if
instance_tags
:
try
:
try
:
ec2
.
create_tags
(
instids
,
instance_tags
)
ec2
.
create_tags
(
instids
,
instance_tags
)
except
boto
.
exception
.
EC2ResponseError
as
e
:
except
boto
.
exception
.
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
"
%
s:
%
s"
%
(
e
.
error_code
,
e
.
error_message
))
module
.
fail_json
(
msg
=
"
%
s:
%
s"
%
(
e
.
error_code
,
e
.
error_message
))
# wait here until the instances are up
# wait here until the instances are up
...
@@ -703,7 +703,7 @@ def terminate_instances(module, ec2, instance_ids):
...
@@ -703,7 +703,7 @@ def terminate_instances(module, ec2, instance_ids):
instance_dict_array
.
append
(
get_instance_info
(
inst
))
instance_dict_array
.
append
(
get_instance_info
(
inst
))
try
:
try
:
ec2
.
terminate_instances
([
inst
.
id
])
ec2
.
terminate_instances
([
inst
.
id
])
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to terminate instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
module
.
fail_json
(
msg
=
'Unable to terminate instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
changed
=
True
changed
=
True
...
@@ -773,7 +773,7 @@ def startstop_instances(module, ec2, instance_ids):
...
@@ -773,7 +773,7 @@ def startstop_instances(module, ec2, instance_ids):
inst
.
start
()
inst
.
start
()
else
:
else
:
inst
.
stop
()
inst
.
stop
()
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to change state for instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
module
.
fail_json
(
msg
=
'Unable to change state for instance {0}, error: {1}'
.
format
(
inst
.
id
,
e
))
changed
=
True
changed
=
True
...
...
library/cloud/ec2_ami
View file @
658c1593
...
@@ -195,7 +195,7 @@ def create_image(module, ec2):
...
@@ -195,7 +195,7 @@ def create_image(module, ec2):
try
:
try
:
img
=
ec2
.
get_image
(
image_id
)
img
=
ec2
.
get_image
(
image_id
)
break
break
except
boto
.
exception
.
EC2ResponseError
as
e
:
except
boto
.
exception
.
EC2ResponseError
,
e
:
if
e
.
error_code
==
'InvalidAMIID.NotFound'
:
if
e
.
error_code
==
'InvalidAMIID.NotFound'
:
time
.
sleep
(
1
)
time
.
sleep
(
1
)
else
:
else
:
...
...
library/cloud/ec2_vpc
View file @
658c1593
...
@@ -263,7 +263,7 @@ def create_vpc(module, vpc_conn):
...
@@ -263,7 +263,7 @@ def create_vpc(module, vpc_conn):
try
:
try
:
vpc_conn
.
create_subnet
(
vpc
.
id
,
subnet
[
'cidr'
],
subnet
.
get
(
'az'
,
None
))
vpc_conn
.
create_subnet
(
vpc
.
id
,
subnet
[
'cidr'
],
subnet
.
get
(
'az'
,
None
))
changed
=
True
changed
=
True
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to create subnet {0}, error: {1}'
.
format
(
subnet
[
'cidr'
],
e
))
module
.
fail_json
(
msg
=
'Unable to create subnet {0}, error: {1}'
.
format
(
subnet
[
'cidr'
],
e
))
# Now delete all absent subnets
# Now delete all absent subnets
for
csubnet
in
current_subnets
:
for
csubnet
in
current_subnets
:
...
@@ -275,7 +275,7 @@ def create_vpc(module, vpc_conn):
...
@@ -275,7 +275,7 @@ def create_vpc(module, vpc_conn):
try
:
try
:
vpc_conn
.
delete_subnet
(
csubnet
.
id
)
vpc_conn
.
delete_subnet
(
csubnet
.
id
)
changed
=
True
changed
=
True
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to delete subnet {0}, error: {1}'
.
format
(
csubnet
.
cidr_block
,
e
))
module
.
fail_json
(
msg
=
'Unable to delete subnet {0}, error: {1}'
.
format
(
csubnet
.
cidr_block
,
e
))
# Handle Internet gateway (create/delete igw)
# Handle Internet gateway (create/delete igw)
...
@@ -289,7 +289,7 @@ def create_vpc(module, vpc_conn):
...
@@ -289,7 +289,7 @@ def create_vpc(module, vpc_conn):
igw
=
vpc_conn
.
create_internet_gateway
()
igw
=
vpc_conn
.
create_internet_gateway
()
vpc_conn
.
attach_internet_gateway
(
igw
.
id
,
vpc
.
id
)
vpc_conn
.
attach_internet_gateway
(
igw
.
id
,
vpc
.
id
)
changed
=
True
changed
=
True
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to create Internet Gateway, error: {0}'
.
format
(
e
))
module
.
fail_json
(
msg
=
'Unable to create Internet Gateway, error: {0}'
.
format
(
e
))
else
:
else
:
# Set igw variable to the current igw instance for use in route tables.
# Set igw variable to the current igw instance for use in route tables.
...
@@ -300,7 +300,7 @@ def create_vpc(module, vpc_conn):
...
@@ -300,7 +300,7 @@ def create_vpc(module, vpc_conn):
vpc_conn
.
detach_internet_gateway
(
igws
[
0
]
.
id
,
vpc
.
id
)
vpc_conn
.
detach_internet_gateway
(
igws
[
0
]
.
id
,
vpc
.
id
)
vpc_conn
.
delete_internet_gateway
(
igws
[
0
]
.
id
)
vpc_conn
.
delete_internet_gateway
(
igws
[
0
]
.
id
)
changed
=
True
changed
=
True
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to delete Internet Gateway, error: {0}'
.
format
(
e
))
module
.
fail_json
(
msg
=
'Unable to delete Internet Gateway, error: {0}'
.
format
(
e
))
# Handle route tables - this may be worth splitting into a
# Handle route tables - this may be worth splitting into a
...
@@ -357,7 +357,7 @@ def create_vpc(module, vpc_conn):
...
@@ -357,7 +357,7 @@ def create_vpc(module, vpc_conn):
vpc_conn
.
associate_route_table
(
new_rt
.
id
,
rsn
.
id
)
vpc_conn
.
associate_route_table
(
new_rt
.
id
,
rsn
.
id
)
all_route_tables
.
append
(
new_rt
)
all_route_tables
.
append
(
new_rt
)
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
module
.
fail_json
(
msg
=
'Unable to create and associate route table {0}, error: '
\
msg
=
'Unable to create and associate route table {0}, error: '
\
'{1}'
.
format
(
rt
,
e
)
'{1}'
.
format
(
rt
,
e
)
...
@@ -382,7 +382,7 @@ def create_vpc(module, vpc_conn):
...
@@ -382,7 +382,7 @@ def create_vpc(module, vpc_conn):
try
:
try
:
if
not
is_main
:
if
not
is_main
:
vpc_conn
.
delete_route_table
(
rt
.
id
)
vpc_conn
.
delete_route_table
(
rt
.
id
)
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
msg
=
'Unable to delete old route table {0}, error: {1}'
.
format
(
rt
.
id
,
e
))
module
.
fail_json
(
msg
=
'Unable to delete old route table {0}, error: {1}'
.
format
(
rt
.
id
,
e
))
vpc_dict
=
get_vpc_info
(
vpc
)
vpc_dict
=
get_vpc_info
(
vpc
)
...
@@ -461,7 +461,7 @@ def terminate_vpc(module, vpc_conn, vpc_id=None, cidr=None):
...
@@ -461,7 +461,7 @@ def terminate_vpc(module, vpc_conn, vpc_id=None, cidr=None):
vpc_conn
.
delete_route_table
(
rt
.
id
)
vpc_conn
.
delete_route_table
(
rt
.
id
)
vpc_conn
.
delete_vpc
(
vpc
.
id
)
vpc_conn
.
delete_vpc
(
vpc
.
id
)
except
EC2ResponseError
as
e
:
except
EC2ResponseError
,
e
:
module
.
fail_json
(
module
.
fail_json
(
msg
=
'Unable to delete VPC {0}, error: {1}'
.
format
(
vpc
.
id
,
e
)
msg
=
'Unable to delete VPC {0}, error: {1}'
.
format
(
vpc
.
id
,
e
)
)
)
...
...
library/cloud/gce
View file @
658c1593
...
@@ -259,10 +259,10 @@ def create_instances(module, gce, instance_names):
...
@@ -259,10 +259,10 @@ def create_instances(module, gce, instance_names):
md
=
literal_eval
(
metadata
)
md
=
literal_eval
(
metadata
)
if
not
isinstance
(
md
,
dict
):
if
not
isinstance
(
md
,
dict
):
raise
ValueError
(
'metadata must be a dict'
)
raise
ValueError
(
'metadata must be a dict'
)
except
ValueError
as
e
:
except
ValueError
,
e
:
print
(
"failed=True msg='bad metadata:
%
s'"
%
str
(
e
))
print
(
"failed=True msg='bad metadata:
%
s'"
%
str
(
e
))
sys
.
exit
(
1
)
sys
.
exit
(
1
)
except
SyntaxError
as
e
:
except
SyntaxError
,
e
:
print
(
"failed=True msg='bad metadata syntax'"
)
print
(
"failed=True msg='bad metadata syntax'"
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
@@ -291,7 +291,7 @@ def create_instances(module, gce, instance_names):
...
@@ -291,7 +291,7 @@ def create_instances(module, gce, instance_names):
changed
=
True
changed
=
True
except
ResourceExistsError
:
except
ResourceExistsError
:
inst
=
gce
.
ex_get_node
(
name
,
lc_zone
)
inst
=
gce
.
ex_get_node
(
name
,
lc_zone
)
except
GoogleBaseError
as
e
:
except
GoogleBaseError
,
e
:
module
.
fail_json
(
msg
=
'Unexpected error attempting to create '
+
\
module
.
fail_json
(
msg
=
'Unexpected error attempting to create '
+
\
'instance
%
s, error:
%
s'
%
(
name
,
e
.
value
))
'instance
%
s, error:
%
s'
%
(
name
,
e
.
value
))
...
@@ -327,7 +327,7 @@ def terminate_instances(module, gce, instance_names, zone_name):
...
@@ -327,7 +327,7 @@ def terminate_instances(module, gce, instance_names, zone_name):
inst
=
gce
.
ex_get_node
(
name
,
zone_name
)
inst
=
gce
.
ex_get_node
(
name
,
zone_name
)
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
if
inst
:
if
inst
:
gce
.
destroy_node
(
inst
)
gce
.
destroy_node
(
inst
)
...
@@ -372,7 +372,7 @@ def main():
...
@@ -372,7 +372,7 @@ def main():
gce
=
get_driver
(
Provider
.
GCE
)(
*
ARGS
,
datacenter
=
zone
,
**
KWARGS
)
gce
=
get_driver
(
Provider
.
GCE
)(
*
ARGS
,
datacenter
=
zone
,
**
KWARGS
)
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
inames
=
[]
inames
=
[]
...
...
library/cloud/gce_lb
View file @
658c1593
...
@@ -211,7 +211,7 @@ def main():
...
@@ -211,7 +211,7 @@ def main():
gcelb
=
get_driver_lb
(
Provider_lb
.
GCE
)(
gce_driver
=
gce
)
gcelb
=
get_driver_lb
(
Provider_lb
.
GCE
)(
gce_driver
=
gce
)
gcelb
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
gcelb
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
changed
=
False
changed
=
False
...
@@ -237,7 +237,7 @@ def main():
...
@@ -237,7 +237,7 @@ def main():
changed
=
True
changed
=
True
except
ResourceExistsError
:
except
ResourceExistsError
:
hc
=
gce
.
ex_get_healthcheck
(
httphealthcheck_name
)
hc
=
gce
.
ex_get_healthcheck
(
httphealthcheck_name
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
if
hc
is
not
None
:
if
hc
is
not
None
:
...
@@ -281,7 +281,7 @@ def main():
...
@@ -281,7 +281,7 @@ def main():
changed
=
True
changed
=
True
except
ResourceExistsError
:
except
ResourceExistsError
:
lb
=
gcelb
.
get_balancer
(
name
)
lb
=
gcelb
.
get_balancer
(
name
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
if
lb
is
not
None
:
if
lb
is
not
None
:
...
@@ -307,7 +307,7 @@ def main():
...
@@ -307,7 +307,7 @@ def main():
changed
=
True
changed
=
True
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
# destroy the health check if specified
# destroy the health check if specified
...
@@ -319,7 +319,7 @@ def main():
...
@@ -319,7 +319,7 @@ def main():
changed
=
True
changed
=
True
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
...
...
library/cloud/gce_net
View file @
658c1593
...
@@ -174,7 +174,7 @@ def main():
...
@@ -174,7 +174,7 @@ def main():
gce
=
get_driver
(
Provider
.
GCE
)(
*
ARGS
,
**
KWARGS
)
gce
=
get_driver
(
Provider
.
GCE
)(
*
ARGS
,
**
KWARGS
)
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
changed
=
False
changed
=
False
...
@@ -188,7 +188,7 @@ def main():
...
@@ -188,7 +188,7 @@ def main():
json_output
[
'ipv4_range'
]
=
network
.
cidr
json_output
[
'ipv4_range'
]
=
network
.
cidr
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
# user wants to create a new network that doesn't yet exist
# user wants to create a new network that doesn't yet exist
...
@@ -202,7 +202,7 @@ def main():
...
@@ -202,7 +202,7 @@ def main():
json_output
[
'name'
]
=
name
json_output
[
'name'
]
=
name
json_output
[
'ipv4_range'
]
=
ipv4_range
json_output
[
'ipv4_range'
]
=
ipv4_range
changed
=
True
changed
=
True
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
if
fwname
:
if
fwname
:
...
@@ -224,7 +224,7 @@ def main():
...
@@ -224,7 +224,7 @@ def main():
changed
=
True
changed
=
True
except
ResourceExistsError
:
except
ResourceExistsError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
json_output
[
'fwname'
]
=
fwname
json_output
[
'fwname'
]
=
fwname
...
@@ -240,7 +240,7 @@ def main():
...
@@ -240,7 +240,7 @@ def main():
fw
=
gce
.
ex_get_firewall
(
fwname
)
fw
=
gce
.
ex_get_firewall
(
fwname
)
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
if
fw
:
if
fw
:
gce
.
ex_destroy_firewall
(
fw
)
gce
.
ex_destroy_firewall
(
fw
)
...
@@ -254,7 +254,7 @@ def main():
...
@@ -254,7 +254,7 @@ def main():
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
# json_output['d2'] = 'not found network name %s' % name
# json_output['d2'] = 'not found network name %s' % name
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
# json_output['d3'] = 'error with %s' % name
# json_output['d3'] = 'error with %s' % name
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
if
network
:
if
network
:
...
...
library/cloud/gce_pd
View file @
658c1593
...
@@ -155,7 +155,7 @@ def main():
...
@@ -155,7 +155,7 @@ def main():
gce
=
get_driver
(
Provider
.
GCE
)(
*
ARGS
,
datacenter
=
zone
,
**
KWARGS
)
gce
=
get_driver
(
Provider
.
GCE
)(
*
ARGS
,
datacenter
=
zone
,
**
KWARGS
)
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
disk
=
inst
=
None
disk
=
inst
=
None
...
@@ -185,7 +185,7 @@ def main():
...
@@ -185,7 +185,7 @@ def main():
json_output
[
'size_gb'
]
=
int
(
disk
.
size
)
json_output
[
'size_gb'
]
=
int
(
disk
.
size
)
except
ResourceNotFoundError
:
except
ResourceNotFoundError
:
pass
pass
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
# user wants a disk to exist. If "instance_name" is supplied the user
# user wants a disk to exist. If "instance_name" is supplied the user
...
@@ -214,14 +214,14 @@ def main():
...
@@ -214,14 +214,14 @@ def main():
except
QuotaExceededError
:
except
QuotaExceededError
:
module
.
fail_json
(
msg
=
'Requested disk size exceeds quota'
,
module
.
fail_json
(
msg
=
'Requested disk size exceeds quota'
,
changed
=
False
)
changed
=
False
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
json_output
[
'size_gb'
]
=
size_gb
json_output
[
'size_gb'
]
=
size_gb
changed
=
True
changed
=
True
if
inst
and
not
is_attached
:
if
inst
and
not
is_attached
:
try
:
try
:
gce
.
attach_volume
(
inst
,
disk
,
device
=
name
,
ex_mode
=
mode
)
gce
.
attach_volume
(
inst
,
disk
,
device
=
name
,
ex_mode
=
mode
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
json_output
[
'attached_to_instance'
]
=
inst
.
name
json_output
[
'attached_to_instance'
]
=
inst
.
name
json_output
[
'attached_mode'
]
=
mode
json_output
[
'attached_mode'
]
=
mode
...
@@ -233,15 +233,15 @@ def main():
...
@@ -233,15 +233,15 @@ def main():
if
inst
and
is_attached
:
if
inst
and
is_attached
:
try
:
try
:
gce
.
detach_volume
(
disk
,
ex_node
=
inst
)
gce
.
detach_volume
(
disk
,
ex_node
=
inst
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
changed
=
True
changed
=
True
if
not
detach_only
:
if
not
detach_only
:
try
:
try
:
gce
.
destroy_volume
(
disk
)
gce
.
destroy_volume
(
disk
)
except
ResourceInUseError
as
e
:
except
ResourceInUseError
,
e
:
module
.
fail_json
(
msg
=
str
(
e
.
value
),
changed
=
False
)
module
.
fail_json
(
msg
=
str
(
e
.
value
),
changed
=
False
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
module
.
fail_json
(
msg
=
unexpected_error_msg
(
e
),
changed
=
False
)
changed
=
True
changed
=
True
...
...
library/cloud/glance_image
View file @
658c1593
...
@@ -133,7 +133,7 @@ def _get_ksclient(module, kwargs):
...
@@ -133,7 +133,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
return
client
...
@@ -141,7 +141,7 @@ def _get_ksclient(module, kwargs):
...
@@ -141,7 +141,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
client
):
def
_get_endpoint
(
module
,
client
):
try
:
try
:
endpoint
=
client
.
service_catalog
.
url_for
(
service_type
=
'image'
,
endpoint_type
=
'publicURL'
)
endpoint
=
client
.
service_catalog
.
url_for
(
service_type
=
'image'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
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
return
endpoint
...
@@ -154,7 +154,7 @@ def _get_glance_client(module, kwargs):
...
@@ -154,7 +154,7 @@ def _get_glance_client(module, kwargs):
}
}
try
:
try
:
client
=
glanceclient
.
Client
(
'1'
,
endpoint
,
**
kwargs
)
client
=
glanceclient
.
Client
(
'1'
,
endpoint
,
**
kwargs
)
except
Exception
as
e
:
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
return
client
...
@@ -164,7 +164,7 @@ def _glance_image_present(module, params, client):
...
@@ -164,7 +164,7 @@ def _glance_image_present(module, params, client):
if
image
.
name
==
params
[
'name'
]:
if
image
.
name
==
params
[
'name'
]:
return
image
.
id
return
image
.
id
return
None
return
None
except
Exception
as
e
:
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
):
def
_glance_image_create
(
module
,
params
,
client
):
...
@@ -187,7 +187,7 @@ def _glance_image_create(module, params, client):
...
@@ -187,7 +187,7 @@ def _glance_image_create(module, params, client):
if
image
.
status
==
'active'
:
if
image
.
status
==
'active'
:
break
break
time
.
sleep
(
5
)
time
.
sleep
(
5
)
except
Exception
as
e
:
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'
:
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
)
...
@@ -199,7 +199,7 @@ def _glance_delete_image(module, params, client):
...
@@ -199,7 +199,7 @@ def _glance_delete_image(module, params, client):
for
image
in
client
.
images
.
list
():
for
image
in
client
.
images
.
list
():
if
image
.
name
==
params
[
'name'
]:
if
image
.
name
==
params
[
'name'
]:
client
.
images
.
delete
(
image
)
client
.
images
.
delete
(
image
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in deleting image:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in deleting image:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
"Deleted"
)
module
.
exit_json
(
changed
=
True
,
result
=
"Deleted"
)
...
...
library/cloud/keystone_user
View file @
658c1593
...
@@ -332,7 +332,7 @@ def main():
...
@@ -332,7 +332,7 @@ def main():
d
=
dispatch
(
keystone
,
user
,
password
,
tenant
,
tenant_description
,
d
=
dispatch
(
keystone
,
user
,
password
,
tenant
,
tenant_description
,
email
,
role
,
state
,
endpoint
,
token
,
login_user
,
email
,
role
,
state
,
endpoint
,
token
,
login_user
,
login_password
,
check_mode
)
login_password
,
check_mode
)
except
Exception
as
e
:
except
Exception
,
e
:
if
check_mode
:
if
check_mode
:
# If we have a failure in check mode
# If we have a failure in check mode
module
.
exit_json
(
changed
=
True
,
module
.
exit_json
(
changed
=
True
,
...
...
library/cloud/nova_compute
View file @
658c1593
...
@@ -137,7 +137,7 @@ def _delete_server(module, nova):
...
@@ -137,7 +137,7 @@ def _delete_server(module, nova):
if
server_list
:
if
server_list
:
server
=
[
x
for
x
in
server_list
if
x
.
name
==
module
.
params
[
'name'
]]
server
=
[
x
for
x
in
server_list
if
x
.
name
==
module
.
params
[
'name'
]]
nova
.
servers
.
delete
(
server
.
pop
())
nova
.
servers
.
delete
(
server
.
pop
())
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in deleting vm:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in deleting vm:
%
s"
%
e
.
message
)
if
module
.
params
[
'wait'
]
==
'no'
:
if
module
.
params
[
'wait'
]
==
'no'
:
module
.
exit_json
(
changed
=
True
,
result
=
"deleted"
)
module
.
exit_json
(
changed
=
True
,
result
=
"deleted"
)
...
@@ -163,14 +163,14 @@ def _create_server(module, nova):
...
@@ -163,14 +163,14 @@ def _create_server(module, nova):
try
:
try
:
server
=
nova
.
servers
.
create
(
*
bootargs
,
**
bootkwargs
)
server
=
nova
.
servers
.
create
(
*
bootargs
,
**
bootkwargs
)
server
=
nova
.
servers
.
get
(
server
.
id
)
server
=
nova
.
servers
.
get
(
server
.
id
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in creating instance:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in creating instance:
%
s "
%
e
.
message
)
if
module
.
params
[
'wait'
]
==
'yes'
:
if
module
.
params
[
'wait'
]
==
'yes'
:
expire
=
time
.
time
()
+
int
(
module
.
params
[
'wait_for'
])
expire
=
time
.
time
()
+
int
(
module
.
params
[
'wait_for'
])
while
time
.
time
()
<
expire
:
while
time
.
time
()
<
expire
:
try
:
try
:
server
=
nova
.
servers
.
get
(
server
.
id
)
server
=
nova
.
servers
.
get
(
server
.
id
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting info from instance:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting info from instance:
%
s "
%
e
.
message
)
if
server
.
status
==
'ACTIVE'
:
if
server
.
status
==
'ACTIVE'
:
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'
]
...
@@ -194,7 +194,7 @@ def _get_server_state(module, nova):
...
@@ -194,7 +194,7 @@ def _get_server_state(module, nova):
servers
=
nova
.
servers
.
list
(
True
,
{
'name'
:
module
.
params
[
'name'
]})
servers
=
nova
.
servers
.
list
(
True
,
{
'name'
:
module
.
params
[
'name'
]})
if
servers
:
if
servers
:
server
=
[
x
for
x
in
servers
if
x
.
name
==
module
.
params
[
'name'
]][
0
]
server
=
[
x
for
x
in
servers
if
x
.
name
==
module
.
params
[
'name'
]][
0
]
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting the server list:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting the server list:
%
s"
%
e
.
message
)
if
server
and
module
.
params
[
'state'
]
==
'present'
:
if
server
and
module
.
params
[
'state'
]
==
'present'
:
if
server
.
status
!=
'ACTIVE'
:
if
server
.
status
!=
'ACTIVE'
:
...
@@ -238,9 +238,9 @@ def main():
...
@@ -238,9 +238,9 @@ def main():
service_type
=
'compute'
)
service_type
=
'compute'
)
try
:
try
:
nova
.
authenticate
()
nova
.
authenticate
()
except
exc
.
Unauthorized
as
e
:
except
exc
.
Unauthorized
,
e
:
module
.
fail_json
(
msg
=
"Invalid OpenStack Nova credentials.:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Invalid OpenStack Nova credentials.:
%
s"
%
e
.
message
)
except
exc
.
AuthorizationFailure
as
e
:
except
exc
.
AuthorizationFailure
,
e
:
module
.
fail_json
(
msg
=
"Unable to authorize user:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Unable to authorize user:
%
s"
%
e
.
message
)
if
module
.
params
[
'state'
]
==
'present'
:
if
module
.
params
[
'state'
]
==
'present'
:
...
...
library/cloud/nova_keypair
View file @
658c1593
...
@@ -107,9 +107,9 @@ def main():
...
@@ -107,9 +107,9 @@ def main():
service_type
=
'compute'
)
service_type
=
'compute'
)
try
:
try
:
nova
.
authenticate
()
nova
.
authenticate
()
except
exc
.
Unauthorized
as
e
:
except
exc
.
Unauthorized
,
e
:
module
.
fail_json
(
msg
=
"Invalid OpenStack Nova credentials.:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Invalid OpenStack Nova credentials.:
%
s"
%
e
.
message
)
except
exc
.
AuthorizationFailure
as
e
:
except
exc
.
AuthorizationFailure
,
e
:
module
.
fail_json
(
msg
=
"Unable to authorize user:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Unable to authorize user:
%
s"
%
e
.
message
)
if
module
.
params
[
'state'
]
==
'present'
:
if
module
.
params
[
'state'
]
==
'present'
:
...
@@ -118,7 +118,7 @@ def main():
...
@@ -118,7 +118,7 @@ def main():
module
.
exit_json
(
changed
=
False
,
result
=
"Key present"
)
module
.
exit_json
(
changed
=
False
,
result
=
"Key present"
)
try
:
try
:
key
=
nova
.
keypairs
.
create
(
module
.
params
[
'name'
],
module
.
params
[
'public_key'
])
key
=
nova
.
keypairs
.
create
(
module
.
params
[
'name'
],
module
.
params
[
'public_key'
])
except
Exception
as
e
:
except
Exception
,
e
:
module
.
exit_json
(
msg
=
"Error in creating the keypair:
%
s"
%
e
.
message
)
module
.
exit_json
(
msg
=
"Error in creating the keypair:
%
s"
%
e
.
message
)
if
not
module
.
params
[
'public_key'
]:
if
not
module
.
params
[
'public_key'
]:
module
.
exit_json
(
changed
=
True
,
key
=
key
.
private_key
)
module
.
exit_json
(
changed
=
True
,
key
=
key
.
private_key
)
...
@@ -128,7 +128,7 @@ def main():
...
@@ -128,7 +128,7 @@ def main():
if
key
.
name
==
module
.
params
[
'name'
]:
if
key
.
name
==
module
.
params
[
'name'
]:
try
:
try
:
nova
.
keypairs
.
delete
(
module
.
params
[
'name'
])
nova
.
keypairs
.
delete
(
module
.
params
[
'name'
])
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"The keypair deletion has failed:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"The keypair deletion has failed:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
"deleted"
)
module
.
exit_json
(
changed
=
True
,
result
=
"deleted"
)
module
.
exit_json
(
changed
=
False
,
result
=
"not present"
)
module
.
exit_json
(
changed
=
False
,
result
=
"not present"
)
...
...
library/cloud/quantum_floating_ip
View file @
658c1593
...
@@ -96,7 +96,7 @@ def _get_ksclient(module, kwargs):
...
@@ -96,7 +96,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -106,7 +106,7 @@ def _get_ksclient(module, kwargs):
...
@@ -106,7 +106,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -120,7 +120,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -120,7 +120,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
return
neutron
return
neutron
...
@@ -136,7 +136,7 @@ def _get_server_state(module, nova):
...
@@ -136,7 +136,7 @@ def _get_server_state(module, nova):
module
.
fail_json
(
msg
=
"The VM is available but not Active. state:"
+
info
[
'status'
])
module
.
fail_json
(
msg
=
"The VM is available but not Active. state:"
+
info
[
'status'
])
server_info
=
info
server_info
=
info
break
break
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting the server list:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting the server list:
%
s"
%
e
.
message
)
return
server_info
,
server
return
server_info
,
server
...
@@ -152,7 +152,7 @@ def _get_port_info(neutron, module, instance_id, internal_network_name=None):
...
@@ -152,7 +152,7 @@ def _get_port_info(neutron, module, instance_id, internal_network_name=None):
}
}
try
:
try
:
ports
=
neutron
.
list_ports
(
**
kwargs
)
ports
=
neutron
.
list_ports
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
if
subnet_id
:
if
subnet_id
:
port
=
next
(
port
for
port
in
ports
[
'ports'
]
if
port
[
'fixed_ips'
][
0
][
'subnet_id'
]
==
subnet_id
)
port
=
next
(
port
for
port
in
ports
[
'ports'
]
if
port
[
'fixed_ips'
][
0
][
'subnet_id'
]
==
subnet_id
)
...
@@ -171,7 +171,7 @@ def _get_floating_ip(module, neutron, fixed_ip_address):
...
@@ -171,7 +171,7 @@ def _get_floating_ip(module, neutron, fixed_ip_address):
}
}
try
:
try
:
ips
=
neutron
.
list_floatingips
(
**
kwargs
)
ips
=
neutron
.
list_floatingips
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"error in fetching the floatingips's
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"error in fetching the floatingips's
%
s"
%
e
.
message
)
if
not
ips
[
'floatingips'
]:
if
not
ips
[
'floatingips'
]:
return
None
,
None
return
None
,
None
...
@@ -184,7 +184,7 @@ def _create_floating_ip(neutron, module, port_id, net_id):
...
@@ -184,7 +184,7 @@ def _create_floating_ip(neutron, module, port_id, net_id):
}
}
try
:
try
:
result
=
neutron
.
create_floatingip
({
'floatingip'
:
kwargs
})
result
=
neutron
.
create_floatingip
({
'floatingip'
:
kwargs
})
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"There was an error in updating the floating ip address:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"There was an error in updating the floating ip address:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
result
,
public_ip
=
result
[
'floatingip'
][
'floating_ip_address'
])
module
.
exit_json
(
changed
=
True
,
result
=
result
,
public_ip
=
result
[
'floatingip'
][
'floating_ip_address'
])
...
@@ -194,7 +194,7 @@ def _get_net_id(neutron, module):
...
@@ -194,7 +194,7 @@ def _get_net_id(neutron, module):
}
}
try
:
try
:
networks
=
neutron
.
list_networks
(
**
kwargs
)
networks
=
neutron
.
list_networks
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
"Error in listing neutron networks:
%
s"
%
e
.
message
)
module
.
fail_json
(
"Error in listing neutron networks:
%
s"
%
e
.
message
)
if
not
networks
[
'networks'
]:
if
not
networks
[
'networks'
]:
return
None
return
None
...
@@ -206,7 +206,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
...
@@ -206,7 +206,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
}
}
try
:
try
:
result
=
neutron
.
update_floatingip
(
floating_ip_id
,
{
'floatingip'
:
kwargs
})
result
=
neutron
.
update_floatingip
(
floating_ip_id
,
{
'floatingip'
:
kwargs
})
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"There was an error in updating the floating ip address:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"There was an error in updating the floating ip address:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
result
)
module
.
exit_json
(
changed
=
True
,
result
=
result
)
...
@@ -231,7 +231,7 @@ def main():
...
@@ -231,7 +231,7 @@ def main():
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
neutron
=
_get_neutron_client
(
module
,
module
.
params
)
neutron
=
_get_neutron_client
(
module
,
module
.
params
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in authenticating to nova:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in authenticating to nova:
%
s"
%
e
.
message
)
server_info
,
server_obj
=
_get_server_state
(
module
,
nova
)
server_info
,
server_obj
=
_get_server_state
(
module
,
nova
)
...
...
library/cloud/quantum_floating_ip_associate
View file @
658c1593
...
@@ -95,7 +95,7 @@ def _get_ksclient(module, kwargs):
...
@@ -95,7 +95,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -105,7 +105,7 @@ def _get_ksclient(module, kwargs):
...
@@ -105,7 +105,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -119,7 +119,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -119,7 +119,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
return
neutron
return
neutron
...
@@ -135,7 +135,7 @@ def _get_server_state(module, nova):
...
@@ -135,7 +135,7 @@ def _get_server_state(module, nova):
module
.
fail_json
(
msg
=
"The VM is available but not Active. state:"
+
info
[
'status'
])
module
.
fail_json
(
msg
=
"The VM is available but not Active. state:"
+
info
[
'status'
])
server_info
=
info
server_info
=
info
break
break
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting the server list:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting the server list:
%
s"
%
e
.
message
)
return
server_info
,
server
return
server_info
,
server
...
@@ -143,7 +143,7 @@ def _get_port_id(neutron, module, instance_id):
...
@@ -143,7 +143,7 @@ def _get_port_id(neutron, module, instance_id):
kwargs
=
dict
(
device_id
=
instance_id
)
kwargs
=
dict
(
device_id
=
instance_id
)
try
:
try
:
ports
=
neutron
.
list_ports
(
**
kwargs
)
ports
=
neutron
.
list_ports
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
if
not
ports
[
'ports'
]:
if
not
ports
[
'ports'
]:
return
None
return
None
...
@@ -155,7 +155,7 @@ def _get_floating_ip_id(module, neutron):
...
@@ -155,7 +155,7 @@ def _get_floating_ip_id(module, neutron):
}
}
try
:
try
:
ips
=
neutron
.
list_floatingips
(
**
kwargs
)
ips
=
neutron
.
list_floatingips
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"error in fetching the floatingips's
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"error in fetching the floatingips's
%
s"
%
e
.
message
)
if
not
ips
[
'floatingips'
]:
if
not
ips
[
'floatingips'
]:
module
.
fail_json
(
msg
=
"Could find the ip specified in parameter, Please check"
)
module
.
fail_json
(
msg
=
"Could find the ip specified in parameter, Please check"
)
...
@@ -172,7 +172,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
...
@@ -172,7 +172,7 @@ def _update_floating_ip(neutron, module, port_id, floating_ip_id):
}
}
try
:
try
:
result
=
neutron
.
update_floatingip
(
floating_ip_id
,
{
'floatingip'
:
kwargs
})
result
=
neutron
.
update_floatingip
(
floating_ip_id
,
{
'floatingip'
:
kwargs
})
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"There was an error in updating the floating ip address:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"There was an error in updating the floating ip address:
%
s"
%
e
.
message
)
module
.
exit_json
(
changed
=
True
,
result
=
result
,
public_ip
=
module
.
params
[
'ip_address'
])
module
.
exit_json
(
changed
=
True
,
result
=
result
,
public_ip
=
module
.
params
[
'ip_address'
])
...
@@ -194,7 +194,7 @@ def main():
...
@@ -194,7 +194,7 @@ def main():
try
:
try
:
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
nova
=
nova_client
.
Client
(
module
.
params
[
'login_username'
],
module
.
params
[
'login_password'
],
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
module
.
params
[
'login_tenant_name'
],
module
.
params
[
'auth_url'
],
service_type
=
'compute'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
" Error in authenticating to nova:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
" Error in authenticating to nova:
%
s"
%
e
.
message
)
neutron
=
_get_neutron_client
(
module
,
module
.
params
)
neutron
=
_get_neutron_client
(
module
,
module
.
params
)
state
,
floating_ip_id
=
_get_floating_ip_id
(
module
,
neutron
)
state
,
floating_ip_id
=
_get_floating_ip_id
(
module
,
neutron
)
...
...
library/cloud/quantum_network
View file @
658c1593
...
@@ -128,7 +128,7 @@ def _get_ksclient(module, kwargs):
...
@@ -128,7 +128,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -138,7 +138,7 @@ def _get_ksclient(module, kwargs):
...
@@ -138,7 +138,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s "
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -152,7 +152,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -152,7 +152,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
" Error in connecting to neutron:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
" Error in connecting to neutron:
%
s "
%
e
.
message
)
return
neutron
return
neutron
...
@@ -178,7 +178,7 @@ def _get_net_id(neutron, module):
...
@@ -178,7 +178,7 @@ def _get_net_id(neutron, module):
}
}
try
:
try
:
networks
=
neutron
.
list_networks
(
**
kwargs
)
networks
=
neutron
.
list_networks
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in listing neutron networks:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in listing neutron networks:
%
s"
%
e
.
message
)
if
not
networks
[
'networks'
]:
if
not
networks
[
'networks'
]:
return
None
return
None
...
@@ -216,7 +216,7 @@ def _create_network(module, neutron):
...
@@ -216,7 +216,7 @@ def _create_network(module, neutron):
try
:
try
:
net
=
neutron
.
create_network
({
'network'
:
network
})
net
=
neutron
.
create_network
({
'network'
:
network
})
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in creating network:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in creating network:
%
s"
%
e
.
message
)
return
net
[
'network'
][
'id'
]
return
net
[
'network'
][
'id'
]
...
@@ -224,7 +224,7 @@ def _delete_network(module, net_id, neutron):
...
@@ -224,7 +224,7 @@ def _delete_network(module, net_id, neutron):
try
:
try
:
id
=
neutron
.
delete_network
(
net_id
)
id
=
neutron
.
delete_network
(
net_id
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in deleting the network:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in deleting the network:
%
s"
%
e
.
message
)
return
True
return
True
...
...
library/cloud/quantum_router
View file @
658c1593
...
@@ -99,7 +99,7 @@ def _get_ksclient(module, kwargs):
...
@@ -99,7 +99,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -109,7 +109,7 @@ def _get_ksclient(module, kwargs):
...
@@ -109,7 +109,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -123,7 +123,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -123,7 +123,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
return
neutron
return
neutron
...
@@ -149,7 +149,7 @@ def _get_router_id(module, neutron):
...
@@ -149,7 +149,7 @@ def _get_router_id(module, neutron):
}
}
try
:
try
:
routers
=
neutron
.
list_routers
(
**
kwargs
)
routers
=
neutron
.
list_routers
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting the router list:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting the router list:
%
s "
%
e
.
message
)
if
not
routers
[
'routers'
]:
if
not
routers
[
'routers'
]:
return
None
return
None
...
@@ -163,7 +163,7 @@ def _create_router(module, neutron):
...
@@ -163,7 +163,7 @@ def _create_router(module, neutron):
}
}
try
:
try
:
new_router
=
neutron
.
create_router
(
dict
(
router
=
router
))
new_router
=
neutron
.
create_router
(
dict
(
router
=
router
))
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in creating router:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in creating router:
%
s"
%
e
.
message
)
return
new_router
[
'router'
][
'id'
]
return
new_router
[
'router'
][
'id'
]
...
...
library/cloud/quantum_router_gateway
View file @
658c1593
...
@@ -89,7 +89,7 @@ def _get_ksclient(module, kwargs):
...
@@ -89,7 +89,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -99,7 +99,7 @@ def _get_ksclient(module, kwargs):
...
@@ -99,7 +99,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -113,7 +113,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -113,7 +113,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
return
neutron
return
neutron
...
@@ -123,7 +123,7 @@ def _get_router_id(module, neutron):
...
@@ -123,7 +123,7 @@ def _get_router_id(module, neutron):
}
}
try
:
try
:
routers
=
neutron
.
list_routers
(
**
kwargs
)
routers
=
neutron
.
list_routers
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting the router list:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting the router list:
%
s "
%
e
.
message
)
if
not
routers
[
'routers'
]:
if
not
routers
[
'routers'
]:
return
None
return
None
...
@@ -136,7 +136,7 @@ def _get_net_id(neutron, module):
...
@@ -136,7 +136,7 @@ def _get_net_id(neutron, module):
}
}
try
:
try
:
networks
=
neutron
.
list_networks
(
**
kwargs
)
networks
=
neutron
.
list_networks
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
"Error in listing neutron networks:
%
s"
%
e
.
message
)
module
.
fail_json
(
"Error in listing neutron networks:
%
s"
%
e
.
message
)
if
not
networks
[
'networks'
]:
if
not
networks
[
'networks'
]:
return
None
return
None
...
@@ -149,7 +149,7 @@ def _get_port_id(neutron, module, router_id, network_id):
...
@@ -149,7 +149,7 @@ def _get_port_id(neutron, module, router_id, network_id):
}
}
try
:
try
:
ports
=
neutron
.
list_ports
(
**
kwargs
)
ports
=
neutron
.
list_ports
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
if
not
ports
[
'ports'
]:
if
not
ports
[
'ports'
]:
return
None
return
None
...
@@ -161,14 +161,14 @@ def _add_gateway_router(neutron, module, router_id, network_id):
...
@@ -161,14 +161,14 @@ def _add_gateway_router(neutron, module, router_id, network_id):
}
}
try
:
try
:
neutron
.
add_gateway_router
(
router_id
,
kwargs
)
neutron
.
add_gateway_router
(
router_id
,
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in adding gateway to router:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in adding gateway to router:
%
s"
%
e
.
message
)
return
True
return
True
def
_remove_gateway_router
(
neutron
,
module
,
router_id
):
def
_remove_gateway_router
(
neutron
,
module
,
router_id
):
try
:
try
:
neutron
.
remove_gateway_router
(
router_id
)
neutron
.
remove_gateway_router
(
router_id
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in removing gateway to router:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in removing gateway to router:
%
s"
%
e
.
message
)
return
True
return
True
...
...
library/cloud/quantum_router_interface
View file @
658c1593
...
@@ -100,7 +100,7 @@ def _get_ksclient(module, kwargs):
...
@@ -100,7 +100,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -110,7 +110,7 @@ def _get_ksclient(module, kwargs):
...
@@ -110,7 +110,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -124,7 +124,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -124,7 +124,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in connecting to neutron:
%
s "
%
e
.
message
)
return
neutron
return
neutron
...
@@ -149,7 +149,7 @@ def _get_router_id(module, neutron):
...
@@ -149,7 +149,7 @@ def _get_router_id(module, neutron):
}
}
try
:
try
:
routers
=
neutron
.
list_routers
(
**
kwargs
)
routers
=
neutron
.
list_routers
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in getting the router list:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in getting the router list:
%
s "
%
e
.
message
)
if
not
routers
[
'routers'
]:
if
not
routers
[
'routers'
]:
return
None
return
None
...
@@ -164,7 +164,7 @@ def _get_subnet_id(module, neutron):
...
@@ -164,7 +164,7 @@ def _get_subnet_id(module, neutron):
}
}
try
:
try
:
subnets
=
neutron
.
list_subnets
(
**
kwargs
)
subnets
=
neutron
.
list_subnets
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
" Error in getting the subnet list:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
" Error in getting the subnet list:
%
s "
%
e
.
message
)
if
not
subnets
[
'subnets'
]:
if
not
subnets
[
'subnets'
]:
return
None
return
None
...
@@ -177,7 +177,7 @@ def _get_port_id(neutron, module, router_id, subnet_id):
...
@@ -177,7 +177,7 @@ def _get_port_id(neutron, module, router_id, subnet_id):
}
}
try
:
try
:
ports
=
neutron
.
list_ports
(
**
kwargs
)
ports
=
neutron
.
list_ports
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in listing ports:
%
s"
%
e
.
message
)
if
not
ports
[
'ports'
]:
if
not
ports
[
'ports'
]:
return
None
return
None
...
@@ -193,7 +193,7 @@ def _add_interface_router(neutron, module, router_id, subnet_id):
...
@@ -193,7 +193,7 @@ def _add_interface_router(neutron, module, router_id, subnet_id):
}
}
try
:
try
:
neutron
.
add_interface_router
(
router_id
,
kwargs
)
neutron
.
add_interface_router
(
router_id
,
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in adding interface to router:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in adding interface to router:
%
s"
%
e
.
message
)
return
True
return
True
...
@@ -203,7 +203,7 @@ def _remove_interface_router(neutron, module, router_id, subnet_id):
...
@@ -203,7 +203,7 @@ def _remove_interface_router(neutron, module, router_id, subnet_id):
}
}
try
:
try
:
neutron
.
remove_interface_router
(
router_id
,
kwargs
)
neutron
.
remove_interface_router
(
router_id
,
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in removing interface from router:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in removing interface from router:
%
s"
%
e
.
message
)
return
True
return
True
...
...
library/cloud/quantum_subnet
View file @
658c1593
...
@@ -128,7 +128,7 @@ def _get_ksclient(module, kwargs):
...
@@ -128,7 +128,7 @@ def _get_ksclient(module, kwargs):
password
=
kwargs
.
get
(
'login_password'
),
password
=
kwargs
.
get
(
'login_password'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
tenant_name
=
kwargs
.
get
(
'login_tenant_name'
),
auth_url
=
kwargs
.
get
(
'auth_url'
))
auth_url
=
kwargs
.
get
(
'auth_url'
))
except
Exception
as
e
:
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
)
global
_os_keystone
global
_os_keystone
_os_keystone
=
kclient
_os_keystone
=
kclient
...
@@ -138,7 +138,7 @@ def _get_ksclient(module, kwargs):
...
@@ -138,7 +138,7 @@ def _get_ksclient(module, kwargs):
def
_get_endpoint
(
module
,
ksclient
):
def
_get_endpoint
(
module
,
ksclient
):
try
:
try
:
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
endpoint
=
ksclient
.
service_catalog
.
url_for
(
service_type
=
'network'
,
endpoint_type
=
'publicURL'
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error getting network endpoint:
%
s"
%
e
.
message
)
return
endpoint
return
endpoint
...
@@ -152,7 +152,7 @@ def _get_neutron_client(module, kwargs):
...
@@ -152,7 +152,7 @@ def _get_neutron_client(module, kwargs):
}
}
try
:
try
:
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
neutron
=
client
.
Client
(
'2.0'
,
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
" Error in connecting to neutron:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
" Error in connecting to neutron:
%
s"
%
e
.
message
)
return
neutron
return
neutron
...
@@ -177,7 +177,7 @@ def _get_net_id(neutron, module):
...
@@ -177,7 +177,7 @@ def _get_net_id(neutron, module):
}
}
try
:
try
:
networks
=
neutron
.
list_networks
(
**
kwargs
)
networks
=
neutron
.
list_networks
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
"Error in listing neutron networks:
%
s"
%
e
.
message
)
module
.
fail_json
(
"Error in listing neutron networks:
%
s"
%
e
.
message
)
if
not
networks
[
'networks'
]:
if
not
networks
[
'networks'
]:
return
None
return
None
...
@@ -197,7 +197,7 @@ def _get_subnet_id(module, neutron):
...
@@ -197,7 +197,7 @@ def _get_subnet_id(module, neutron):
}
}
try
:
try
:
subnets
=
neutron
.
list_subnets
(
**
kwargs
)
subnets
=
neutron
.
list_subnets
(
**
kwargs
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
" Error in getting the subnet list:
%
s "
%
e
.
message
)
module
.
fail_json
(
msg
=
" Error in getting the subnet list:
%
s "
%
e
.
message
)
if
not
subnets
[
'subnets'
]:
if
not
subnets
[
'subnets'
]:
return
None
return
None
...
@@ -239,7 +239,7 @@ def _create_subnet(module, neutron):
...
@@ -239,7 +239,7 @@ def _create_subnet(module, neutron):
def
_delete_subnet
(
module
,
neutron
,
subnet_id
):
def
_delete_subnet
(
module
,
neutron
,
subnet_id
):
try
:
try
:
neutron
.
delete_subnet
(
subnet_id
)
neutron
.
delete_subnet
(
subnet_id
)
except
Exception
as
e
:
except
Exception
,
e
:
module
.
fail_json
(
msg
=
"Error in deleting subnet:
%
s"
%
e
.
message
)
module
.
fail_json
(
msg
=
"Error in deleting subnet:
%
s"
%
e
.
message
)
return
True
return
True
...
...
library/database/mongodb_user
View file @
658c1593
...
@@ -199,7 +199,7 @@ def main():
...
@@ -199,7 +199,7 @@ def main():
if
login_user
is
not
None
and
login_password
is
not
None
:
if
login_user
is
not
None
and
login_password
is
not
None
:
client
.
admin
.
authenticate
(
login_user
,
login_password
)
client
.
admin
.
authenticate
(
login_user
,
login_password
)
except
ConnectionFailure
as
e
:
except
ConnectionFailure
,
e
:
module
.
fail_json
(
msg
=
'unable to connect to database, check login_user and login_password are correct'
)
module
.
fail_json
(
msg
=
'unable to connect to database, check login_user and login_password are correct'
)
if
state
==
'present'
:
if
state
==
'present'
:
...
...
library/packaging/apt_repository
View file @
658c1593
...
@@ -205,7 +205,7 @@ class SourcesList(object):
...
@@ -205,7 +205,7 @@ class SourcesList(object):
try
:
try
:
f
.
write
(
line
)
f
.
write
(
line
)
except
IOError
as
err
:
except
IOError
,
err
:
module
.
fail_json
(
msg
=
"Failed to write to file
%
s:
%
s"
%
(
tmp_path
,
unicode
(
err
)))
module
.
fail_json
(
msg
=
"Failed to write to file
%
s:
%
s"
%
(
tmp_path
,
unicode
(
err
)))
module
.
atomic_move
(
tmp_path
,
filename
)
module
.
atomic_move
(
tmp_path
,
filename
)
else
:
else
:
...
@@ -366,7 +366,7 @@ def main():
...
@@ -366,7 +366,7 @@ def main():
sourceslist
.
add_source
(
repo
)
sourceslist
.
add_source
(
repo
)
elif
state
==
'absent'
:
elif
state
==
'absent'
:
sourceslist
.
remove_source
(
repo
)
sourceslist
.
remove_source
(
repo
)
except
InvalidSource
as
err
:
except
InvalidSource
,
err
:
module
.
fail_json
(
msg
=
'Invalid repository string:
%
s'
%
unicode
(
err
))
module
.
fail_json
(
msg
=
'Invalid repository string:
%
s'
%
unicode
(
err
))
sources_after
=
sourceslist
.
dump
()
sources_after
=
sourceslist
.
dump
()
...
@@ -378,7 +378,7 @@ def main():
...
@@ -378,7 +378,7 @@ def main():
if
update_cache
:
if
update_cache
:
cache
=
apt
.
Cache
()
cache
=
apt
.
Cache
()
cache
.
update
()
cache
.
update
()
except
OSError
as
err
:
except
OSError
,
err
:
module
.
fail_json
(
msg
=
unicode
(
err
))
module
.
fail_json
(
msg
=
unicode
(
err
))
module
.
exit_json
(
changed
=
changed
,
repo
=
repo
,
state
=
state
)
module
.
exit_json
(
changed
=
changed
,
repo
=
repo
,
state
=
state
)
...
...
plugins/inventory/digital_ocean.py
View file @
658c1593
...
@@ -139,7 +139,7 @@ except ImportError:
...
@@ -139,7 +139,7 @@ except ImportError:
try
:
try
:
from
dopy.manager
import
DoError
,
DoManager
from
dopy.manager
import
DoError
,
DoManager
except
ImportError
as
e
:
except
ImportError
,
e
:
print
"failed=True msg='`dopy` library required for this script'"
print
"failed=True msg='`dopy` library required for this script'"
sys
.
exit
(
1
)
sys
.
exit
(
1
)
...
...
plugins/inventory/ec2.py
View file @
658c1593
...
@@ -281,7 +281,7 @@ class Ec2Inventory(object):
...
@@ -281,7 +281,7 @@ class Ec2Inventory(object):
for
instance
in
reservation
.
instances
:
for
instance
in
reservation
.
instances
:
self
.
add_instance
(
instance
,
region
)
self
.
add_instance
(
instance
,
region
)
except
boto
.
exception
.
BotoServerError
as
e
:
except
boto
.
exception
.
BotoServerError
,
e
:
if
not
self
.
eucalyptus
:
if
not
self
.
eucalyptus
:
print
"Looks like AWS is down again:"
print
"Looks like AWS is down again:"
print
e
print
e
...
@@ -297,7 +297,7 @@ class Ec2Inventory(object):
...
@@ -297,7 +297,7 @@ class Ec2Inventory(object):
instances
=
conn
.
get_all_dbinstances
()
instances
=
conn
.
get_all_dbinstances
()
for
instance
in
instances
:
for
instance
in
instances
:
self
.
add_rds_instance
(
instance
,
region
)
self
.
add_rds_instance
(
instance
,
region
)
except
boto
.
exception
.
BotoServerError
as
e
:
except
boto
.
exception
.
BotoServerError
,
e
:
if
not
e
.
reason
==
"Forbidden"
:
if
not
e
.
reason
==
"Forbidden"
:
print
"Looks like AWS RDS is down: "
print
"Looks like AWS RDS is down: "
print
e
print
e
...
...
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