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:
parent
5d1ed1fc25
commit
52aa522c19
7 changed files with 129 additions and 137 deletions
|
@ -3,14 +3,13 @@
|
||||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
# 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
|
from __future__ import absolute_import, division, print_function
|
||||||
__metaclass__ = type
|
|
||||||
|
|
||||||
|
__metaclass__ = type
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
'supported_by': 'community'}
|
'supported_by': 'community'}
|
||||||
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
module: gce
|
module: gce
|
||||||
|
@ -325,6 +324,7 @@ import logging
|
||||||
|
|
||||||
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
|
||||||
|
@ -336,6 +336,7 @@ try:
|
||||||
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
||||||
ResourceExistsError, ResourceInUseError, ResourceNotFoundError
|
ResourceExistsError, ResourceInUseError, ResourceNotFoundError
|
||||||
from libcloud.compute.drivers.gce import GCEAddress
|
from libcloud.compute.drivers.gce import GCEAddress
|
||||||
|
|
||||||
_ = Provider.GCE
|
_ = Provider.GCE
|
||||||
HAS_LIBCLOUD = True
|
HAS_LIBCLOUD = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -378,7 +379,7 @@ def get_instance_info(inst):
|
||||||
else:
|
else:
|
||||||
public_ip = inst.public_ips[0]
|
public_ip = inst.public_ips[0]
|
||||||
|
|
||||||
return({
|
return ({
|
||||||
'image': inst.image is not None and inst.image.split('/')[-1] or None,
|
'image': inst.image is not None and inst.image.split('/')[-1] or None,
|
||||||
'disks': disk_names,
|
'disks': disk_names,
|
||||||
'machine_type': inst.size,
|
'machine_type': inst.size,
|
||||||
|
@ -553,7 +554,7 @@ def create_instances(module, gce, instance_names, number, lc_zone):
|
||||||
changed = True
|
changed = True
|
||||||
except GoogleBaseError as e:
|
except GoogleBaseError as e:
|
||||||
module.fail_json(msg='Unexpected error attempting to create ' +
|
module.fail_json(msg='Unexpected error attempting to create ' +
|
||||||
'instance %s, error: %s' % (instance, e.value))
|
'instance %s, error: %s' % (instance, e.value))
|
||||||
if inst:
|
if inst:
|
||||||
new_instances.append(inst)
|
new_instances.append(inst)
|
||||||
|
|
||||||
|
@ -576,7 +577,7 @@ def create_instances(module, gce, instance_names, number, lc_zone):
|
||||||
# Work around libcloud bug: attached volumes don't get added
|
# Work around libcloud bug: attached volumes don't get added
|
||||||
# to the instance metadata. get_instance_info() only cares about
|
# to the instance metadata. get_instance_info() only cares about
|
||||||
# source and index.
|
# source and index.
|
||||||
if len(inst.extra['disks']) != i+1:
|
if len(inst.extra['disks']) != i + 1:
|
||||||
inst.extra['disks'].append(
|
inst.extra['disks'].append(
|
||||||
{'source': lc_disk.extra['selfLink'], 'index': i})
|
{'source': lc_disk.extra['selfLink'], 'index': i})
|
||||||
|
|
||||||
|
@ -589,6 +590,7 @@ def create_instances(module, gce, instance_names, number, lc_zone):
|
||||||
|
|
||||||
return (changed, instance_json_data, instance_names)
|
return (changed, instance_json_data, instance_names)
|
||||||
|
|
||||||
|
|
||||||
def change_instance_state(module, gce, instance_names, number, zone, state):
|
def change_instance_state(module, gce, instance_names, number, zone, state):
|
||||||
"""Changes the state of a list of instances. For example,
|
"""Changes the state of a list of instances. For example,
|
||||||
change from started to stopped, or started to absent.
|
change from started to stopped, or started to absent.
|
||||||
|
@ -633,47 +635,46 @@ def change_instance_state(module, gce, instance_names, number, zone, state):
|
||||||
if state in ['absent', 'deleted']:
|
if state in ['absent', 'deleted']:
|
||||||
gce.destroy_node(node)
|
gce.destroy_node(node)
|
||||||
changed = True
|
changed = True
|
||||||
elif state == 'started' and \
|
elif state == 'started' and node.state == libcloud.compute.types.NodeState.STOPPED:
|
||||||
node.state == libcloud.compute.types.NodeState.STOPPED:
|
|
||||||
gce.ex_start_node(node)
|
gce.ex_start_node(node)
|
||||||
changed = True
|
changed = True
|
||||||
elif state in ['stopped', 'terminated'] and \
|
elif state in ['stopped', 'terminated'] and node.state == libcloud.compute.types.NodeState.RUNNING:
|
||||||
node.state == libcloud.compute.types.NodeState.RUNNING:
|
|
||||||
gce.ex_stop_node(node)
|
gce.ex_stop_node(node)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
return (changed, state_instance_names)
|
return (changed, state_instance_names)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
image = dict(default='debian-8'),
|
image=dict(default='debian-8'),
|
||||||
image_family = dict(),
|
image_family=dict(),
|
||||||
external_projects = dict(type='list'),
|
external_projects=dict(type='list'),
|
||||||
instance_names = dict(),
|
instance_names=dict(),
|
||||||
machine_type = dict(default='n1-standard-1'),
|
machine_type=dict(default='n1-standard-1'),
|
||||||
metadata = dict(),
|
metadata=dict(),
|
||||||
name = dict(aliases=['base_name']),
|
name=dict(aliases=['base_name']),
|
||||||
num_instances = dict(type='int'),
|
num_instances=dict(type='int'),
|
||||||
network = dict(default='default'),
|
network=dict(default='default'),
|
||||||
subnetwork = dict(),
|
subnetwork=dict(),
|
||||||
persistent_boot_disk = dict(type='bool', default=False),
|
persistent_boot_disk=dict(type='bool', default=False),
|
||||||
disks = dict(type='list'),
|
disks=dict(type='list'),
|
||||||
state = dict(choices=['active', 'present', 'absent', 'deleted',
|
state=dict(choices=['active', 'present', 'absent', 'deleted',
|
||||||
'started', 'stopped', 'terminated'],
|
'started', 'stopped', 'terminated'],
|
||||||
default='present'),
|
default='present'),
|
||||||
tags = dict(type='list'),
|
tags=dict(type='list'),
|
||||||
zone = dict(default='us-central1-a'),
|
zone=dict(default='us-central1-a'),
|
||||||
service_account_email = dict(),
|
service_account_email=dict(),
|
||||||
service_account_permissions = dict(type='list'),
|
service_account_permissions=dict(type='list'),
|
||||||
pem_file = dict(type='path'),
|
pem_file=dict(type='path'),
|
||||||
credentials_file = dict(type='path'),
|
credentials_file=dict(type='path'),
|
||||||
project_id = dict(),
|
project_id=dict(),
|
||||||
ip_forward = dict(type='bool', default=False),
|
ip_forward=dict(type='bool', default=False),
|
||||||
external_ip=dict(default='ephemeral'),
|
external_ip=dict(default='ephemeral'),
|
||||||
disk_auto_delete = dict(type='bool', default=True),
|
disk_auto_delete=dict(type='bool', default=True),
|
||||||
disk_size = dict(type='int', default=10),
|
disk_size=dict(type='int', default=10),
|
||||||
preemptible = dict(type='bool', default=None),
|
preemptible=dict(type='bool', default=None),
|
||||||
),
|
),
|
||||||
mutually_exclusive=[('instance_names', 'name')]
|
mutually_exclusive=[('instance_names', 'name')]
|
||||||
)
|
)
|
||||||
|
@ -751,6 +752,7 @@ class LazyDiskImage:
|
||||||
Object for lazy instantiation of disk image
|
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.
|
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):
|
def __init__(self, module, gce, name, has_pd, family=None, projects=None):
|
||||||
self.image = None
|
self.image = None
|
||||||
self.was_called = False
|
self.was_called = False
|
||||||
|
|
|
@ -122,6 +122,7 @@ def get_address(gce, name, region):
|
||||||
except ResourceNotFoundError:
|
except ResourceNotFoundError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def create_address(gce, params):
|
def create_address(gce, params):
|
||||||
"""
|
"""
|
||||||
Create a new Address.
|
Create a new Address.
|
||||||
|
@ -147,6 +148,7 @@ def create_address(gce, params):
|
||||||
|
|
||||||
return (changed, return_data)
|
return (changed, return_data)
|
||||||
|
|
||||||
|
|
||||||
def delete_address(address):
|
def delete_address(address):
|
||||||
"""
|
"""
|
||||||
Delete an Address.
|
Delete an Address.
|
||||||
|
@ -167,6 +169,7 @@ def delete_address(address):
|
||||||
return_data = address.address
|
return_data = address.address
|
||||||
return (changed, return_data)
|
return (changed, return_data)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(argument_spec=dict(
|
module = AnsibleModule(argument_spec=dict(
|
||||||
name=dict(required=True),
|
name=dict(required=True),
|
||||||
|
|
|
@ -157,8 +157,8 @@ try:
|
||||||
from libcloud.compute.providers import get_driver
|
from libcloud.compute.providers import get_driver
|
||||||
from libcloud.loadbalancer.types import Provider as Provider_lb
|
from libcloud.loadbalancer.types import Provider as Provider_lb
|
||||||
from libcloud.loadbalancer.providers import get_driver as get_driver_lb
|
from libcloud.loadbalancer.providers import get_driver as get_driver_lb
|
||||||
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError
|
||||||
ResourceExistsError, ResourceNotFoundError
|
|
||||||
_ = Provider.GCE
|
_ = Provider.GCE
|
||||||
HAS_LIBCLOUD = True
|
HAS_LIBCLOUD = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -170,26 +170,26 @@ from ansible.module_utils.gce import USER_AGENT_PRODUCT, USER_AGENT_VERSION, gce
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
httphealthcheck_name = dict(),
|
httphealthcheck_name=dict(),
|
||||||
httphealthcheck_port = dict(default=80),
|
httphealthcheck_port=dict(default=80),
|
||||||
httphealthcheck_path = dict(default='/'),
|
httphealthcheck_path=dict(default='/'),
|
||||||
httphealthcheck_interval = dict(default=5),
|
httphealthcheck_interval=dict(default=5),
|
||||||
httphealthcheck_timeout = dict(default=5),
|
httphealthcheck_timeout=dict(default=5),
|
||||||
httphealthcheck_unhealthy_count = dict(default=2),
|
httphealthcheck_unhealthy_count=dict(default=2),
|
||||||
httphealthcheck_healthy_count = dict(default=2),
|
httphealthcheck_healthy_count=dict(default=2),
|
||||||
httphealthcheck_host = dict(),
|
httphealthcheck_host=dict(),
|
||||||
name = dict(),
|
name=dict(),
|
||||||
protocol = dict(default='tcp'),
|
protocol=dict(default='tcp'),
|
||||||
region = dict(),
|
region=dict(),
|
||||||
external_ip = dict(),
|
external_ip=dict(),
|
||||||
port_range = dict(),
|
port_range=dict(),
|
||||||
members = dict(type='list'),
|
members=dict(type='list'),
|
||||||
state = dict(default='present'),
|
state=dict(default='present'),
|
||||||
service_account_email = dict(),
|
service_account_email=dict(),
|
||||||
pem_file = dict(type='path'),
|
pem_file=dict(type='path'),
|
||||||
credentials_file = dict(type='path'),
|
credentials_file=dict(type='path'),
|
||||||
project_id = dict(),
|
project_id=dict(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -203,10 +203,8 @@ def main():
|
||||||
httphealthcheck_path = module.params.get('httphealthcheck_path')
|
httphealthcheck_path = module.params.get('httphealthcheck_path')
|
||||||
httphealthcheck_interval = module.params.get('httphealthcheck_interval')
|
httphealthcheck_interval = module.params.get('httphealthcheck_interval')
|
||||||
httphealthcheck_timeout = module.params.get('httphealthcheck_timeout')
|
httphealthcheck_timeout = module.params.get('httphealthcheck_timeout')
|
||||||
httphealthcheck_unhealthy_count = \
|
httphealthcheck_unhealthy_count = module.params.get('httphealthcheck_unhealthy_count')
|
||||||
module.params.get('httphealthcheck_unhealthy_count')
|
httphealthcheck_healthy_count = module.params.get('httphealthcheck_healthy_count')
|
||||||
httphealthcheck_healthy_count = \
|
|
||||||
module.params.get('httphealthcheck_healthy_count')
|
|
||||||
httphealthcheck_host = module.params.get('httphealthcheck_host')
|
httphealthcheck_host = module.params.get('httphealthcheck_host')
|
||||||
name = module.params.get('name')
|
name = module.params.get('name')
|
||||||
protocol = module.params.get('protocol')
|
protocol = module.params.get('protocol')
|
||||||
|
@ -227,8 +225,7 @@ def main():
|
||||||
json_output = {'name': name, 'state': state}
|
json_output = {'name': name, 'state': state}
|
||||||
|
|
||||||
if not name and not httphealthcheck_name:
|
if not name and not httphealthcheck_name:
|
||||||
module.fail_json(msg='Nothing to do, please specify a "name" ' + \
|
module.fail_json(msg='Nothing to do, please specify a "name" ' + 'or "httphealthcheck_name" parameter', changed=False)
|
||||||
'or "httphealthcheck_name" parameter', changed=False)
|
|
||||||
|
|
||||||
if state in ['active', 'present']:
|
if state in ['active', 'present']:
|
||||||
# first, create the httphealthcheck if requested
|
# first, create the httphealthcheck if requested
|
||||||
|
@ -237,12 +234,12 @@ def main():
|
||||||
json_output['httphealthcheck_name'] = httphealthcheck_name
|
json_output['httphealthcheck_name'] = httphealthcheck_name
|
||||||
try:
|
try:
|
||||||
hc = gcelb.ex_create_healthcheck(httphealthcheck_name,
|
hc = gcelb.ex_create_healthcheck(httphealthcheck_name,
|
||||||
host=httphealthcheck_host, path=httphealthcheck_path,
|
host=httphealthcheck_host, path=httphealthcheck_path,
|
||||||
port=httphealthcheck_port,
|
port=httphealthcheck_port,
|
||||||
interval=httphealthcheck_interval,
|
interval=httphealthcheck_interval,
|
||||||
timeout=httphealthcheck_timeout,
|
timeout=httphealthcheck_timeout,
|
||||||
unhealthy_threshold=httphealthcheck_unhealthy_count,
|
unhealthy_threshold=httphealthcheck_unhealthy_count,
|
||||||
healthy_threshold=httphealthcheck_healthy_count)
|
healthy_threshold=httphealthcheck_healthy_count)
|
||||||
changed = True
|
changed = True
|
||||||
except ResourceExistsError:
|
except ResourceExistsError:
|
||||||
hc = gce.ex_get_healthcheck(httphealthcheck_name)
|
hc = gce.ex_get_healthcheck(httphealthcheck_name)
|
||||||
|
@ -255,17 +252,15 @@ def main():
|
||||||
json_output['httphealthcheck_port'] = hc.port
|
json_output['httphealthcheck_port'] = hc.port
|
||||||
json_output['httphealthcheck_interval'] = hc.interval
|
json_output['httphealthcheck_interval'] = hc.interval
|
||||||
json_output['httphealthcheck_timeout'] = hc.timeout
|
json_output['httphealthcheck_timeout'] = hc.timeout
|
||||||
json_output['httphealthcheck_unhealthy_count'] = \
|
json_output['httphealthcheck_unhealthy_count'] = hc.unhealthy_threshold
|
||||||
hc.unhealthy_threshold
|
json_output['httphealthcheck_healthy_count'] = hc.healthy_threshold
|
||||||
json_output['httphealthcheck_healthy_count'] = \
|
|
||||||
hc.healthy_threshold
|
|
||||||
|
|
||||||
# create the forwarding rule (and target pool under the hood)
|
# create the forwarding rule (and target pool under the hood)
|
||||||
lb = None
|
lb = None
|
||||||
if name:
|
if name:
|
||||||
if not region:
|
if not region:
|
||||||
module.fail_json(msg='Missing required region name',
|
module.fail_json(msg='Missing required region name',
|
||||||
changed=False)
|
changed=False)
|
||||||
nodes = []
|
nodes = []
|
||||||
output_nodes = []
|
output_nodes = []
|
||||||
json_output['name'] = name
|
json_output['name'] = name
|
||||||
|
@ -282,11 +277,11 @@ def main():
|
||||||
try:
|
try:
|
||||||
if hc is not None:
|
if hc is not None:
|
||||||
lb = gcelb.create_balancer(name, port_range, protocol,
|
lb = gcelb.create_balancer(name, port_range, protocol,
|
||||||
None, nodes, ex_region=region, ex_healthchecks=[hc],
|
None, nodes, ex_region=region, ex_healthchecks=[hc],
|
||||||
ex_address=external_ip)
|
ex_address=external_ip)
|
||||||
else:
|
else:
|
||||||
lb = gcelb.create_balancer(name, port_range, protocol,
|
lb = gcelb.create_balancer(name, port_range, protocol,
|
||||||
None, nodes, ex_region=region, ex_address=external_ip)
|
None, nodes, ex_region=region, ex_address=external_ip)
|
||||||
changed = True
|
changed = True
|
||||||
except ResourceExistsError:
|
except ResourceExistsError:
|
||||||
lb = gcelb.get_balancer(name)
|
lb = gcelb.get_balancer(name)
|
||||||
|
@ -331,7 +326,6 @@ def main():
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
module.fail_json(msg=unexpected_error_msg(e), changed=False)
|
||||||
|
|
||||||
|
|
||||||
json_output['changed'] = changed
|
json_output['changed'] = changed
|
||||||
module.exit_json(**json_output)
|
module.exit_json(**json_output)
|
||||||
|
|
||||||
|
|
|
@ -339,7 +339,7 @@ def _validate_autoscaling_params(params):
|
||||||
{'name': 'name', 'required': True, 'type': str},
|
{'name': 'name', 'required': True, 'type': str},
|
||||||
{'name': 'enabled', 'required': True, 'type': bool},
|
{'name': 'enabled', 'required': True, 'type': bool},
|
||||||
{'name': 'policy', 'required': True, 'type': dict}
|
{'name': 'policy', 'required': True, 'type': dict}
|
||||||
] # yapf: disable
|
] # yapf: disable
|
||||||
|
|
||||||
(as_req_valid, as_req_msg) = _check_params(params['autoscaling'],
|
(as_req_valid, as_req_msg) = _check_params(params['autoscaling'],
|
||||||
as_req_fields)
|
as_req_fields)
|
||||||
|
@ -351,7 +351,7 @@ def _validate_autoscaling_params(params):
|
||||||
{'name': 'max_instances', 'required': True, 'type': int},
|
{'name': 'max_instances', 'required': True, 'type': int},
|
||||||
{'name': 'min_instances', 'required': False, 'type': int},
|
{'name': 'min_instances', 'required': False, 'type': int},
|
||||||
{'name': 'cool_down_period', 'required': False, 'type': int}
|
{'name': 'cool_down_period', 'required': False, 'type': int}
|
||||||
] # yapf: disable
|
] # yapf: disable
|
||||||
|
|
||||||
(as_policy_valid, as_policy_msg) = _check_params(
|
(as_policy_valid, as_policy_msg) = _check_params(
|
||||||
params['autoscaling']['policy'], as_policy_fields)
|
params['autoscaling']['policy'], as_policy_fields)
|
||||||
|
@ -385,7 +385,7 @@ def _validate_named_port_params(params):
|
||||||
req_fields = [
|
req_fields = [
|
||||||
{'name': 'name', 'required': True, 'type': str},
|
{'name': 'name', 'required': True, 'type': str},
|
||||||
{'name': 'port', 'required': True, 'type': int}
|
{'name': 'port', 'required': True, 'type': int}
|
||||||
] # yapf: disable
|
] # yapf: disable
|
||||||
|
|
||||||
for np in params['named_ports']:
|
for np in params['named_ports']:
|
||||||
(valid_named_ports, np_msg) = _check_params(np, req_fields)
|
(valid_named_ports, np_msg) = _check_params(np, req_fields)
|
||||||
|
@ -772,7 +772,7 @@ def main():
|
||||||
req_create_fields = [
|
req_create_fields = [
|
||||||
{'name': 'template', 'required': True, 'type': str},
|
{'name': 'template', 'required': True, 'type': str},
|
||||||
{'name': 'size', 'required': True, 'type': int}
|
{'name': 'size', 'required': True, 'type': int}
|
||||||
] # yapf: disable
|
] # yapf: disable
|
||||||
|
|
||||||
(valid_create_fields, valid_create_msg) = _check_params(
|
(valid_create_fields, valid_create_msg) = _check_params(
|
||||||
params, req_create_fields)
|
params, req_create_fields)
|
||||||
|
|
|
@ -264,8 +264,7 @@ target_tags:
|
||||||
try:
|
try:
|
||||||
from libcloud.compute.types import Provider
|
from libcloud.compute.types import Provider
|
||||||
from libcloud.compute.providers import get_driver
|
from libcloud.compute.providers import get_driver
|
||||||
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError
|
||||||
ResourceExistsError, ResourceNotFoundError
|
|
||||||
_ = Provider.GCE
|
_ = Provider.GCE
|
||||||
HAS_LIBCLOUD = True
|
HAS_LIBCLOUD = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -293,6 +292,7 @@ def format_allowed_section(allowed):
|
||||||
return_val["ports"] = ports
|
return_val["ports"] = ports
|
||||||
return return_val
|
return return_val
|
||||||
|
|
||||||
|
|
||||||
def format_allowed(allowed):
|
def format_allowed(allowed):
|
||||||
"""Format the 'allowed' value so that it is GCE compatible."""
|
"""Format the 'allowed' value so that it is GCE compatible."""
|
||||||
return_value = []
|
return_value = []
|
||||||
|
@ -304,33 +304,34 @@ def format_allowed(allowed):
|
||||||
return_value.append(format_allowed_section(section))
|
return_value.append(format_allowed_section(section))
|
||||||
return return_value
|
return return_value
|
||||||
|
|
||||||
|
|
||||||
def sorted_allowed_list(allowed_list):
|
def sorted_allowed_list(allowed_list):
|
||||||
"""Sort allowed_list (output of format_allowed) by protocol and port."""
|
"""Sort allowed_list (output of format_allowed) by protocol and port."""
|
||||||
# sort by protocol
|
# sort by protocol
|
||||||
allowed_by_protocol = sorted(allowed_list,key=lambda x: x['IPProtocol'])
|
allowed_by_protocol = sorted(allowed_list, key=lambda x: x['IPProtocol'])
|
||||||
# sort the ports list
|
# sort the ports list
|
||||||
return sorted(allowed_by_protocol, key=lambda y: y.get('ports', []).sort())
|
return sorted(allowed_by_protocol, key=lambda y: y.get('ports', []).sort())
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
allowed = dict(),
|
allowed=dict(),
|
||||||
ipv4_range = dict(),
|
ipv4_range=dict(),
|
||||||
fwname = dict(),
|
fwname=dict(),
|
||||||
name = dict(),
|
name=dict(),
|
||||||
src_range = dict(default=[], type='list'),
|
src_range=dict(default=[], type='list'),
|
||||||
src_tags = dict(default=[], type='list'),
|
src_tags=dict(default=[], type='list'),
|
||||||
target_tags = dict(default=[], type='list'),
|
target_tags=dict(default=[], type='list'),
|
||||||
state = dict(default='present'),
|
state=dict(default='present'),
|
||||||
service_account_email = dict(),
|
service_account_email=dict(),
|
||||||
pem_file = dict(type='path'),
|
pem_file=dict(type='path'),
|
||||||
credentials_file = dict(type='path'),
|
credentials_file=dict(type='path'),
|
||||||
project_id = dict(),
|
project_id=dict(),
|
||||||
mode = dict(default='legacy', choices=['legacy', 'auto', 'custom']),
|
mode=dict(default='legacy', choices=['legacy', 'auto', 'custom']),
|
||||||
subnet_name = dict(),
|
subnet_name=dict(),
|
||||||
subnet_region = dict(),
|
subnet_region=dict(),
|
||||||
subnet_desc = dict(),
|
subnet_desc=dict(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -379,8 +380,8 @@ def main():
|
||||||
if name and not network:
|
if name and not network:
|
||||||
if not ipv4_range and mode != 'auto':
|
if not ipv4_range and mode != 'auto':
|
||||||
module.fail_json(msg="Network '" + name + "' is not found. To create network in legacy or custom mode, 'ipv4_range' parameter is required",
|
module.fail_json(msg="Network '" + name + "' is not found. To create network in legacy or custom mode, 'ipv4_range' parameter is required",
|
||||||
changed=False)
|
changed=False)
|
||||||
args = [ipv4_range if mode =='legacy' else None]
|
args = [ipv4_range if mode == 'legacy' else None]
|
||||||
kwargs = {}
|
kwargs = {}
|
||||||
if mode != 'legacy':
|
if mode != 'legacy':
|
||||||
kwargs['mode'] = mode
|
kwargs['mode'] = mode
|
||||||
|
@ -414,8 +415,7 @@ def main():
|
||||||
if not allowed and not src_range and not src_tags:
|
if not allowed and not src_range and not src_tags:
|
||||||
if changed and network:
|
if changed and network:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg="Network created, but missing required " + \
|
msg="Network created, but missing required " + "firewall rule parameter(s)", changed=True)
|
||||||
"firewall rule parameter(s)", changed=True)
|
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
msg="Missing required firewall rule parameter(s)",
|
msg="Missing required firewall rule parameter(s)",
|
||||||
changed=False)
|
changed=False)
|
||||||
|
@ -484,7 +484,7 @@ def main():
|
||||||
except ResourceNotFoundError:
|
except ResourceNotFoundError:
|
||||||
try:
|
try:
|
||||||
gce.ex_create_firewall(fwname, allowed_list, network=name,
|
gce.ex_create_firewall(fwname, allowed_list, network=name,
|
||||||
source_ranges=src_range, source_tags=src_tags, target_tags=target_tags)
|
source_ranges=src_range, source_tags=src_tags, target_tags=target_tags)
|
||||||
changed = True
|
changed = True
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
|
@ -144,8 +144,7 @@ EXAMPLES = '''
|
||||||
try:
|
try:
|
||||||
from libcloud.compute.types import Provider
|
from libcloud.compute.types import Provider
|
||||||
from libcloud.compute.providers import get_driver
|
from libcloud.compute.providers import get_driver
|
||||||
from libcloud.common.google import GoogleBaseError, QuotaExceededError, \
|
from libcloud.common.google import GoogleBaseError, QuotaExceededError, ResourceExistsError, ResourceNotFoundError, ResourceInUseError
|
||||||
ResourceExistsError, ResourceNotFoundError, ResourceInUseError
|
|
||||||
_ = Provider.GCE
|
_ = Provider.GCE
|
||||||
HAS_LIBCLOUD = True
|
HAS_LIBCLOUD = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
|
@ -157,24 +156,24 @@ from ansible.module_utils.gce import gce_connect, unexpected_error_msg
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec=dict(
|
||||||
delete_on_termination = dict(type='bool'),
|
delete_on_termination=dict(type='bool'),
|
||||||
detach_only = dict(type='bool'),
|
detach_only=dict(type='bool'),
|
||||||
instance_name = dict(),
|
instance_name=dict(),
|
||||||
mode = dict(default='READ_ONLY', choices=['READ_WRITE', 'READ_ONLY']),
|
mode=dict(default='READ_ONLY', choices=['READ_WRITE', 'READ_ONLY']),
|
||||||
name = dict(required=True),
|
name=dict(required=True),
|
||||||
size_gb = dict(default=10),
|
size_gb=dict(default=10),
|
||||||
disk_type = dict(default='pd-standard'),
|
disk_type=dict(default='pd-standard'),
|
||||||
image = dict(),
|
image=dict(),
|
||||||
image_family = dict(),
|
image_family=dict(),
|
||||||
external_projects = dict(type='list'),
|
external_projects=dict(type='list'),
|
||||||
snapshot = dict(),
|
snapshot=dict(),
|
||||||
state = dict(default='present'),
|
state=dict(default='present'),
|
||||||
zone = dict(default='us-central1-b'),
|
zone=dict(default='us-central1-b'),
|
||||||
service_account_email = dict(),
|
service_account_email=dict(),
|
||||||
pem_file = dict(type='path'),
|
pem_file=dict(type='path'),
|
||||||
credentials_file = dict(type='path'),
|
credentials_file=dict(type='path'),
|
||||||
project_id = dict(),
|
project_id=dict(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if not HAS_LIBCLOUD:
|
if not HAS_LIBCLOUD:
|
||||||
|
@ -209,7 +208,7 @@ def main():
|
||||||
disk = inst = None
|
disk = inst = None
|
||||||
changed = is_attached = False
|
changed = is_attached = False
|
||||||
|
|
||||||
json_output = { 'name': name, 'zone': zone, 'state': state, 'disk_type': disk_type }
|
json_output = {'name': name, 'zone': zone, 'state': state, 'disk_type': disk_type}
|
||||||
if detach_only:
|
if detach_only:
|
||||||
json_output['detach_only'] = True
|
json_output['detach_only'] = True
|
||||||
json_output['detached_from_instance'] = instance_name
|
json_output['detached_from_instance'] = instance_name
|
||||||
|
@ -248,7 +247,7 @@ def main():
|
||||||
raise Exception
|
raise Exception
|
||||||
except:
|
except:
|
||||||
module.fail_json(msg="Must supply a size_gb larger than 1 GB",
|
module.fail_json(msg="Must supply a size_gb larger than 1 GB",
|
||||||
changed=False)
|
changed=False)
|
||||||
|
|
||||||
if instance_name and inst is None:
|
if instance_name and inst is None:
|
||||||
module.fail_json(msg='Instance %s does not exist in zone %s' % (
|
module.fail_json(msg='Instance %s does not exist in zone %s' % (
|
||||||
|
@ -275,7 +274,7 @@ def main():
|
||||||
pass
|
pass
|
||||||
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 as 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
|
||||||
|
|
|
@ -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/gc_storage.py
|
||||||
lib/ansible/modules/cloud/google/gcdns_record.py
|
lib/ansible/modules/cloud/google/gcdns_record.py
|
||||||
lib/ansible/modules/cloud/google/gcdns_zone.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/gce_tag.py
|
||||||
lib/ansible/modules/cloud/google/gcpubsub.py
|
lib/ansible/modules/cloud/google/gcpubsub.py
|
||||||
lib/ansible/modules/cloud/google/gcspanner.py
|
lib/ansible/modules/cloud/google/gcspanner.py
|
||||||
|
|
Loading…
Reference in a new issue