PEP 8 E111 cleanup.

This commit is contained in:
Matt Clay 2017-01-30 20:01:03 -08:00
parent 5f89fc4a68
commit 85300883ef
2 changed files with 38 additions and 39 deletions

View file

@ -85,10 +85,10 @@ topics:
''' '''
try: try:
from ast import literal_eval from ast import literal_eval
HAS_PYTHON26 = True HAS_PYTHON26 = True
except ImportError: except ImportError:
HAS_PYTHON26 = False HAS_PYTHON26 = False
try: try:
from google.cloud import pubsub from google.cloud import pubsub
@ -96,52 +96,52 @@ try:
except ImportError as e: except ImportError as e:
HAS_GOOGLE_CLOUD_PUBSUB = False HAS_GOOGLE_CLOUD_PUBSUB = False
def list_func(data, member='name'): def list_func(data, member='name'):
"""Used for state=list.""" """Used for state=list."""
return [getattr(x, member) for x in data] return [getattr(x, member) for x in data]
def main(): def main():
module = AnsibleModule(argument_spec=dict( module = AnsibleModule(argument_spec=dict(
view=dict(choices=['topics', 'subscriptions'], default='topics'), view=dict(choices=['topics', 'subscriptions'], default='topics'),
topic=dict(required=False), topic=dict(required=False),
state=dict(choices=['list'], default='list'), state=dict(choices=['list'], default='list'),
service_account_email=dict(), service_account_email=dict(),
credentials_file=dict(), credentials_file=dict(),
project_id=dict(), ),) project_id=dict(), ),)
if not HAS_PYTHON26: if not HAS_PYTHON26:
module.fail_json( module.fail_json(
msg="GCE module requires python's 'ast' module, python v2.6+") msg="GCE module requires python's 'ast' module, python v2.6+")
if not HAS_GOOGLE_CLOUD_PUBSUB: if not HAS_GOOGLE_CLOUD_PUBSUB:
module.fail_json(msg="Please install google-cloud-pubsub library.") module.fail_json(msg="Please install google-cloud-pubsub library.")
CLIENT_MINIMUM_VERSION = '0.22.0' CLIENT_MINIMUM_VERSION = '0.22.0'
if not check_min_pkg_version('google-cloud-pubsub', CLIENT_MINIMUM_VERSION): if not check_min_pkg_version('google-cloud-pubsub', CLIENT_MINIMUM_VERSION):
module.fail_json(msg="Please install google-cloud-pubsub library version %s" % CLIENT_MINIMUM_VERSION) module.fail_json(msg="Please install google-cloud-pubsub library version %s" % CLIENT_MINIMUM_VERSION)
mod_params = {} mod_params = {}
mod_params['state'] = module.params.get('state') mod_params['state'] = module.params.get('state')
mod_params['topic'] = module.params.get('topic') mod_params['topic'] = module.params.get('topic')
mod_params['view'] = module.params.get('view') mod_params['view'] = module.params.get('view')
creds, params = get_google_cloud_credentials(module) creds, params = get_google_cloud_credentials(module)
pubsub_client = pubsub.Client(project=params['project_id'], credentials=creds, use_gax=False) pubsub_client = pubsub.Client(project=params['project_id'], credentials=creds, use_gax=False)
pubsub_client.user_agent = 'ansible-pubsub-0.1' pubsub_client.user_agent = 'ansible-pubsub-0.1'
json_output = {} json_output = {}
if mod_params['view'] == 'topics': if mod_params['view'] == 'topics':
json_output['topics'] = list_func(pubsub_client.list_topics()) json_output['topics'] = list_func(pubsub_client.list_topics())
elif mod_params['view'] == 'subscriptions': elif mod_params['view'] == 'subscriptions':
if mod_params['topic']: if mod_params['topic']:
t = pubsub_client.topic(mod_params['topic']) t = pubsub_client.topic(mod_params['topic'])
json_output['subscriptions'] = list_func(t.list_subscriptions()) json_output['subscriptions'] = list_func(t.list_subscriptions())
else: else:
json_output['subscriptions'] = list_func(pubsub_client.list_subscriptions()) json_output['subscriptions'] = list_func(pubsub_client.list_subscriptions())
json_output['changed'] = False json_output['changed'] = False
json_output.update(mod_params) json_output.update(mod_params)
module.exit_json(**json_output) module.exit_json(**json_output)
# import module snippets # import module snippets
from ansible.module_utils.basic import * from ansible.module_utils.basic import *

View file

@ -106,7 +106,6 @@ lib/ansible/modules/cloud/google/gc_storage.py
lib/ansible/modules/cloud/google/gce_img.py lib/ansible/modules/cloud/google/gce_img.py
lib/ansible/modules/cloud/google/gce_tag.py lib/ansible/modules/cloud/google/gce_tag.py
lib/ansible/modules/cloud/google/gcpubsub.py lib/ansible/modules/cloud/google/gcpubsub.py
lib/ansible/modules/cloud/google/gcpubsub_facts.py
lib/ansible/modules/cloud/misc/ovirt.py lib/ansible/modules/cloud/misc/ovirt.py
lib/ansible/modules/cloud/misc/proxmox.py lib/ansible/modules/cloud/misc/proxmox.py
lib/ansible/modules/cloud/misc/proxmox_kvm.py lib/ansible/modules/cloud/misc/proxmox_kvm.py