Skip to content

Commit d1b7c04

Browse files
reformat
1 parent 7614a86 commit d1b7c04

File tree

2 files changed

+25
-32
lines changed

2 files changed

+25
-32
lines changed

plugins/lookup/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,22 +62,22 @@ class LookupModule(LookupBase):
6262
display = Display()
6363

6464
def handle_error(self, **kwargs):
65-
raise AnsibleError(to_native(kwargs.get('msg')))
65+
raise AnsibleError(to_native(kwargs.get("msg")))
6666

6767
def warn_callback(self, warning):
6868
self.display.warning(warning)
6969

7070
def run(self, terms, variables=None, **kwargs):
7171
if len(terms) != 1:
72-
raise AnsibleError('You must pass exactly one endpoint to query')
72+
raise AnsibleError("You must pass exactly one endpoint to query")
7373

7474
self.set_options(direct=kwargs)
7575

7676
module = AnsibleCloudStackAPI(argument_spec={}, direct_params=kwargs, error_callback=self.handle_error, warn_callback=self.warn_callback)
7777

7878
args = {}
79-
if self.get_option('query_params'):
80-
args.update(self.get_option('query_params', {}))
79+
if self.get_option("query_params"):
80+
args.update(self.get_option("query_params", {}))
8181

8282
res = module.query_api(terms[0], **args)
8383

plugins/module_utils/cloudstack_api.py

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
CS_IMP_ERR = None
1919
try:
2020
from cs import CloudStack, CloudStackException
21+
2122
HAS_LIB_CS = True
2223
except ImportError:
2324
CS_IMP_ERR = traceback.format_exc()
@@ -33,24 +34,24 @@ class AnsibleCloudStackAPI(AnsibleModule):
3334
error_callback = None
3435
warn_callback = None
3536
AUTH_ARGSPEC = dict(
36-
api_key=os.getenv('CLOUDSTACK_KEY'),
37-
api_secret=os.getenv('CLOUDSTACK_SECRET'),
38-
api_url=os.getenv('CLOUDSTACK_ENDPOINT'),
39-
api_http_method=os.getenv('CLOUDSTACK_METHOD', 'get'),
40-
api_timeout=os.getenv('CLOUDSTACK_TIMEOUT', 10),
41-
api_verify_ssl_cert=os.getenv('CLOUDSTACK_VERIFY'),
42-
validate_certs=os.getenv('CLOUDSTACK_DANGEROUS_NO_TLS_VERIFY', True),
37+
api_key=os.getenv("CLOUDSTACK_KEY"),
38+
api_secret=os.getenv("CLOUDSTACK_SECRET"),
39+
api_url=os.getenv("CLOUDSTACK_ENDPOINT"),
40+
api_http_method=os.getenv("CLOUDSTACK_METHOD", "get"),
41+
api_timeout=os.getenv("CLOUDSTACK_TIMEOUT", 10),
42+
api_verify_ssl_cert=os.getenv("CLOUDSTACK_VERIFY"),
43+
validate_certs=os.getenv("CLOUDSTACK_DANGEROUS_NO_TLS_VERIFY", True),
4344
)
4445

4546
def __init__(self, argument_spec=None, direct_params=None, error_callback=None, warn_callback=None, **kwargs):
4647

4748
if not HAS_LIB_CS:
48-
self.fail_json(msg=missing_required_lib('cs'), exception=CS_IMP_ERR)
49+
self.fail_json(msg=missing_required_lib("cs"), exception=CS_IMP_ERR)
4950

5051
full_argspec = {}
5152
full_argspec.update(AnsibleCloudStackAPI.AUTH_ARGSPEC)
5253
full_argspec.update(argument_spec)
53-
kwargs['supports_check_mode'] = True
54+
kwargs["supports_check_mode"] = True
5455

5556
self.error_callback = error_callback
5657
self.warn_callback = warn_callback
@@ -68,7 +69,7 @@ def __init__(self, argument_spec=None, direct_params=None, error_callback=None,
6869
super(AnsibleCloudStackAPI, self).__init__(argument_spec=full_argspec, **kwargs)
6970

7071
# Perform some basic validation
71-
if not re.match('^https{0,1}://', self.api_url):
72+
if not re.match("^https{0,1}://", self.api_url):
7273
self.api_url = "https://{0}".format(self.api_url)
7374

7475
def fail_json(self, **kwargs):
@@ -89,35 +90,27 @@ def cs(self):
8990

9091
def get_api_config(self):
9192
api_config = {
92-
'endpoint': self.api_url,
93-
'key': self.api_key,
94-
'secret': self.api_secret,
95-
'timeout': self.api_timeout,
96-
'method': self.api_http_method,
97-
'verify': self.api_verify_ssl_cert,
98-
'dangerous_no_tls_verify': not self.validate_certs,
93+
"endpoint": self.api_url,
94+
"key": self.api_key,
95+
"secret": self.api_secret,
96+
"timeout": self.api_timeout,
97+
"method": self.api_http_method,
98+
"verify": self.api_verify_ssl_cert,
99+
"dangerous_no_tls_verify": not self.validate_certs,
99100
}
100101

101-
# self.result.update({
102-
# 'api_url': api_config['endpoint'],
103-
# 'api_key': api_config['key'],
104-
# 'api_timeout': int(api_config['timeout']),
105-
# 'api_http_method': api_config['method'],
106-
# 'api_verify_ssl_cert': api_config['verify'],
107-
# 'validate_certs': not api_config['dangerous_no_tls_verify'],
108-
# })
109102
return api_config
110103

111104
def query_api(self, command, **args):
112105

113106
try:
114107
res = getattr(self.cs, command)(**args)
115108

116-
if 'errortext' in res:
117-
self.fail_json(msg="Failed: '%s'" % res['errortext'])
109+
if "errortext" in res:
110+
self.fail_json(msg="Failed: '%s'" % res["errortext"])
118111

119112
except CloudStackException as e:
120-
self.fail_json(msg='CloudStackException: %s' % to_native(e))
113+
self.fail_json(msg="CloudStackException: %s" % to_native(e))
121114

122115
except Exception as e:
123116
self.fail_json(msg=to_native(e))

0 commit comments

Comments
 (0)