1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

google: PEP8 compliancy fixes (#32309)

This PR includes:
- PEP8 compliancy fixes
- Documentation fixes

Signed-off-by: Satyajit Bulage <sbulage@redhat.com>
This commit is contained in:
Satyajit Bulage 2017-10-31 15:23:31 +05:30 committed by René Moser
parent 5d1ed1fc25
commit 52aa522c19
7 changed files with 129 additions and 137 deletions

View file

@ -3,14 +3,13 @@
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: gce
@ -325,6 +324,7 @@ import logging
try:
from ast import literal_eval
HAS_PYTHON26 = True
except ImportError:
HAS_PYTHON26 = False
@ -336,6 +336,7 @@ try:
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
ResourceExistsError, ResourceInUseError, ResourceNotFoundError
from libcloud.compute.drivers.gce import GCEAddress
_ = Provider.GCE
HAS_LIBCLOUD = True
except ImportError:
@ -589,6 +590,7 @@ def create_instances(module, gce, instance_names, number, lc_zone):
return (changed, instance_json_data, instance_names)
def change_instance_state(module, gce, instance_names, number, zone, state):
"""Changes the state of a list of instances. For example,
change from started to stopped, or started to absent.
@ -633,17 +635,16 @@ def change_instance_state(module, gce, instance_names, number, zone, state):
if state in ['absent', 'deleted']:
gce.destroy_node(node)
changed = True
elif state == 'started' and \
node.state == libcloud.compute.types.NodeState.STOPPED:
elif state == 'started' and node.state == libcloud.compute.types.NodeState.STOPPED:
gce.ex_start_node(node)
changed = True
elif state in ['stopped', 'terminated'] and \
node.state == libcloud.compute.types.NodeState.RUNNING:
elif state in ['stopped', 'terminated'] and node.state == libcloud.compute.types.NodeState.RUNNING:
gce.ex_stop_node(node)
changed = True
return (changed, state_instance_names)
def main():
module = AnsibleModule(
argument_spec=dict(
@ -751,6 +752,7 @@ class LazyDiskImage:
Object for lazy instantiation of disk image
gce.ex_get_image is a very expensive call, so we want to avoid calling it as much as possible.
"""
def __init__(self, module, gce, name, has_pd, family=None, projects=None):
self.image = None
self.was_called = False

View file

@ -122,6 +122,7 @@ def get_address(gce, name, region):
except ResourceNotFoundError:
return None
def create_address(gce, params):
"""
Create a new Address.
@ -147,6 +148,7 @@ def create_address(gce, params):
return (changed, return_data)
def delete_address(address):
"""
Delete an Address.
@ -167,6 +169,7 @@ def delete_address(address):
return_data = address.address
return (changed, return_data)
def main():
module = AnsibleModule(argument_spec=dict(
name=dict(required=True),

View file

@ -157,8 +157,8 @@ try:
from libcloud.compute.providers import get_driver
from libcloud.loadbalancer.types import Provider as Provider_lb
from libcloud.loadbalancer.providers import get_driver as get_driver_lb
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
ResourceExistsError, ResourceNotFoundError
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError
_ = Provider.GCE
HAS_LIBCLOUD = True
except ImportError:
@ -203,10 +203,8 @@ def main():
httphealthcheck_path = module.params.get('httphealthcheck_path')
httphealthcheck_interval = module.params.get('httphealthcheck_interval')
httphealthcheck_timeout = module.params.get('httphealthcheck_timeout')
httphealthcheck_unhealthy_count = \
module.params.get('httphealthcheck_unhealthy_count')
httphealthcheck_healthy_count = \
module.params.get('httphealthcheck_healthy_count')
httphealthcheck_unhealthy_count = module.params.get('httphealthcheck_unhealthy_count')
httphealthcheck_healthy_count = module.params.get('httphealthcheck_healthy_count')
httphealthcheck_host = module.params.get('httphealthcheck_host')
name = module.params.get('name')
protocol = module.params.get('protocol')
@ -227,8 +225,7 @@ def main():
json_output = {'name': name, 'state': state}
if not name and not httphealthcheck_name:
module.fail_json(msg='Nothing to do, please specify a "name" ' + \
'or "httphealthcheck_name" parameter', changed=False)
module.fail_json(msg='Nothing to do, please specify a "name" ' + 'or "httphealthcheck_name" parameter', changed=False)
if state in ['active', 'present']:
# first, create the httphealthcheck if requested
@ -255,10 +252,8 @@ def main():
json_output['httphealthcheck_port'] = hc.port
json_output['httphealthcheck_interval'] = hc.interval
json_output['httphealthcheck_timeout'] = hc.timeout
json_output['httphealthcheck_unhealthy_count'] = \
hc.unhealthy_threshold
json_output['httphealthcheck_healthy_count'] = \
hc.healthy_threshold
json_output['httphealthcheck_unhealthy_count'] = hc.unhealthy_threshold
json_output['httphealthcheck_healthy_count'] = hc.healthy_threshold
# create the forwarding rule (and target pool under the hood)
lb = None
@ -331,7 +326,6 @@ def main():
except Exception as e:
module.fail_json(msg=unexpected_error_msg(e), changed=False)
json_output['changed'] = changed
module.exit_json(**json_output)

View file

@ -264,8 +264,7 @@ target_tags:
try:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
ResourceExistsError, ResourceNotFoundError
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError
_ = Provider.GCE
HAS_LIBCLOUD = True
except ImportError:
@ -293,6 +292,7 @@ def format_allowed_section(allowed):
return_val["ports"] = ports
return return_val
def format_allowed(allowed):
"""Format the 'allowed' value so that it is GCE compatible."""
return_value = []
@ -304,6 +304,7 @@ def format_allowed(allowed):
return_value.append(format_allowed_section(section))
return return_value
def sorted_allowed_list(allowed_list):
"""Sort allowed_list (output of format_allowed) by protocol and port."""
# sort by protocol
@ -414,8 +415,7 @@ def main():
if not allowed and not src_range and not src_tags:
if changed and network:
module.fail_json(
msg="Network created, but missing required " + \
"firewall rule parameter(s)", changed=True)
msg="Network created, but missing required " + "firewall rule parameter(s)", changed=True)
module.fail_json(
msg="Missing required firewall rule parameter(s)",
changed=False)

View file

@ -144,8 +144,7 @@ EXAMPLES = '''
try:
from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
ResourceExistsError, ResourceNotFoundError, ResourceInUseError
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError, ResourceInUseError
_ = Provider.GCE
HAS_LIBCLOUD = True
except ImportError:

View file

@ -69,12 +69,6 @@ lib/ansible/modules/cloud/docker/docker_network.py
lib/ansible/modules/cloud/google/gc_storage.py
lib/ansible/modules/cloud/google/gcdns_record.py
lib/ansible/modules/cloud/google/gcdns_zone.py
lib/ansible/modules/cloud/google/gce.py
lib/ansible/modules/cloud/google/gce_eip.py
lib/ansible/modules/cloud/google/gce_lb.py
lib/ansible/modules/cloud/google/gce_mig.py
lib/ansible/modules/cloud/google/gce_net.py
lib/ansible/modules/cloud/google/gce_pd.py
lib/ansible/modules/cloud/google/gce_tag.py
lib/ansible/modules/cloud/google/gcpubsub.py
lib/ansible/modules/cloud/google/gcspanner.py