Bug fixes for GCP modules (as of 2019-01-22T12:43:52-08:00) (#51246)
This commit is contained in:
parent
2836c8c897
commit
395fbce194
24 changed files with 419 additions and 622 deletions
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -212,7 +211,7 @@ def main():
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
profile=dict(type='str', choices=['COMPATIBLE', 'MODERN', 'RESTRICTED', 'CUSTOM']),
|
profile=dict(type='str', choices=['COMPATIBLE', 'MODERN', 'RESTRICTED', 'CUSTOM']),
|
||||||
min_tls_version=dict(type='str', choices=['TLS_1_0', 'TLS_1_1', 'TLS_1_2']),
|
min_tls_version=dict(type='str', choices=['TLS_1_0', 'TLS_1_1', 'TLS_1_2']),
|
||||||
custom_features=dict(type='list', elements='str')
|
custom_features=dict(type='list', elements='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -269,7 +268,7 @@ def resource_to_request(module):
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'profile': module.params.get('profile'),
|
u'profile': module.params.get('profile'),
|
||||||
u'minTlsVersion': module.params.get('min_tls_version'),
|
u'minTlsVersion': module.params.get('min_tls_version'),
|
||||||
u'customFeatures': module.params.get('custom_features')
|
u'customFeatures': module.params.get('custom_features'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -304,8 +303,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -344,7 +343,7 @@ def response_to_hash(module, response):
|
||||||
u'enabledFeatures': response.get(u'enabledFeatures'),
|
u'enabledFeatures': response.get(u'enabledFeatures'),
|
||||||
u'customFeatures': response.get(u'customFeatures'),
|
u'customFeatures': response.get(u'customFeatures'),
|
||||||
u'fingerprint': response.get(u'fingerprint'),
|
u'fingerprint': response.get(u'fingerprint'),
|
||||||
u'warnings': SslPolicyWarningsArray(response.get(u'warnings', []), module).from_response()
|
u'warnings': SslPolicyWarningsArray(response.get(u'warnings', []), module).from_response(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -370,7 +369,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
@ -404,16 +403,10 @@ class SslPolicyWarningsArray(object):
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'code': item.get('code'), u'message': item.get('message')})
|
||||||
u'code': item.get('code'),
|
|
||||||
u'message': item.get('message')
|
|
||||||
})
|
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'code': item.get(u'code'), u'message': item.get(u'message')})
|
||||||
u'code': item.get(u'code'),
|
|
||||||
u'message': item.get(u'message')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -154,11 +153,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -168,9 +163,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -279,12 +278,11 @@ def main():
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
network=dict(required=True),
|
network=dict(required=True),
|
||||||
enable_flow_logs=dict(type='bool'),
|
enable_flow_logs=dict(type='bool'),
|
||||||
secondary_ip_ranges=dict(type='list', elements='dict', options=dict(
|
secondary_ip_ranges=dict(
|
||||||
range_name=dict(required=True, type='str'),
|
type='list', elements='dict', options=dict(range_name=dict(required=True, type='str'), ip_cidr_range=dict(required=True, type='str'))
|
||||||
ip_cidr_range=dict(required=True, type='str')
|
),
|
||||||
)),
|
|
||||||
private_ip_google_access=dict(type='bool'),
|
private_ip_google_access=dict(type='bool'),
|
||||||
region=dict(required=True, type='str')
|
region=dict(required=True, type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -325,8 +323,7 @@ def create(module, link, kind):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind, fetch):
|
||||||
update_fields(module, resource_to_request(module),
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
response_to_hash(module, fetch))
|
|
||||||
return fetch_resource(module, self_link(module), kind)
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
@ -342,41 +339,30 @@ def update_fields(module, request, response):
|
||||||
def ip_cidr_range_update(module, request, response):
|
def ip_cidr_range_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/subnetworks/{name}/expandIpCidrRange"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'ipCidrRange': module.params.get('ip_cidr_range')},
|
||||||
"projects/{project}/regions/{region}/subnetworks/{name}/expandIpCidrRange"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'ipCidrRange': module.params.get('ip_cidr_range')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def enable_flow_logs_update(module, request, response):
|
def enable_flow_logs_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.patch(
|
auth.patch(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/subnetworks/{name}"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
|
||||||
"projects/{project}/regions/{region}/subnetworks/{name}"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
{
|
||||||
u'enableFlowLogs': module.params.get('enable_flow_logs'),
|
u'enableFlowLogs': module.params.get('enable_flow_logs'),
|
||||||
u'fingerprint': response.get('fingerprint'),
|
u'fingerprint': response.get('fingerprint'),
|
||||||
u'secondaryIpRanges': SubnetworkSecondaryiprangesArray(module.params.get('secondary_ip_ranges', []), module).to_request()
|
u'secondaryIpRanges': SubnetworkSecondaryiprangesArray(module.params.get('secondary_ip_ranges', []), module).to_request(),
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def private_ip_google_access_update(module, request, response):
|
def private_ip_google_access_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/subnetworks/{name}/setPrivateIpGoogleAccess"]).format(
|
||||||
"https://www.googleapis.com/compute/v1/",
|
**module.params
|
||||||
"projects/{project}/regions/{region}/subnetworks/{name}/setPrivateIpGoogleAccess"
|
),
|
||||||
]).format(**module.params),
|
{u'privateIpGoogleAccess': module.params.get('private_ip_google_access')},
|
||||||
{
|
|
||||||
u'privateIpGoogleAccess': module.params.get('private_ip_google_access')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -395,7 +381,7 @@ def resource_to_request(module):
|
||||||
u'enableFlowLogs': module.params.get('enable_flow_logs'),
|
u'enableFlowLogs': module.params.get('enable_flow_logs'),
|
||||||
u'secondaryIpRanges': SubnetworkSecondaryiprangesArray(module.params.get('secondary_ip_ranges', []), module).to_request(),
|
u'secondaryIpRanges': SubnetworkSecondaryiprangesArray(module.params.get('secondary_ip_ranges', []), module).to_request(),
|
||||||
u'privateIpGoogleAccess': module.params.get('private_ip_google_access'),
|
u'privateIpGoogleAccess': module.params.get('private_ip_google_access'),
|
||||||
u'region': module.params.get('region')
|
u'region': module.params.get('region'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -430,8 +416,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -472,7 +458,7 @@ def response_to_hash(module, response):
|
||||||
u'fingerprint': response.get(u'fingerprint'),
|
u'fingerprint': response.get(u'fingerprint'),
|
||||||
u'secondaryIpRanges': SubnetworkSecondaryiprangesArray(response.get(u'secondaryIpRanges', []), module).from_response(),
|
u'secondaryIpRanges': SubnetworkSecondaryiprangesArray(response.get(u'secondaryIpRanges', []), module).from_response(),
|
||||||
u'privateIpGoogleAccess': response.get(u'privateIpGoogleAccess'),
|
u'privateIpGoogleAccess': response.get(u'privateIpGoogleAccess'),
|
||||||
u'region': module.params.get('region')
|
u'region': module.params.get('region'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -498,7 +484,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
@ -532,16 +518,10 @@ class SubnetworkSecondaryiprangesArray(object):
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'rangeName': item.get('range_name'), u'ipCidrRange': item.get('ip_cidr_range')})
|
||||||
u'rangeName': item.get('range_name'),
|
|
||||||
u'ipCidrRange': item.get('ip_cidr_range')
|
|
||||||
})
|
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'rangeName': item.get(u'rangeName'), u'ipCidrRange': item.get(u'ipCidrRange')})
|
||||||
u'rangeName': item.get(u'rangeName'),
|
|
||||||
u'ipCidrRange': item.get(u'ipCidrRange')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -176,12 +175,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str'),
|
|
||||||
region=dict(required=True, type='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -191,9 +185,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -189,7 +188,7 @@ def main():
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
url_map=dict(required=True)
|
url_map=dict(required=True),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -230,8 +229,7 @@ def create(module, link, kind):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind, fetch):
|
||||||
update_fields(module, resource_to_request(module),
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
response_to_hash(module, fetch))
|
|
||||||
return fetch_resource(module, self_link(module), kind)
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
@ -243,13 +241,8 @@ def update_fields(module, request, response):
|
||||||
def url_map_update(module, request, response):
|
def url_map_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/targetHttpProxies/{name}/setUrlMap"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')},
|
||||||
"projects/{project}/targetHttpProxies/{name}/setUrlMap"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,7 +256,7 @@ def resource_to_request(module):
|
||||||
u'kind': 'compute#targetHttpProxy',
|
u'kind': 'compute#targetHttpProxy',
|
||||||
u'description': module.params.get('description'),
|
u'description': module.params.get('description'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')
|
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -298,8 +291,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -333,7 +326,7 @@ def response_to_hash(module, response):
|
||||||
u'description': response.get(u'description'),
|
u'description': response.get(u'description'),
|
||||||
u'id': response.get(u'id'),
|
u'id': response.get(u'id'),
|
||||||
u'name': response.get(u'name'),
|
u'name': response.get(u'name'),
|
||||||
u'urlMap': response.get(u'urlMap')
|
u'urlMap': response.get(u'urlMap'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -359,7 +352,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -110,11 +109,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -124,9 +119,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -280,7 +279,7 @@ def main():
|
||||||
quic_override=dict(type='str', choices=['NONE', 'ENABLE', 'DISABLE']),
|
quic_override=dict(type='str', choices=['NONE', 'ENABLE', 'DISABLE']),
|
||||||
ssl_certificates=dict(required=True, type='list'),
|
ssl_certificates=dict(required=True, type='list'),
|
||||||
ssl_policy=dict(),
|
ssl_policy=dict(),
|
||||||
url_map=dict(required=True)
|
url_map=dict(required=True),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -321,8 +320,7 @@ def create(module, link, kind):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind, fetch):
|
||||||
update_fields(module, resource_to_request(module),
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
response_to_hash(module, fetch))
|
|
||||||
return fetch_resource(module, self_link(module), kind)
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
@ -340,52 +338,32 @@ def update_fields(module, request, response):
|
||||||
def quic_override_update(module, request, response):
|
def quic_override_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetHttpsProxies/{name}/setQuicOverride"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'quicOverride': module.params.get('quic_override')},
|
||||||
"projects/{project}/global/targetHttpsProxies/{name}/setQuicOverride"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'quicOverride': module.params.get('quic_override')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def ssl_certificates_update(module, request, response):
|
def ssl_certificates_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/targetHttpsProxies/{name}/setSslCertificates"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink')},
|
||||||
"projects/{project}/targetHttpsProxies/{name}/setSslCertificates"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def ssl_policy_update(module, request, response):
|
def ssl_policy_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetHttpsProxies/{name}/setSslPolicy"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink')},
|
||||||
"projects/{project}/global/targetHttpsProxies/{name}/setSslPolicy"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def url_map_update(module, request, response):
|
def url_map_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/targetHttpsProxies/{name}/setUrlMap"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')},
|
||||||
"projects/{project}/targetHttpsProxies/{name}/setUrlMap"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -402,7 +380,7 @@ def resource_to_request(module):
|
||||||
u'quicOverride': module.params.get('quic_override'),
|
u'quicOverride': module.params.get('quic_override'),
|
||||||
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink'),
|
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink'),
|
||||||
u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink'),
|
u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink'),
|
||||||
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink')
|
u'urlMap': replace_resource_dict(module.params.get(u'url_map', {}), 'selfLink'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -437,8 +415,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -475,7 +453,7 @@ def response_to_hash(module, response):
|
||||||
u'quicOverride': response.get(u'quicOverride'),
|
u'quicOverride': response.get(u'quicOverride'),
|
||||||
u'sslCertificates': response.get(u'sslCertificates'),
|
u'sslCertificates': response.get(u'sslCertificates'),
|
||||||
u'sslPolicy': response.get(u'sslPolicy'),
|
u'sslPolicy': response.get(u'sslPolicy'),
|
||||||
u'urlMap': response.get(u'urlMap')
|
u'urlMap': response.get(u'urlMap'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -501,7 +479,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -133,11 +132,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -147,9 +142,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -257,7 +256,7 @@ def main():
|
||||||
instances=dict(type='list'),
|
instances=dict(type='list'),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
session_affinity=dict(type='str', choices=['NONE', 'CLIENT_IP', 'CLIENT_IP_PROTO']),
|
session_affinity=dict(type='str', choices=['NONE', 'CLIENT_IP', 'CLIENT_IP_PROTO']),
|
||||||
region=dict(required=True, type='str')
|
region=dict(required=True, type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -316,7 +315,7 @@ def resource_to_request(module):
|
||||||
u'healthCheck': replace_resource_dict(module.params.get(u'health_check', {}), 'selfLink'),
|
u'healthCheck': replace_resource_dict(module.params.get(u'health_check', {}), 'selfLink'),
|
||||||
u'instances': replace_resource_dict(module.params.get('instances', []), 'selfLink'),
|
u'instances': replace_resource_dict(module.params.get('instances', []), 'selfLink'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'sessionAffinity': module.params.get('session_affinity')
|
u'sessionAffinity': module.params.get('session_affinity'),
|
||||||
}
|
}
|
||||||
request = encode_request(request, module)
|
request = encode_request(request, module)
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
|
@ -352,8 +351,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
result = decode_request(result, module)
|
result = decode_request(result, module)
|
||||||
|
|
||||||
|
@ -394,7 +393,7 @@ def response_to_hash(module, response):
|
||||||
u'id': response.get(u'id'),
|
u'id': response.get(u'id'),
|
||||||
u'instances': response.get(u'instances'),
|
u'instances': response.get(u'instances'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'sessionAffinity': module.params.get('session_affinity')
|
u'sessionAffinity': module.params.get('session_affinity'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -420,7 +419,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -168,12 +167,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str'),
|
|
||||||
region=dict(required=True, type='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -183,9 +177,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -266,7 +265,7 @@ def main():
|
||||||
proxy_header=dict(type='str', choices=['NONE', 'PROXY_V1']),
|
proxy_header=dict(type='str', choices=['NONE', 'PROXY_V1']),
|
||||||
service=dict(required=True),
|
service=dict(required=True),
|
||||||
ssl_certificates=dict(required=True, type='list'),
|
ssl_certificates=dict(required=True, type='list'),
|
||||||
ssl_policy=dict()
|
ssl_policy=dict(),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -307,8 +306,7 @@ def create(module, link, kind):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind, fetch):
|
||||||
update_fields(module, resource_to_request(module),
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
response_to_hash(module, fetch))
|
|
||||||
return fetch_resource(module, self_link(module), kind)
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
@ -326,52 +324,32 @@ def update_fields(module, request, response):
|
||||||
def proxy_header_update(module, request, response):
|
def proxy_header_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetSslProxies/{name}/setProxyHeader"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'proxyHeader': module.params.get('proxy_header')},
|
||||||
"projects/{project}/global/targetSslProxies/{name}/setProxyHeader"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'proxyHeader': module.params.get('proxy_header')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def service_update(module, request, response):
|
def service_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetSslProxies/{name}/setBackendService"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink')},
|
||||||
"projects/{project}/global/targetSslProxies/{name}/setBackendService"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def ssl_certificates_update(module, request, response):
|
def ssl_certificates_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetSslProxies/{name}/setSslCertificates"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink')},
|
||||||
"projects/{project}/global/targetSslProxies/{name}/setSslCertificates"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def ssl_policy_update(module, request, response):
|
def ssl_policy_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetSslProxies/{name}/setSslPolicy"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink')},
|
||||||
"projects/{project}/global/targetSslProxies/{name}/setSslPolicy"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -388,7 +366,7 @@ def resource_to_request(module):
|
||||||
u'proxyHeader': module.params.get('proxy_header'),
|
u'proxyHeader': module.params.get('proxy_header'),
|
||||||
u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink'),
|
u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink'),
|
||||||
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink'),
|
u'sslCertificates': replace_resource_dict(module.params.get('ssl_certificates', []), 'selfLink'),
|
||||||
u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink')
|
u'sslPolicy': replace_resource_dict(module.params.get(u'ssl_policy', {}), 'selfLink'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -423,8 +401,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -461,7 +439,7 @@ def response_to_hash(module, response):
|
||||||
u'proxyHeader': response.get(u'proxyHeader'),
|
u'proxyHeader': response.get(u'proxyHeader'),
|
||||||
u'service': response.get(u'service'),
|
u'service': response.get(u'service'),
|
||||||
u'sslCertificates': response.get(u'sslCertificates'),
|
u'sslCertificates': response.get(u'sslCertificates'),
|
||||||
u'sslPolicy': response.get(u'sslPolicy')
|
u'sslPolicy': response.get(u'sslPolicy'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -487,7 +465,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -129,11 +128,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -143,9 +138,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -199,7 +198,7 @@ def main():
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
proxy_header=dict(type='str', choices=['NONE', 'PROXY_V1']),
|
proxy_header=dict(type='str', choices=['NONE', 'PROXY_V1']),
|
||||||
service=dict(required=True)
|
service=dict(required=True),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -240,8 +239,7 @@ def create(module, link, kind):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind, fetch):
|
||||||
update_fields(module, resource_to_request(module),
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
response_to_hash(module, fetch))
|
|
||||||
return fetch_resource(module, self_link(module), kind)
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
@ -255,26 +253,16 @@ def update_fields(module, request, response):
|
||||||
def proxy_header_update(module, request, response):
|
def proxy_header_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetTcpProxies/{name}/setProxyHeader"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'proxyHeader': module.params.get('proxy_header')},
|
||||||
"projects/{project}/global/targetTcpProxies/{name}/setProxyHeader"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'proxyHeader': module.params.get('proxy_header')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def service_update(module, request, response):
|
def service_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/targetTcpProxies/{name}/setBackendService"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink')},
|
||||||
"projects/{project}/global/targetTcpProxies/{name}/setBackendService"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -289,7 +277,7 @@ def resource_to_request(module):
|
||||||
u'description': module.params.get('description'),
|
u'description': module.params.get('description'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'proxyHeader': module.params.get('proxy_header'),
|
u'proxyHeader': module.params.get('proxy_header'),
|
||||||
u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink')
|
u'service': replace_resource_dict(module.params.get(u'service', {}), 'selfLink'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -324,8 +312,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -360,7 +348,7 @@ def response_to_hash(module, response):
|
||||||
u'id': response.get(u'id'),
|
u'id': response.get(u'id'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'proxyHeader': response.get(u'proxyHeader'),
|
u'proxyHeader': response.get(u'proxyHeader'),
|
||||||
u'service': response.get(u'service')
|
u'service': response.get(u'service'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -386,7 +374,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -115,11 +114,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -129,9 +124,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -181,7 +180,7 @@ def main():
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
network=dict(required=True),
|
network=dict(required=True),
|
||||||
region=dict(required=True, type='str')
|
region=dict(required=True, type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -235,7 +234,7 @@ def resource_to_request(module):
|
||||||
u'kind': 'compute#targetVpnGateway',
|
u'kind': 'compute#targetVpnGateway',
|
||||||
u'description': module.params.get('description'),
|
u'description': module.params.get('description'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink')
|
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -270,8 +269,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -307,7 +306,7 @@ def response_to_hash(module, response):
|
||||||
u'id': response.get(u'id'),
|
u'id': response.get(u'id'),
|
||||||
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
|
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
|
||||||
u'tunnels': response.get(u'tunnels'),
|
u'tunnels': response.get(u'tunnels'),
|
||||||
u'forwardingRules': response.get(u'forwardingRules')
|
u'forwardingRules': response.get(u'forwardingRules'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -333,7 +332,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -130,12 +129,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str'),
|
|
||||||
region=dict(required=True, type='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -145,9 +139,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -371,27 +370,33 @@ def main():
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
default_service=dict(required=True),
|
default_service=dict(required=True),
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
host_rules=dict(type='list', elements='dict', options=dict(
|
host_rules=dict(
|
||||||
description=dict(type='str'),
|
type='list',
|
||||||
hosts=dict(required=True, type='list', elements='str'),
|
elements='dict',
|
||||||
path_matcher=dict(required=True, type='str')
|
options=dict(
|
||||||
)),
|
description=dict(type='str'), hosts=dict(required=True, type='list', elements='str'), path_matcher=dict(required=True, type='str')
|
||||||
|
),
|
||||||
|
),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
path_matchers=dict(type='list', elements='dict', options=dict(
|
path_matchers=dict(
|
||||||
|
type='list',
|
||||||
|
elements='dict',
|
||||||
|
options=dict(
|
||||||
default_service=dict(required=True),
|
default_service=dict(required=True),
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
name=dict(required=True, type='str'),
|
name=dict(required=True, type='str'),
|
||||||
path_rules=dict(type='list', elements='dict', options=dict(
|
path_rules=dict(
|
||||||
paths=dict(required=True, type='list', elements='str'),
|
type='list', elements='dict', options=dict(paths=dict(required=True, type='list', elements='str'), service=dict(required=True))
|
||||||
service=dict(required=True)
|
),
|
||||||
))
|
),
|
||||||
)),
|
),
|
||||||
tests=dict(type='list', elements='dict', options=dict(
|
tests=dict(
|
||||||
description=dict(type='str'),
|
type='list',
|
||||||
host=dict(required=True, type='str'),
|
elements='dict',
|
||||||
path=dict(required=True, type='str'),
|
options=dict(
|
||||||
service=dict(required=True)
|
description=dict(type='str'), host=dict(required=True, type='str'), path=dict(required=True, type='str'), service=dict(required=True)
|
||||||
))
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -449,7 +454,7 @@ def resource_to_request(module):
|
||||||
u'hostRules': UrlMapHostrulesArray(module.params.get('host_rules', []), module).to_request(),
|
u'hostRules': UrlMapHostrulesArray(module.params.get('host_rules', []), module).to_request(),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'pathMatchers': UrlMapPathmatchersArray(module.params.get('path_matchers', []), module).to_request(),
|
u'pathMatchers': UrlMapPathmatchersArray(module.params.get('path_matchers', []), module).to_request(),
|
||||||
u'tests': UrlMapTestsArray(module.params.get('tests', []), module).to_request()
|
u'tests': UrlMapTestsArray(module.params.get('tests', []), module).to_request(),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -484,8 +489,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -523,7 +528,7 @@ def response_to_hash(module, response):
|
||||||
u'fingerprint': response.get(u'fingerprint'),
|
u'fingerprint': response.get(u'fingerprint'),
|
||||||
u'name': module.params.get('name'),
|
u'name': module.params.get('name'),
|
||||||
u'pathMatchers': UrlMapPathmatchersArray(response.get(u'pathMatchers', []), module).from_response(),
|
u'pathMatchers': UrlMapPathmatchersArray(response.get(u'pathMatchers', []), module).from_response(),
|
||||||
u'tests': UrlMapTestsArray(response.get(u'tests', []), module).from_response()
|
u'tests': UrlMapTestsArray(response.get(u'tests', []), module).from_response(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -549,7 +554,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
@ -583,18 +588,10 @@ class UrlMapHostrulesArray(object):
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'description': item.get('description'), u'hosts': item.get('hosts'), u'pathMatcher': item.get('path_matcher')})
|
||||||
u'description': item.get('description'),
|
|
||||||
u'hosts': item.get('hosts'),
|
|
||||||
u'pathMatcher': item.get('path_matcher')
|
|
||||||
})
|
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'description': item.get(u'description'), u'hosts': item.get(u'hosts'), u'pathMatcher': item.get(u'pathMatcher')})
|
||||||
u'description': item.get(u'description'),
|
|
||||||
u'hosts': item.get(u'hosts'),
|
|
||||||
u'pathMatcher': item.get(u'pathMatcher')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class UrlMapPathmatchersArray(object):
|
class UrlMapPathmatchersArray(object):
|
||||||
|
@ -618,20 +615,24 @@ class UrlMapPathmatchersArray(object):
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'defaultService': replace_resource_dict(item.get(u'default_service', {}), 'selfLink'),
|
u'defaultService': replace_resource_dict(item.get(u'default_service', {}), 'selfLink'),
|
||||||
u'description': item.get('description'),
|
u'description': item.get('description'),
|
||||||
u'name': item.get('name'),
|
u'name': item.get('name'),
|
||||||
u'pathRules': UrlMapPathrulesArray(item.get('path_rules', []), self.module).to_request()
|
u'pathRules': UrlMapPathrulesArray(item.get('path_rules', []), self.module).to_request(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'defaultService': item.get(u'defaultService'),
|
u'defaultService': item.get(u'defaultService'),
|
||||||
u'description': item.get(u'description'),
|
u'description': item.get(u'description'),
|
||||||
u'name': item.get(u'name'),
|
u'name': item.get(u'name'),
|
||||||
u'pathRules': UrlMapPathrulesArray(item.get(u'pathRules', []), self.module).from_response()
|
u'pathRules': UrlMapPathrulesArray(item.get(u'pathRules', []), self.module).from_response(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class UrlMapPathrulesArray(object):
|
class UrlMapPathrulesArray(object):
|
||||||
|
@ -655,16 +656,10 @@ class UrlMapPathrulesArray(object):
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'paths': item.get('paths'), u'service': replace_resource_dict(item.get(u'service', {}), 'selfLink')})
|
||||||
u'paths': item.get('paths'),
|
|
||||||
u'service': replace_resource_dict(item.get(u'service', {}), 'selfLink')
|
|
||||||
})
|
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'paths': item.get(u'paths'), u'service': item.get(u'service')})
|
||||||
u'paths': item.get(u'paths'),
|
|
||||||
u'service': item.get(u'service')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class UrlMapTestsArray(object):
|
class UrlMapTestsArray(object):
|
||||||
|
@ -688,20 +683,19 @@ class UrlMapTestsArray(object):
|
||||||
return items
|
return items
|
||||||
|
|
||||||
def _request_for_item(self, item):
|
def _request_for_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'description': item.get('description'),
|
u'description': item.get('description'),
|
||||||
u'host': item.get('host'),
|
u'host': item.get('host'),
|
||||||
u'path': item.get('path'),
|
u'path': item.get('path'),
|
||||||
u'service': replace_resource_dict(item.get(u'service', {}), 'selfLink')
|
u'service': replace_resource_dict(item.get(u'service', {}), 'selfLink'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def _response_from_item(self, item):
|
def _response_from_item(self, item):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
u'description': item.get(u'description'),
|
{u'description': item.get(u'description'), u'host': item.get(u'host'), u'path': item.get(u'path'), u'service': item.get(u'service')}
|
||||||
u'host': item.get(u'host'),
|
)
|
||||||
u'path': item.get(u'path'),
|
|
||||||
u'service': item.get(u'service')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -211,11 +210,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -225,9 +220,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -289,7 +288,7 @@ def main():
|
||||||
local_traffic_selector=dict(type='list', elements='str'),
|
local_traffic_selector=dict(type='list', elements='str'),
|
||||||
remote_traffic_selector=dict(type='list', elements='str'),
|
remote_traffic_selector=dict(type='list', elements='str'),
|
||||||
labels=dict(type='dict'),
|
labels=dict(type='dict'),
|
||||||
region=dict(required=True, type='str')
|
region=dict(required=True, type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -331,8 +330,7 @@ def create(module, link, kind):
|
||||||
|
|
||||||
|
|
||||||
def update(module, link, kind, fetch):
|
def update(module, link, kind, fetch):
|
||||||
update_fields(module, resource_to_request(module),
|
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
|
||||||
response_to_hash(module, fetch))
|
|
||||||
return fetch_resource(module, self_link(module), kind)
|
return fetch_resource(module, self_link(module), kind)
|
||||||
|
|
||||||
|
|
||||||
|
@ -344,14 +342,8 @@ def update_fields(module, request, response):
|
||||||
def labels_update(module, request, response):
|
def labels_update(module, request, response):
|
||||||
auth = GcpSession(module, 'compute')
|
auth = GcpSession(module, 'compute')
|
||||||
auth.post(
|
auth.post(
|
||||||
''.join([
|
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/vpnTunnels/{name}/setLabels"]).format(**module.params),
|
||||||
"https://www.googleapis.com/compute/v1/",
|
{u'labels': module.params.get('labels'), u'labelFingerprint': response.get('labelFingerprint')},
|
||||||
"projects/{project}/regions/{region}/vpnTunnels/{name}/setLabels"
|
|
||||||
]).format(**module.params),
|
|
||||||
{
|
|
||||||
u'labels': module.params.get('labels'),
|
|
||||||
u'labelFingerprint': response.get('labelFingerprint')
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -372,7 +364,7 @@ def resource_to_request(module):
|
||||||
u'ikeVersion': module.params.get('ike_version'),
|
u'ikeVersion': module.params.get('ike_version'),
|
||||||
u'localTrafficSelector': module.params.get('local_traffic_selector'),
|
u'localTrafficSelector': module.params.get('local_traffic_selector'),
|
||||||
u'remoteTrafficSelector': module.params.get('remote_traffic_selector'),
|
u'remoteTrafficSelector': module.params.get('remote_traffic_selector'),
|
||||||
u'labels': module.params.get('labels')
|
u'labels': module.params.get('labels'),
|
||||||
}
|
}
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
for k, v in request.items():
|
for k, v in request.items():
|
||||||
|
@ -407,8 +399,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -450,7 +442,7 @@ def response_to_hash(module, response):
|
||||||
u'localTrafficSelector': response.get(u'localTrafficSelector'),
|
u'localTrafficSelector': response.get(u'localTrafficSelector'),
|
||||||
u'remoteTrafficSelector': response.get(u'remoteTrafficSelector'),
|
u'remoteTrafficSelector': response.get(u'remoteTrafficSelector'),
|
||||||
u'labels': response.get(u'labels'),
|
u'labels': response.get(u'labels'),
|
||||||
u'labelFingerprint': response.get(u'labelFingerprint')
|
u'labelFingerprint': response.get(u'labelFingerprint'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -476,7 +468,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
op_result = fetch_resource(module, op_uri, 'compute#operation')
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -168,12 +167,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
|
||||||
argument_spec=dict(
|
|
||||||
filters=dict(type='list', elements='str'),
|
|
||||||
region=dict(required=True, type='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
|
||||||
|
@ -183,9 +177,7 @@ def main():
|
||||||
items = items.get('items')
|
items = items.get('items')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -597,7 +596,9 @@ def main():
|
||||||
name=dict(type='str'),
|
name=dict(type='str'),
|
||||||
description=dict(type='str'),
|
description=dict(type='str'),
|
||||||
initial_node_count=dict(required=True, type='int'),
|
initial_node_count=dict(required=True, type='int'),
|
||||||
node_config=dict(type='dict', options=dict(
|
node_config=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
machine_type=dict(type='str'),
|
machine_type=dict(type='str'),
|
||||||
disk_size_gb=dict(type='int'),
|
disk_size_gb=dict(type='int'),
|
||||||
oauth_scopes=dict(type='list', elements='str'),
|
oauth_scopes=dict(type='list', elements='str'),
|
||||||
|
@ -607,30 +608,33 @@ def main():
|
||||||
labels=dict(type='dict'),
|
labels=dict(type='dict'),
|
||||||
local_ssd_count=dict(type='int'),
|
local_ssd_count=dict(type='int'),
|
||||||
tags=dict(type='list', elements='str'),
|
tags=dict(type='list', elements='str'),
|
||||||
preemptible=dict(type='bool')
|
preemptible=dict(type='bool'),
|
||||||
)),
|
),
|
||||||
master_auth=dict(type='dict', options=dict(
|
),
|
||||||
|
master_auth=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
username=dict(type='str'),
|
username=dict(type='str'),
|
||||||
password=dict(type='str'),
|
password=dict(type='str'),
|
||||||
cluster_ca_certificate=dict(type='str'),
|
cluster_ca_certificate=dict(type='str'),
|
||||||
client_certificate=dict(type='str'),
|
client_certificate=dict(type='str'),
|
||||||
client_key=dict(type='str')
|
client_key=dict(type='str'),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
logging_service=dict(type='str', choices=['logging.googleapis.com', 'none']),
|
logging_service=dict(type='str', choices=['logging.googleapis.com', 'none']),
|
||||||
monitoring_service=dict(type='str', choices=['monitoring.googleapis.com', 'none']),
|
monitoring_service=dict(type='str', choices=['monitoring.googleapis.com', 'none']),
|
||||||
network=dict(type='str'),
|
network=dict(type='str'),
|
||||||
cluster_ipv4_cidr=dict(type='str'),
|
cluster_ipv4_cidr=dict(type='str'),
|
||||||
addons_config=dict(type='dict', options=dict(
|
addons_config=dict(
|
||||||
http_load_balancing=dict(type='dict', options=dict(
|
type='dict',
|
||||||
disabled=dict(type='bool')
|
options=dict(
|
||||||
)),
|
http_load_balancing=dict(type='dict', options=dict(disabled=dict(type='bool'))),
|
||||||
horizontal_pod_autoscaling=dict(type='dict', options=dict(
|
horizontal_pod_autoscaling=dict(type='dict', options=dict(disabled=dict(type='bool'))),
|
||||||
disabled=dict(type='bool')
|
),
|
||||||
))
|
),
|
||||||
)),
|
|
||||||
subnetwork=dict(type='str'),
|
subnetwork=dict(type='str'),
|
||||||
location=dict(type='list', elements='str'),
|
location=dict(type='list', elements='str'),
|
||||||
zone=dict(required=True, type='str')
|
zone=dict(required=True, type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -692,7 +696,7 @@ def resource_to_request(module):
|
||||||
u'clusterIpv4Cidr': module.params.get('cluster_ipv4_cidr'),
|
u'clusterIpv4Cidr': module.params.get('cluster_ipv4_cidr'),
|
||||||
u'addonsConfig': ClusterAddonsconfig(module.params.get('addons_config', {}), module).to_request(),
|
u'addonsConfig': ClusterAddonsconfig(module.params.get('addons_config', {}), module).to_request(),
|
||||||
u'subnetwork': module.params.get('subnetwork'),
|
u'subnetwork': module.params.get('subnetwork'),
|
||||||
u'location': module.params.get('location')
|
u'location': module.params.get('location'),
|
||||||
}
|
}
|
||||||
request = encode_request(request, module)
|
request = encode_request(request, module)
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
|
@ -728,8 +732,8 @@ def return_if_object(module, response, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -779,7 +783,7 @@ def response_to_hash(module, response):
|
||||||
u'nodeIpv4CidrSize': response.get(u'nodeIpv4CidrSize'),
|
u'nodeIpv4CidrSize': response.get(u'nodeIpv4CidrSize'),
|
||||||
u'servicesIpv4Cidr': response.get(u'servicesIpv4Cidr'),
|
u'servicesIpv4Cidr': response.get(u'servicesIpv4Cidr'),
|
||||||
u'currentNodeCount': response.get(u'currentNodeCount'),
|
u'currentNodeCount': response.get(u'currentNodeCount'),
|
||||||
u'expireTime': response.get(u'expireTime')
|
u'expireTime': response.get(u'expireTime'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -805,7 +809,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri)
|
op_result = fetch_resource(module, op_uri)
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
@ -829,9 +833,7 @@ def raise_if_errors(response, err_path, module):
|
||||||
#
|
#
|
||||||
# Format the request to match the expected input by the API
|
# Format the request to match the expected input by the API
|
||||||
def encode_request(resource_request, module):
|
def encode_request(resource_request, module):
|
||||||
return {
|
return {'cluster': resource_request}
|
||||||
'cluster': resource_request
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterNodeconfig(object):
|
class ClusterNodeconfig(object):
|
||||||
|
@ -843,7 +845,8 @@ class ClusterNodeconfig(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'machineType': self.request.get('machine_type'),
|
u'machineType': self.request.get('machine_type'),
|
||||||
u'diskSizeGb': self.request.get('disk_size_gb'),
|
u'diskSizeGb': self.request.get('disk_size_gb'),
|
||||||
u'oauthScopes': self.request.get('oauth_scopes'),
|
u'oauthScopes': self.request.get('oauth_scopes'),
|
||||||
|
@ -853,11 +856,13 @@ class ClusterNodeconfig(object):
|
||||||
u'labels': self.request.get('labels'),
|
u'labels': self.request.get('labels'),
|
||||||
u'localSsdCount': self.request.get('local_ssd_count'),
|
u'localSsdCount': self.request.get('local_ssd_count'),
|
||||||
u'tags': self.request.get('tags'),
|
u'tags': self.request.get('tags'),
|
||||||
u'preemptible': self.request.get('preemptible')
|
u'preemptible': self.request.get('preemptible'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'machineType': self.request.get(u'machineType'),
|
u'machineType': self.request.get(u'machineType'),
|
||||||
u'diskSizeGb': self.request.get(u'diskSizeGb'),
|
u'diskSizeGb': self.request.get(u'diskSizeGb'),
|
||||||
u'oauthScopes': self.request.get(u'oauthScopes'),
|
u'oauthScopes': self.request.get(u'oauthScopes'),
|
||||||
|
@ -867,8 +872,9 @@ class ClusterNodeconfig(object):
|
||||||
u'labels': self.request.get(u'labels'),
|
u'labels': self.request.get(u'labels'),
|
||||||
u'localSsdCount': self.request.get(u'localSsdCount'),
|
u'localSsdCount': self.request.get(u'localSsdCount'),
|
||||||
u'tags': self.request.get(u'tags'),
|
u'tags': self.request.get(u'tags'),
|
||||||
u'preemptible': self.request.get(u'preemptible')
|
u'preemptible': self.request.get(u'preemptible'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ClusterMasterauth(object):
|
class ClusterMasterauth(object):
|
||||||
|
@ -880,22 +886,26 @@ class ClusterMasterauth(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'username': self.request.get('username'),
|
u'username': self.request.get('username'),
|
||||||
u'password': self.request.get('password'),
|
u'password': self.request.get('password'),
|
||||||
u'clusterCaCertificate': self.request.get('cluster_ca_certificate'),
|
u'clusterCaCertificate': self.request.get('cluster_ca_certificate'),
|
||||||
u'clientCertificate': self.request.get('client_certificate'),
|
u'clientCertificate': self.request.get('client_certificate'),
|
||||||
u'clientKey': self.request.get('client_key')
|
u'clientKey': self.request.get('client_key'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'username': self.request.get(u'username'),
|
u'username': self.request.get(u'username'),
|
||||||
u'password': self.request.get(u'password'),
|
u'password': self.request.get(u'password'),
|
||||||
u'clusterCaCertificate': self.request.get(u'clusterCaCertificate'),
|
u'clusterCaCertificate': self.request.get(u'clusterCaCertificate'),
|
||||||
u'clientCertificate': self.request.get(u'clientCertificate'),
|
u'clientCertificate': self.request.get(u'clientCertificate'),
|
||||||
u'clientKey': self.request.get(u'clientKey')
|
u'clientKey': self.request.get(u'clientKey'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ClusterAddonsconfig(object):
|
class ClusterAddonsconfig(object):
|
||||||
|
@ -907,16 +917,20 @@ class ClusterAddonsconfig(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'httpLoadBalancing': ClusterHttploadbalancing(self.request.get('http_load_balancing', {}), self.module).to_request(),
|
u'httpLoadBalancing': ClusterHttploadbalancing(self.request.get('http_load_balancing', {}), self.module).to_request(),
|
||||||
u'horizontalPodAutoscaling': ClusterHorizontalpodautoscaling(self.request.get('horizontal_pod_autoscaling', {}), self.module).to_request()
|
u'horizontalPodAutoscaling': ClusterHorizontalpodautoscaling(self.request.get('horizontal_pod_autoscaling', {}), self.module).to_request(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'httpLoadBalancing': ClusterHttploadbalancing(self.request.get(u'httpLoadBalancing', {}), self.module).from_response(),
|
u'httpLoadBalancing': ClusterHttploadbalancing(self.request.get(u'httpLoadBalancing', {}), self.module).from_response(),
|
||||||
u'horizontalPodAutoscaling': ClusterHorizontalpodautoscaling(self.request.get(u'horizontalPodAutoscaling', {}), self.module).from_response()
|
u'horizontalPodAutoscaling': ClusterHorizontalpodautoscaling(self.request.get(u'horizontalPodAutoscaling', {}), self.module).from_response(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class ClusterHttploadbalancing(object):
|
class ClusterHttploadbalancing(object):
|
||||||
|
@ -928,14 +942,10 @@ class ClusterHttploadbalancing(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'disabled': self.request.get('disabled')})
|
||||||
u'disabled': self.request.get('disabled')
|
|
||||||
})
|
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'disabled': self.request.get(u'disabled')})
|
||||||
u'disabled': self.request.get(u'disabled')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class ClusterHorizontalpodautoscaling(object):
|
class ClusterHorizontalpodautoscaling(object):
|
||||||
|
@ -947,14 +957,10 @@ class ClusterHorizontalpodautoscaling(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'disabled': self.request.get('disabled')})
|
||||||
u'disabled': self.request.get('disabled')
|
|
||||||
})
|
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'disabled': self.request.get(u'disabled')})
|
||||||
u'disabled': self.request.get(u'disabled')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -367,11 +366,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(zone=dict(required=True, type='str')))
|
||||||
argument_spec=dict(
|
|
||||||
zone=dict(required=True, type='str')
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||||
|
@ -381,9 +376,7 @@ def main():
|
||||||
items = items.get('clusters')
|
items = items.get('clusters')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -443,7 +442,9 @@ def main():
|
||||||
argument_spec=dict(
|
argument_spec=dict(
|
||||||
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
state=dict(default='present', choices=['present', 'absent'], type='str'),
|
||||||
name=dict(type='str'),
|
name=dict(type='str'),
|
||||||
config=dict(type='dict', options=dict(
|
config=dict(
|
||||||
|
type='dict',
|
||||||
|
options=dict(
|
||||||
machine_type=dict(type='str'),
|
machine_type=dict(type='str'),
|
||||||
disk_size_gb=dict(type='int'),
|
disk_size_gb=dict(type='int'),
|
||||||
oauth_scopes=dict(type='list', elements='str'),
|
oauth_scopes=dict(type='list', elements='str'),
|
||||||
|
@ -453,24 +454,21 @@ def main():
|
||||||
labels=dict(type='dict'),
|
labels=dict(type='dict'),
|
||||||
local_ssd_count=dict(type='int'),
|
local_ssd_count=dict(type='int'),
|
||||||
tags=dict(type='list', elements='str'),
|
tags=dict(type='list', elements='str'),
|
||||||
preemptible=dict(type='bool')
|
preemptible=dict(type='bool'),
|
||||||
)),
|
),
|
||||||
|
),
|
||||||
initial_node_count=dict(required=True, type='int'),
|
initial_node_count=dict(required=True, type='int'),
|
||||||
autoscaling=dict(type='dict', options=dict(
|
autoscaling=dict(type='dict', options=dict(enabled=dict(type='bool'), min_node_count=dict(type='int'), max_node_count=dict(type='int'))),
|
||||||
enabled=dict(type='bool'),
|
management=dict(
|
||||||
min_node_count=dict(type='int'),
|
type='dict',
|
||||||
max_node_count=dict(type='int')
|
options=dict(
|
||||||
)),
|
|
||||||
management=dict(type='dict', options=dict(
|
|
||||||
auto_upgrade=dict(type='bool'),
|
auto_upgrade=dict(type='bool'),
|
||||||
auto_repair=dict(type='bool'),
|
auto_repair=dict(type='bool'),
|
||||||
upgrade_options=dict(type='dict', options=dict(
|
upgrade_options=dict(type='dict', options=dict(auto_upgrade_start_time=dict(type='str'), description=dict(type='str'))),
|
||||||
auto_upgrade_start_time=dict(type='str'),
|
),
|
||||||
description=dict(type='str')
|
),
|
||||||
))
|
|
||||||
)),
|
|
||||||
cluster=dict(required=True),
|
cluster=dict(required=True),
|
||||||
zone=dict(required=True, type='str')
|
zone=dict(required=True, type='str'),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -525,7 +523,7 @@ def resource_to_request(module):
|
||||||
u'config': NodePoolConfig(module.params.get('config', {}), module).to_request(),
|
u'config': NodePoolConfig(module.params.get('config', {}), module).to_request(),
|
||||||
u'initialNodeCount': module.params.get('initial_node_count'),
|
u'initialNodeCount': module.params.get('initial_node_count'),
|
||||||
u'autoscaling': NodePoolAutoscaling(module.params.get('autoscaling', {}), module).to_request(),
|
u'autoscaling': NodePoolAutoscaling(module.params.get('autoscaling', {}), module).to_request(),
|
||||||
u'management': NodePoolManagement(module.params.get('management', {}), module).to_request()
|
u'management': NodePoolManagement(module.params.get('management', {}), module).to_request(),
|
||||||
}
|
}
|
||||||
request = encode_request(request, module)
|
request = encode_request(request, module)
|
||||||
return_vals = {}
|
return_vals = {}
|
||||||
|
@ -546,17 +544,13 @@ def self_link(module):
|
||||||
'project': module.params['project'],
|
'project': module.params['project'],
|
||||||
'zone': module.params['zone'],
|
'zone': module.params['zone'],
|
||||||
'cluster': replace_resource_dict(module.params['cluster'], 'name'),
|
'cluster': replace_resource_dict(module.params['cluster'], 'name'),
|
||||||
'name': module.params['name']
|
'name': module.params['name'],
|
||||||
}
|
}
|
||||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools/{name}".format(**res)
|
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools/{name}".format(**res)
|
||||||
|
|
||||||
|
|
||||||
def collection(module):
|
def collection(module):
|
||||||
res = {
|
res = {'project': module.params['project'], 'zone': module.params['zone'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')}
|
||||||
'project': module.params['project'],
|
|
||||||
'zone': module.params['zone'],
|
|
||||||
'cluster': replace_resource_dict(module.params['cluster'], 'name')
|
|
||||||
}
|
|
||||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res)
|
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res)
|
||||||
|
|
||||||
|
|
||||||
|
@ -572,8 +566,8 @@ def return_if_object(module, response, allow_not_found=False):
|
||||||
try:
|
try:
|
||||||
module.raise_for_status(response)
|
module.raise_for_status(response)
|
||||||
result = response.json()
|
result = response.json()
|
||||||
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
except getattr(json.decoder, 'JSONDecodeError', ValueError):
|
||||||
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
|
||||||
|
|
||||||
if navigate_hash(result, ['error', 'errors']):
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
@ -608,7 +602,7 @@ def response_to_hash(module, response):
|
||||||
u'initialNodeCount': module.params.get('initial_node_count'),
|
u'initialNodeCount': module.params.get('initial_node_count'),
|
||||||
u'version': response.get(u'version'),
|
u'version': response.get(u'version'),
|
||||||
u'autoscaling': NodePoolAutoscaling(response.get(u'autoscaling', {}), module).from_response(),
|
u'autoscaling': NodePoolAutoscaling(response.get(u'autoscaling', {}), module).from_response(),
|
||||||
u'management': NodePoolManagement(response.get(u'management', {}), module).from_response()
|
u'management': NodePoolManagement(response.get(u'management', {}), module).from_response(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -634,7 +628,7 @@ def wait_for_completion(status, op_result, module):
|
||||||
op_id = navigate_hash(op_result, ['name'])
|
op_id = navigate_hash(op_result, ['name'])
|
||||||
op_uri = async_op_url(module, {'op_id': op_id})
|
op_uri = async_op_url(module, {'op_id': op_id})
|
||||||
while status != 'DONE':
|
while status != 'DONE':
|
||||||
raise_if_errors(op_result, ['error', 'errors'], 'message')
|
raise_if_errors(op_result, ['error', 'errors'], module)
|
||||||
time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
op_result = fetch_resource(module, op_uri)
|
op_result = fetch_resource(module, op_uri)
|
||||||
status = navigate_hash(op_result, ['status'])
|
status = navigate_hash(op_result, ['status'])
|
||||||
|
@ -658,9 +652,7 @@ def raise_if_errors(response, err_path, module):
|
||||||
#
|
#
|
||||||
# Format the request to match the expected input by the API
|
# Format the request to match the expected input by the API
|
||||||
def encode_request(resource_request, module):
|
def encode_request(resource_request, module):
|
||||||
return {
|
return {'nodePool': resource_request}
|
||||||
'nodePool': resource_request
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class NodePoolConfig(object):
|
class NodePoolConfig(object):
|
||||||
|
@ -672,7 +664,8 @@ class NodePoolConfig(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'machineType': self.request.get('machine_type'),
|
u'machineType': self.request.get('machine_type'),
|
||||||
u'diskSizeGb': self.request.get('disk_size_gb'),
|
u'diskSizeGb': self.request.get('disk_size_gb'),
|
||||||
u'oauthScopes': self.request.get('oauth_scopes'),
|
u'oauthScopes': self.request.get('oauth_scopes'),
|
||||||
|
@ -682,11 +675,13 @@ class NodePoolConfig(object):
|
||||||
u'labels': self.request.get('labels'),
|
u'labels': self.request.get('labels'),
|
||||||
u'localSsdCount': self.request.get('local_ssd_count'),
|
u'localSsdCount': self.request.get('local_ssd_count'),
|
||||||
u'tags': self.request.get('tags'),
|
u'tags': self.request.get('tags'),
|
||||||
u'preemptible': self.request.get('preemptible')
|
u'preemptible': self.request.get('preemptible'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'machineType': self.request.get(u'machineType'),
|
u'machineType': self.request.get(u'machineType'),
|
||||||
u'diskSizeGb': self.request.get(u'diskSizeGb'),
|
u'diskSizeGb': self.request.get(u'diskSizeGb'),
|
||||||
u'oauthScopes': self.request.get(u'oauthScopes'),
|
u'oauthScopes': self.request.get(u'oauthScopes'),
|
||||||
|
@ -696,8 +691,9 @@ class NodePoolConfig(object):
|
||||||
u'labels': self.request.get(u'labels'),
|
u'labels': self.request.get(u'labels'),
|
||||||
u'localSsdCount': self.request.get(u'localSsdCount'),
|
u'localSsdCount': self.request.get(u'localSsdCount'),
|
||||||
u'tags': self.request.get(u'tags'),
|
u'tags': self.request.get(u'tags'),
|
||||||
u'preemptible': self.request.get(u'preemptible')
|
u'preemptible': self.request.get(u'preemptible'),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NodePoolAutoscaling(object):
|
class NodePoolAutoscaling(object):
|
||||||
|
@ -709,18 +705,14 @@ class NodePoolAutoscaling(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
u'enabled': self.request.get('enabled'),
|
{u'enabled': self.request.get('enabled'), u'minNodeCount': self.request.get('min_node_count'), u'maxNodeCount': self.request.get('max_node_count')}
|
||||||
u'minNodeCount': self.request.get('min_node_count'),
|
)
|
||||||
u'maxNodeCount': self.request.get('max_node_count')
|
|
||||||
})
|
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
u'enabled': self.request.get(u'enabled'),
|
{u'enabled': self.request.get(u'enabled'), u'minNodeCount': self.request.get(u'minNodeCount'), u'maxNodeCount': self.request.get(u'maxNodeCount')}
|
||||||
u'minNodeCount': self.request.get(u'minNodeCount'),
|
)
|
||||||
u'maxNodeCount': self.request.get(u'maxNodeCount')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
class NodePoolManagement(object):
|
class NodePoolManagement(object):
|
||||||
|
@ -732,18 +724,22 @@ class NodePoolManagement(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'autoUpgrade': self.request.get('auto_upgrade'),
|
u'autoUpgrade': self.request.get('auto_upgrade'),
|
||||||
u'autoRepair': self.request.get('auto_repair'),
|
u'autoRepair': self.request.get('auto_repair'),
|
||||||
u'upgradeOptions': NodePoolUpgradeoptions(self.request.get('upgrade_options', {}), self.module).to_request()
|
u'upgradeOptions': NodePoolUpgradeoptions(self.request.get('upgrade_options', {}), self.module).to_request(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict(
|
||||||
|
{
|
||||||
u'autoUpgrade': self.request.get(u'autoUpgrade'),
|
u'autoUpgrade': self.request.get(u'autoUpgrade'),
|
||||||
u'autoRepair': self.request.get(u'autoRepair'),
|
u'autoRepair': self.request.get(u'autoRepair'),
|
||||||
u'upgradeOptions': NodePoolUpgradeoptions(self.request.get(u'upgradeOptions', {}), self.module).from_response()
|
u'upgradeOptions': NodePoolUpgradeoptions(self.request.get(u'upgradeOptions', {}), self.module).from_response(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NodePoolUpgradeoptions(object):
|
class NodePoolUpgradeoptions(object):
|
||||||
|
@ -755,16 +751,10 @@ class NodePoolUpgradeoptions(object):
|
||||||
self.request = {}
|
self.request = {}
|
||||||
|
|
||||||
def to_request(self):
|
def to_request(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'autoUpgradeStartTime': self.request.get('auto_upgrade_start_time'), u'description': self.request.get('description')})
|
||||||
u'autoUpgradeStartTime': self.request.get('auto_upgrade_start_time'),
|
|
||||||
u'description': self.request.get('description')
|
|
||||||
})
|
|
||||||
|
|
||||||
def from_response(self):
|
def from_response(self):
|
||||||
return remove_nones_from_dict({
|
return remove_nones_from_dict({u'autoUpgradeStartTime': self.request.get(u'autoUpgradeStartTime'), u'description': self.request.get(u'description')})
|
||||||
u'autoUpgradeStartTime': self.request.get(u'autoUpgradeStartTime'),
|
|
||||||
u'description': self.request.get(u'description')
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -18,15 +18,14 @@
|
||||||
# ----------------------------------------------------------------------------
|
# ----------------------------------------------------------------------------
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function
|
from __future__ import absolute_import, division, print_function
|
||||||
|
|
||||||
__metaclass__ = type
|
__metaclass__ = type
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Documentation
|
# Documentation
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
|
||||||
'status': ["preview"],
|
|
||||||
'supported_by': 'community'}
|
|
||||||
|
|
||||||
DOCUMENTATION = '''
|
DOCUMENTATION = '''
|
||||||
---
|
---
|
||||||
|
@ -268,12 +267,7 @@ import json
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = GcpModule(
|
module = GcpModule(argument_spec=dict(zone=dict(required=True, type='str'), cluster=dict(required=True)))
|
||||||
argument_spec=dict(
|
|
||||||
zone=dict(required=True, type='str'),
|
|
||||||
cluster=dict(required=True)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
if not module.params['scopes']:
|
if not module.params['scopes']:
|
||||||
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
|
||||||
|
@ -283,18 +277,12 @@ def main():
|
||||||
items = items.get('nodePools')
|
items = items.get('nodePools')
|
||||||
else:
|
else:
|
||||||
items = []
|
items = []
|
||||||
return_value = {
|
return_value = {'items': items}
|
||||||
'items': items
|
|
||||||
}
|
|
||||||
module.exit_json(**return_value)
|
module.exit_json(**return_value)
|
||||||
|
|
||||||
|
|
||||||
def collection(module):
|
def collection(module):
|
||||||
res = {
|
res = {'project': module.params['project'], 'zone': module.params['zone'], 'cluster': replace_resource_dict(module.params['cluster'], 'name')}
|
||||||
'project': module.params['project'],
|
|
||||||
'zone': module.params['zone'],
|
|
||||||
'cluster': replace_resource_dict(module.params['cluster'], 'name')
|
|
||||||
}
|
|
||||||
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res)
|
return "https://container.googleapis.com/v1/projects/{project}/zones/{zone}/clusters/{cluster}/nodePools".format(**res)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue