Bug fixes for GCP modules (as of 2019-01-22T12:43:52-08:00) (#51247)

This commit is contained in:
Alex Stephen 2019-01-23 13:45:20 -08:00 committed by ansibot
parent 6a3eaba52e
commit 2836c8c897
24 changed files with 577 additions and 809 deletions

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -163,7 +162,7 @@ def main():
dns_name=dict(required=True, type='str'),
name=dict(required=True, type='str'),
name_server_set=dict(type='list', elements='str'),
labels=dict(type='dict')
labels=dict(type='dict'),
)
)
@ -204,8 +203,7 @@ def create(module, link, kind):
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)
@ -217,14 +215,8 @@ def update_fields(module, request, response):
def description_update(module, request, response):
auth = GcpSession(module, 'dns')
auth.patch(
''.join([
"https://www.googleapis.com/dns/v1/",
"projects/{project}/managedZones/{name}"
]).format(**module.params),
{
u'description': module.params.get('description'),
u'labels': module.params.get('labels')
}
''.join(["https://www.googleapis.com/dns/v1/", "projects/{project}/managedZones/{name}"]).format(**module.params),
{u'description': module.params.get('description'), u'labels': module.params.get('labels')},
)
@ -240,7 +232,7 @@ def resource_to_request(module):
u'dnsName': module.params.get('dns_name'),
u'name': module.params.get('name'),
u'nameServerSet': module.params.get('name_server_set'),
u'labels': module.params.get('labels')
u'labels': module.params.get('labels'),
}
return_vals = {}
for k, v in request.items():
@ -275,8 +267,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -313,7 +305,7 @@ def response_to_hash(module, response):
u'nameServers': response.get(u'nameServers'),
u'nameServerSet': response.get(u'nameServerSet'),
u'creationTime': response.get(u'creationTime'),
u'labels': response.get(u'labels')
u'labels': response.get(u'labels'),
}

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -122,11 +121,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
dns_name=dict(type='list', elements='str')
)
)
module = GcpModule(argument_spec=dict(dns_name=dict(type='list', elements='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
@ -136,9 +131,7 @@ def main():
items = items.get('managedZones')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -174,7 +173,7 @@ def main():
type=dict(required=True, type='str', choices=['A', 'AAAA', 'CAA', 'CNAME', 'MX', 'NAPTR', 'NS', 'PTR', 'SOA', 'SPF', 'SRV', 'TXT']),
ttl=dict(type='int'),
target=dict(type='list', elements='str'),
managed_zone=dict(required=True)
managed_zone=dict(required=True),
)
)
@ -184,9 +183,7 @@ def main():
state = module.params['state']
kind = 'dns#resourceRecordSet'
fetch = fetch_wrapped_resource(module, 'dns#resourceRecordSet',
'dns#resourceRecordSetsListResponse',
'rrsets')
fetch = fetch_wrapped_resource(module, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets')
changed = False
if fetch:
@ -216,9 +213,7 @@ def create(module, link, kind):
change_id = int(change['id'])
if change['status'] == 'pending':
wait_for_change_to_complete(change_id, module)
return fetch_wrapped_resource(module, 'dns#resourceRecordSet',
'dns#resourceRecordSetsListResponse',
'rrsets')
return fetch_wrapped_resource(module, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets')
def update(module, link, kind, fetch):
@ -226,9 +221,7 @@ def update(module, link, kind, fetch):
change_id = int(change['id'])
if change['status'] == 'pending':
wait_for_change_to_complete(change_id, module)
return fetch_wrapped_resource(module, 'dns#resourceRecordSet',
'dns#resourceRecordSetsListResponse',
'rrsets')
return fetch_wrapped_resource(module, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets')
def delete(module, link, kind, fetch):
@ -236,9 +229,7 @@ def delete(module, link, kind, fetch):
change_id = int(change['id'])
if change['status'] == 'pending':
wait_for_change_to_complete(change_id, module)
return fetch_wrapped_resource(module, 'dns#resourceRecordSet',
'dns#resourceRecordSetsListResponse',
'rrsets')
return fetch_wrapped_resource(module, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets')
def resource_to_request(module):
@ -247,7 +238,7 @@ def resource_to_request(module):
u'name': module.params.get('name'),
u'type': module.params.get('type'),
u'ttl': module.params.get('ttl'),
u'rrdatas': module.params.get('target')
u'rrdatas': module.params.get('target'),
}
return_vals = {}
for k, v in request.items():
@ -283,16 +274,13 @@ def self_link(module):
'project': module.params['project'],
'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name'),
'name': module.params['name'],
'type': module.params['type']
'type': module.params['type'],
}
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets?name={name}&type={type}".format(**res)
def collection(module):
res = {
'project': module.params['project'],
'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')
}
res = {'project': module.params['project'], 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')}
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**res)
@ -308,8 +296,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -338,12 +326,7 @@ def is_different(module, response):
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'name': response.get(u'name'),
u'type': response.get(u'type'),
u'ttl': response.get(u'ttl'),
u'rrdatas': response.get(u'target')
}
return {u'name': response.get(u'name'), u'type': response.get(u'type'), u'ttl': response.get(u'ttl'), u'rrdatas': response.get(u'target')}
def updated_record(module):
@ -352,7 +335,7 @@ def updated_record(module):
'name': module.params['name'],
'type': module.params['type'],
'ttl': module.params['ttl'] if module.params['ttl'] else 900,
'rrdatas': module.params['target']
'rrdatas': module.params['target'],
}
@ -377,20 +360,21 @@ class SOAForwardable(object):
def prefetch_soa_resource(module):
name = module.params['name'].split('.')[1:]
resource = SOAForwardable({
'type': 'SOA',
'managed_zone': module.params['managed_zone'],
'name': '.'.join(name),
'project': module.params['project'],
'scopes': module.params['scopes'],
'service_account_file': module.params['service_account_file'],
'auth_kind': module.params['auth_kind'],
'service_account_email': module.params['service_account_email']
}, module)
resource = SOAForwardable(
{
'type': 'SOA',
'managed_zone': module.params['managed_zone'],
'name': '.'.join(name),
'project': module.params['project'],
'scopes': module.params['scopes'],
'service_account_file': module.params['service_account_file'],
'auth_kind': module.params['auth_kind'],
'service_account_email': module.params['service_account_email'],
},
module,
)
result = fetch_wrapped_resource(resource, 'dns#resourceRecordSet',
'dns#resourceRecordSetsListResponse',
'rrsets')
result = fetch_wrapped_resource(resource, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets')
if not result:
raise ValueError("Google DNS Managed Zone %s not found" % module.params['managed_zone']['name'])
return result
@ -398,11 +382,7 @@ def prefetch_soa_resource(module):
def create_change(original, updated, module):
auth = GcpSession(module, 'dns')
return return_if_change_object(module,
auth.post(collection(module),
resource_to_change_request(
original, updated, module)
))
return return_if_change_object(module, auth.post(collection(module), resource_to_change_request(original, updated, module)))
# Fetch current SOA. We need the last SOA so we can increment its serial
@ -458,12 +438,7 @@ def get_change_status(change_id, module):
def new_change_request():
return {
'kind': 'dns#change',
'additions': [],
'deletions': [],
'start_time': datetime.datetime.now().isoformat()
}
return {'kind': 'dns#change', 'additions': [], 'deletions': [], 'start_time': datetime.datetime.now().isoformat()}
def return_if_change_object(module, response):

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -108,11 +107,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
managed_zone=dict(required=True)
)
)
module = GcpModule(argument_spec=dict(managed_zone=dict(required=True)))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
@ -122,17 +117,12 @@ def main():
items = items.get('rrsets')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)
def collection(module):
res = {
'project': module.params['project'],
'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')
}
res = {'project': module.params['project'], 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')}
return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets".format(**res)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -121,11 +120,7 @@ def main():
"""Main function"""
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
display_name=dict(type='str')
)
argument_spec=dict(state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(type='str'), display_name=dict(type='str'))
)
if not module.params['scopes']:
@ -174,10 +169,7 @@ def delete(module, link):
def resource_to_request(module):
request = {
u'name': module.params.get('name'),
u'displayName': module.params.get('display_name')
}
request = {u'name': module.params.get('name'), u'displayName': module.params.get('display_name')}
request = encode_request(request, module)
return_vals = {}
for k, v in request.items():
@ -212,8 +204,8 @@ def return_if_object(module, response, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module)
@ -251,7 +243,7 @@ def response_to_hash(module, response):
u'uniqueId': response.get(u'uniqueId'),
u'email': response.get(u'email'),
u'displayName': response.get(u'displayName'),
u'oauth2ClientId': response.get(u'oauth2ClientId')
u'oauth2ClientId': response.get(u'oauth2ClientId'),
}
@ -259,10 +251,7 @@ def encode_request(resource_request, module):
"""Structures the request as accountId + rest of request"""
account_id = resource_request['name'].split('@')[0]
del resource_request['name']
return {
'accountId': account_id,
'serviceAccount': resource_request
}
return {'accountId': account_id, 'serviceAccount': resource_request}
def decode_response(response, module):

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -102,10 +101,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
)
)
module = GcpModule(argument_spec=dict())
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/iam']
@ -115,9 +111,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -179,10 +178,8 @@ def main():
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
topic=dict(),
push_config=dict(type='dict', options=dict(
push_endpoint=dict(type='str')
)),
ack_deadline_seconds=dict(type='int')
push_config=dict(type='dict', options=dict(push_endpoint=dict(type='str'))),
ack_deadline_seconds=dict(type='int'),
)
)
@ -235,7 +232,7 @@ def resource_to_request(module):
u'name': module.params.get('name'),
u'topic': replace_resource_dict(module.params.get(u'topic', {}), 'name'),
u'pushConfig': SubscriptionPushconfig(module.params.get('push_config', {}), module).to_request(),
u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds')
u'ackDeadlineSeconds': module.params.get('ack_deadline_seconds'),
}
request = encode_request(request, module)
return_vals = {}
@ -271,8 +268,8 @@ def return_if_object(module, response, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_request(result, module)
@ -308,7 +305,7 @@ def response_to_hash(module, response):
u'name': response.get(u'name'),
u'topic': response.get(u'topic'),
u'pushConfig': SubscriptionPushconfig(response.get(u'pushConfig', {}), module).from_response(),
u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds')
u'ackDeadlineSeconds': response.get(u'ackDeadlineSeconds'),
}
@ -323,10 +320,8 @@ def decode_request(response, module):
def encode_request(request, module):
request['topic'] = '/'.join(['projects', module.params['project'],
'topics', module.params['topic']['name']])
request['name'] = '/'.join(['projects', module.params['project'],
'subscriptions', module.params['name']])
request['topic'] = '/'.join(['projects', module.params['project'], 'topics', module.params['topic']['name']])
request['name'] = '/'.join(['projects', module.params['project'], 'subscriptions', module.params['name']])
return request
@ -340,14 +335,10 @@ class SubscriptionPushconfig(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'pushEndpoint': self.request.get('push_endpoint')
})
return remove_nones_from_dict({u'pushEndpoint': self.request.get('push_endpoint')})
def from_response(self):
return remove_nones_from_dict({
u'pushEndpoint': self.request.get(u'pushEndpoint')
})
return remove_nones_from_dict({u'pushEndpoint': self.request.get(u'pushEndpoint')})
if __name__ == '__main__':

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -115,10 +114,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
)
)
module = GcpModule(argument_spec=dict())
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
@ -128,9 +124,7 @@ def main():
items = items.get('subscriptions')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -88,12 +87,7 @@ import json
def main():
"""Main function"""
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str')
)
)
module = GcpModule(argument_spec=dict(state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
@ -141,9 +135,7 @@ def delete(module, link):
def resource_to_request(module):
request = {
u'name': module.params.get('name')
}
request = {u'name': module.params.get('name')}
request = encode_request(request, module)
return_vals = {}
for k, v in request.items():
@ -178,8 +170,8 @@ def return_if_object(module, response, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_request(result, module)
@ -211,9 +203,7 @@ def is_different(module, response):
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'name': response.get(u'name')
}
return {u'name': response.get(u'name')}
def decode_request(response, module):
@ -223,8 +213,7 @@ def decode_request(response, module):
def encode_request(request, module):
request['name'] = '/'.join(['projects', module.params['project'],
'topics', module.params['name']])
request['name'] = '/'.join(['projects', module.params['project'], 'topics', module.params['name']])
return request

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -77,10 +76,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
)
)
module = GcpModule(argument_spec=dict())
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/pubsub']
@ -90,9 +86,7 @@ def main():
items = items.get('topics')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -182,11 +181,8 @@ def main():
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
labels=dict(type='dict'),
parent=dict(type='dict', options=dict(
type=dict(type='str'),
id=dict(type='str')
)),
id=dict(required=True, type='str')
parent=dict(type='dict', options=dict(type=dict(type='str'), id=dict(type='str'))),
id=dict(required=True, type='str'),
)
)
@ -240,7 +236,7 @@ def resource_to_request(module):
u'projectId': module.params.get('id'),
u'name': module.params.get('name'),
u'labels': module.params.get('labels'),
u'parent': ProjectParent(module.params.get('parent', {}), module).to_request()
u'parent': ProjectParent(module.params.get('parent', {}), module).to_request(),
}
return_vals = {}
for k, v in request.items():
@ -314,7 +310,7 @@ def response_to_hash(module, response):
u'name': response.get(u'name'),
u'createTime': response.get(u'createTime'),
u'labels': response.get(u'labels'),
u'parent': ProjectParent(response.get(u'parent', {}), module).from_response()
u'parent': ProjectParent(response.get(u'parent', {}), module).from_response(),
}
@ -333,6 +329,7 @@ def wait_for_operation(module, response):
return {}
status = navigate_hash(op_result, ['done'])
wait_done = wait_for_completion(status, op_result, module)
raise_if_errors(op_result, ['error'], module)
return navigate_hash(wait_done, ['response'])
@ -340,7 +337,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
if not status:
raise_if_errors(op_result, ['error'], 'message')
raise_if_errors(op_result, ['error'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri)
status = navigate_hash(op_result, ['done'])
@ -362,16 +359,10 @@ class ProjectParent(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'type': self.request.get('type'),
u'id': self.request.get('id')
})
return remove_nones_from_dict({u'type': self.request.get('type'), u'id': self.request.get('id')})
def from_response(self):
return remove_nones_from_dict({
u'type': self.request.get(u'type'),
u'id': self.request.get(u'id')
})
return remove_nones_from_dict({u'type': self.request.get(u'type'), u'id': self.request.get(u'id')})
if __name__ == '__main__':

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -129,10 +128,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
)
)
module = GcpModule(argument_spec=dict())
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
@ -142,9 +138,7 @@ def main():
items = items.get('projects')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -51,9 +50,8 @@ options:
name:
description:
- A unique identifier for the database, which cannot be changed after the instance
is created. Values are of the form projects/<project>/instances/[a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
required: false
is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9].
required: true
extra_statements:
description:
- 'An optional list of DDL statements to run inside the newly created database.
@ -70,6 +68,9 @@ options:
task and then set this instance field to "{{ name-of-resource }}"'
required: true
extends_documentation_fragment: gcp
notes:
- 'API Reference: U(https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances.databases)'
- 'Official Documentation: U(https://cloud.google.com/spanner/)'
'''
EXAMPLES = '''
@ -101,8 +102,7 @@ RETURN = '''
name:
description:
- A unique identifier for the database, which cannot be changed after the instance
is created. Values are of the form projects/<project>/instances/[a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9].
returned: success
type: str
extraStatements:
@ -138,9 +138,9 @@ def main():
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
name=dict(required=True, type='str'),
extra_statements=dict(type='list', elements='str'),
instance=dict(required=True)
instance=dict(required=True),
)
)
@ -180,8 +180,7 @@ def create(module, link):
def update(module, link):
auth = GcpSession(module, 'spanner')
return return_if_object(module, auth.put(link, resource_to_request(module)))
module.fail_json(msg="Database cannot be edited")
def delete(module, link):
@ -191,8 +190,9 @@ def delete(module, link):
def resource_to_request(module):
request = {
u'instance': replace_resource_dict(module.params.get(u'instance', {}), 'name'),
u'name': module.params.get('name'),
u'extraStatements': module.params.get('extra_statements')
u'extraStatements': module.params.get('extra_statements'),
}
request = encode_request(request, module)
return_vals = {}
@ -209,19 +209,12 @@ def fetch_resource(module, link, allow_not_found=True):
def self_link(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name'),
'name': module.params['name']
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name'), 'name': module.params['name']}
return "https://spanner.googleapis.com/v1/projects/{project}/instances/{instance}/databases/{name}".format(**res)
def collection(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name')
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
return "https://spanner.googleapis.com/v1/projects/{project}/instances/{instance}/databases".format(**res)
@ -237,8 +230,8 @@ def return_if_object(module, response, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module)
@ -270,10 +263,7 @@ def is_different(module, response):
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'name': response.get(u'name'),
u'extraStatements': module.params.get('extra_statements')
}
return {u'name': module.params.get('name'), u'extraStatements': module.params.get('extra_statements')}
def decode_response(response, module):

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -70,8 +69,7 @@ items:
name:
description:
- A unique identifier for the database, which cannot be changed after the instance
is created. Values are of the form projects/<project>/instances/[a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9].
returned: success
type: str
extraStatements:
@ -101,11 +99,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
instance=dict(required=True)
)
)
module = GcpModule(argument_spec=dict(instance=dict(required=True)))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin']
@ -115,17 +109,12 @@ def main():
items = items.get('databases')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)
def collection(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name')
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
return "https://spanner.googleapis.com/v1/projects/{project}/instances/{instance}/databases".format(**res)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -51,13 +50,17 @@ options:
name:
description:
- A unique identifier for the instance, which cannot be changed after the instance
is created. Values are of the form projects/<project>/instances/[a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
required: false
is created. The name must be between 6 and 30 characters in length.
required: true
config:
description:
- A reference to the instance configuration.
required: false
- The name of the instance's configuration (similar but not quite the same as
a region) which defines defines the geographic placement and replication of
your databases in this instance. It determines where your data is stored. Values
are typically of the form `regional-europe-west1` , `us-central` etc.
- In order to obtain a valid list please consult the [Configuration section of
the docs](U(https://cloud.google.com/spanner/docs/instances).)
required: true
display_name:
description:
- The descriptive name for this instance as it appears in UIs. Must be unique
@ -67,28 +70,16 @@ options:
description:
- The number of nodes allocated to this instance.
required: false
default: '1'
labels:
description:
- Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources
into groups that reflect a customer's organizational needs and deployment strategies.
Cloud Labels can be used to filter collections of resources. They can be used
to control how resource metrics are aggregated. And they can be used as arguments
to policy management rules (e.g. route, firewall, load balancing, etc.).
- 'Label keys must be between 1 and 63 characters long and must conform to the
following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.'
- Label values must be between 0 and 63 characters long and must conform to the
regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
- No more than 64 labels can be associated with a given resource.
- See U(https://goo.gl/xmQnxf) for more information on and examples of labels.
- 'If you plan to use labels in your own code, please note that additional characters
may be allowed in the future. And so you are advised to use an internal label
representation, such as JSON, which doesn''t rely upon specific characters being
disallowed. For example, representing labels as the string: name + "_" + value
would prove problematic if we were to allow "_" in a future release.'
- 'An object containing a list of "key": value pairs.'
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
required: false
extends_documentation_fragment: gcp
notes:
- 'API Reference: U(https://cloud.google.com/spanner/docs/reference/rest/v1/projects.instances)'
- 'Official Documentation: U(https://cloud.google.com/spanner/)'
'''
EXAMPLES = '''
@ -110,13 +101,17 @@ RETURN = '''
name:
description:
- A unique identifier for the instance, which cannot be changed after the instance
is created. Values are of the form projects/<project>/instances/[a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
is created. The name must be between 6 and 30 characters in length.
returned: success
type: str
config:
description:
- A reference to the instance configuration.
- The name of the instance's configuration (similar but not quite the same as a
region) which defines defines the geographic placement and replication of your
databases in this instance. It determines where your data is stored. Values are
typically of the form `regional-europe-west1` , `us-central` etc.
- In order to obtain a valid list please consult the [Configuration section of the
docs](U(https://cloud.google.com/spanner/docs/instances).)
returned: success
type: str
displayName:
@ -132,22 +127,6 @@ nodeCount:
type: int
labels:
description:
- Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources
into groups that reflect a customer's organizational needs and deployment strategies.
Cloud Labels can be used to filter collections of resources. They can be used
to control how resource metrics are aggregated. And they can be used as arguments
to policy management rules (e.g. route, firewall, load balancing, etc.).
- 'Label keys must be between 1 and 63 characters long and must conform to the following
regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.'
- Label values must be between 0 and 63 characters long and must conform to the
regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
- No more than 64 labels can be associated with a given resource.
- See U(https://goo.gl/xmQnxf) for more information on and examples of labels.
- 'If you plan to use labels in your own code, please note that additional characters
may be allowed in the future. And so you are advised to use an internal label
representation, such as JSON, which doesn''t rely upon specific characters being
disallowed. For example, representing labels as the string: name + "_" + value
would prove problematic if we were to allow "_" in a future release.'
- 'An object containing a list of "key": value pairs.'
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
returned: success
@ -160,6 +139,7 @@ labels:
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict
import json
import time
################################################################################
# Main
@ -172,11 +152,11 @@ def main():
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
config=dict(type='str'),
name=dict(required=True, type='str'),
config=dict(required=True, type='str'),
display_name=dict(required=True, type='str'),
node_count=dict(type='int'),
labels=dict(type='dict')
node_count=dict(default=1, type='int'),
labels=dict(type='dict'),
)
)
@ -212,17 +192,17 @@ def main():
def create(module, link):
auth = GcpSession(module, 'spanner')
return return_if_object(module, auth.post(link, resource_to_create(module)))
return wait_for_operation(module, auth.post(link, resource_to_create(module)))
def update(module, link):
auth = GcpSession(module, 'spanner')
return return_if_object(module, auth.patch(link, resource_to_update(module)))
return wait_for_operation(module, auth.patch(link, resource_to_update(module)))
def delete(module, link):
auth = GcpSession(module, 'spanner')
return return_if_object(module, auth.delete(link))
return wait_for_operation(module, auth.delete(link))
def resource_to_request(module):
@ -231,7 +211,7 @@ def resource_to_request(module):
u'config': module.params.get('config'),
u'displayName': module.params.get('display_name'),
u'nodeCount': module.params.get('node_count'),
u'labels': module.params.get('labels')
u'labels': module.params.get('labels'),
}
return_vals = {}
for k, v in request.items():
@ -266,8 +246,8 @@ def return_if_object(module, response, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module)
@ -300,36 +280,61 @@ def is_different(module, response):
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'name': response.get(u'name'),
u'name': module.params.get('name'),
u'config': response.get(u'config'),
u'displayName': response.get(u'displayName'),
u'nodeCount': response.get(u'nodeCount'),
u'labels': response.get(u'labels')
u'labels': response.get(u'labels'),
}
def async_op_url(module, extra_data=None):
if extra_data is None:
extra_data = {}
url = "https://spanner.googleapis.com/v1/projects/{project}/global/operations/{op_id}"
combined = extra_data.copy()
combined.update(module.params)
return url.format(**combined)
def wait_for_operation(module, response):
op_result = return_if_object(module, response)
if op_result is None:
return {}
status = navigate_hash(op_result, ['status'])
wait_done = wait_for_completion(status, op_result, module)
return fetch_resource(module, navigate_hash(wait_done, ['targetLink']))
def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri)
status = navigate_hash(op_result, ['status'])
return op_result
def raise_if_errors(response, err_path, module):
errors = navigate_hash(response, err_path)
if errors is not None:
module.fail_json(msg=errors)
def resource_to_create(module):
instance = resource_to_request(module)
instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'],
module.params['name'])
instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'],
instance['config'])
return {
'instanceId': module.params['name'],
'instance': instance
}
instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'], module.params['name'])
instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'], instance['config'])
return {'instanceId': module.params['name'], 'instance': instance}
def resource_to_update(module):
instance = resource_to_request(module)
instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'],
module.params['name'])
instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'],
instance['config'])
return {
'instance': instance,
'fieldMask': "'name' ,'config' ,'displayName' ,'nodeCount' ,'labels'"
}
instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'], module.params['name'])
instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'], instance['config'])
return {'instance': instance, 'fieldMask': "'name' ,'config' ,'displayName' ,'nodeCount' ,'labels'"}
def decode_response(response, module):

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -61,13 +60,17 @@ items:
name:
description:
- A unique identifier for the instance, which cannot be changed after the instance
is created. Values are of the form projects/<project>/instances/[a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
is created. The name must be between 6 and 30 characters in length.
returned: success
type: str
config:
description:
- A reference to the instance configuration.
- The name of the instance's configuration (similar but not quite the same as
a region) which defines defines the geographic placement and replication of
your databases in this instance. It determines where your data is stored.
Values are typically of the form `regional-europe-west1` , `us-central` etc.
- In order to obtain a valid list please consult the [Configuration section
of the docs](U(https://cloud.google.com/spanner/docs/instances).)
returned: success
type: str
displayName:
@ -83,23 +86,6 @@ items:
type: int
labels:
description:
- Cloud Labels are a flexible and lightweight mechanism for organizing cloud
resources into groups that reflect a customer's organizational needs and deployment
strategies. Cloud Labels can be used to filter collections of resources. They
can be used to control how resource metrics are aggregated. And they can be
used as arguments to policy management rules (e.g. route, firewall, load balancing,
etc.).
- 'Label keys must be between 1 and 63 characters long and must conform to the
following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.'
- Label values must be between 0 and 63 characters long and must conform to
the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
- No more than 64 labels can be associated with a given resource.
- See U(https://goo.gl/xmQnxf) for more information on and examples of labels.
- 'If you plan to use labels in your own code, please note that additional characters
may be allowed in the future. And so you are advised to use an internal label
representation, such as JSON, which doesn''t rely upon specific characters
being disallowed. For example, representing labels as the string: name + "_"
+ value would prove problematic if we were to allow "_" in a future release.'
- 'An object containing a list of "key": value pairs.'
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
returned: success
@ -118,10 +104,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
)
)
module = GcpModule(argument_spec=dict())
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin']
@ -131,9 +114,7 @@ def main():
items = items.get('instances')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -146,7 +145,7 @@ def main():
charset=dict(type='str'),
collation=dict(type='str'),
name=dict(type='str'),
instance=dict(required=True)
instance=dict(required=True),
)
)
@ -201,7 +200,7 @@ def resource_to_request(module):
u'kind': 'sql#database',
u'charset': module.params.get('charset'),
u'collation': module.params.get('collation'),
u'name': module.params.get('name')
u'name': module.params.get('name'),
}
return_vals = {}
for k, v in request.items():
@ -217,19 +216,12 @@ def fetch_resource(module, link, kind, allow_not_found=True):
def self_link(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name'),
'name': module.params['name']
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name'), 'name': module.params['name']}
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases/{name}".format(**res)
def collection(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name')
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases".format(**res)
@ -278,11 +270,7 @@ def is_different(module, response):
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'charset': response.get(u'charset'),
u'collation': response.get(u'collation'),
u'name': response.get(u'name')
}
return {u'charset': response.get(u'charset'), u'collation': response.get(u'collation'), u'name': response.get(u'name')}
def async_op_url(module, extra_data=None):
@ -307,7 +295,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'sql#operation')
status = navigate_hash(op_result, ['status'])

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -102,11 +101,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
instance=dict(required=True)
)
)
module = GcpModule(argument_spec=dict(instance=dict(required=True)))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin']
@ -116,17 +111,12 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)
def collection(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name')
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/databases".format(**res)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -571,46 +570,53 @@ def main():
backend_type=dict(type='str', choices=['FIRST_GEN', 'SECOND_GEN', 'EXTERNAL']),
connection_name=dict(type='str'),
database_version=dict(type='str', choices=['MYSQL_5_5', 'MYSQL_5_6', 'MYSQL_5_7', 'POSTGRES_9_6']),
failover_replica=dict(type='dict', options=dict(
available=dict(type='bool'),
name=dict(type='str')
)),
failover_replica=dict(type='dict', options=dict(available=dict(type='bool'), name=dict(type='str'))),
instance_type=dict(type='str', choices=['CLOUD_SQL_INSTANCE', 'ON_PREMISES_INSTANCE', 'READ_REPLICA_INSTANCE']),
ipv6_address=dict(type='str'),
master_instance_name=dict(type='str'),
max_disk_size=dict(type='int'),
name=dict(required=True, type='str'),
region=dict(type='str'),
replica_configuration=dict(type='dict', options=dict(
failover_target=dict(type='bool'),
mysql_replica_configuration=dict(type='dict', options=dict(
ca_certificate=dict(type='str'),
client_certificate=dict(type='str'),
client_key=dict(type='str'),
connect_retry_interval=dict(type='int'),
dump_file_path=dict(type='str'),
master_heartbeat_period=dict(type='int'),
password=dict(type='str'),
ssl_cipher=dict(type='str'),
username=dict(type='str'),
verify_server_certificate=dict(type='bool')
)),
replica_names=dict(type='list', elements='str'),
service_account_email_address=dict(type='str')
)),
settings=dict(type='dict', options=dict(
ip_configuration=dict(type='dict', options=dict(
ipv4_enabled=dict(type='bool'),
authorized_networks=dict(type='list', elements='dict', options=dict(
expiration_time=dict(type='str'),
name=dict(type='str'),
value=dict(type='str')
)),
require_ssl=dict(type='bool')
)),
tier=dict(type='str'),
settings_version=dict(type='int')
))
replica_configuration=dict(
type='dict',
options=dict(
failover_target=dict(type='bool'),
mysql_replica_configuration=dict(
type='dict',
options=dict(
ca_certificate=dict(type='str'),
client_certificate=dict(type='str'),
client_key=dict(type='str'),
connect_retry_interval=dict(type='int'),
dump_file_path=dict(type='str'),
master_heartbeat_period=dict(type='int'),
password=dict(type='str'),
ssl_cipher=dict(type='str'),
username=dict(type='str'),
verify_server_certificate=dict(type='bool'),
),
),
replica_names=dict(type='list', elements='str'),
service_account_email_address=dict(type='str'),
),
),
settings=dict(
type='dict',
options=dict(
ip_configuration=dict(
type='dict',
options=dict(
ipv4_enabled=dict(type='bool'),
authorized_networks=dict(
type='list', elements='dict', options=dict(expiration_time=dict(type='str'), name=dict(type='str'), value=dict(type='str'))
),
require_ssl=dict(type='bool'),
),
),
tier=dict(type='str'),
settings_version=dict(type='int'),
),
),
)
)
@ -674,7 +680,7 @@ def resource_to_request(module):
u'name': module.params.get('name'),
u'region': module.params.get('region'),
u'replicaConfiguration': InstanceReplicaconfiguration(module.params.get('replica_configuration', {}), module).to_request(),
u'settings': InstanceSettings(module.params.get('settings', {}), module).to_request()
u'settings': InstanceSettings(module.params.get('settings', {}), module).to_request(),
}
return_vals = {}
for k, v in request.items():
@ -755,7 +761,7 @@ def response_to_hash(module, response):
u'name': response.get(u'name'),
u'region': response.get(u'region'),
u'replicaConfiguration': InstanceReplicaconfiguration(response.get(u'replicaConfiguration', {}), module).from_response(),
u'settings': InstanceSettings(response.get(u'settings', {}), module).from_response()
u'settings': InstanceSettings(response.get(u'settings', {}), module).from_response(),
}
@ -781,7 +787,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'sql#operation')
status = navigate_hash(op_result, ['status'])
@ -803,16 +809,10 @@ class InstanceFailoverreplica(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'available': self.request.get('available'),
u'name': self.request.get('name')
})
return remove_nones_from_dict({u'available': self.request.get('available'), u'name': self.request.get('name')})
def from_response(self):
return remove_nones_from_dict({
u'available': self.request.get(u'available'),
u'name': self.request.get(u'name')
})
return remove_nones_from_dict({u'available': self.request.get(u'available'), u'name': self.request.get(u'name')})
class InstanceIpaddressesArray(object):
@ -836,18 +836,10 @@ class InstanceIpaddressesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'ipAddress': item.get('ip_address'),
u'timeToRetire': item.get('time_to_retire'),
u'type': item.get('type')
})
return remove_nones_from_dict({u'ipAddress': item.get('ip_address'), u'timeToRetire': item.get('time_to_retire'), u'type': item.get('type')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'ipAddress': item.get(u'ipAddress'),
u'timeToRetire': item.get(u'timeToRetire'),
u'type': item.get(u'type')
})
return remove_nones_from_dict({u'ipAddress': item.get(u'ipAddress'), u'timeToRetire': item.get(u'timeToRetire'), u'type': item.get(u'type')})
class InstanceReplicaconfiguration(object):
@ -859,20 +851,26 @@ class InstanceReplicaconfiguration(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'failoverTarget': self.request.get('failover_target'),
u'mysqlReplicaConfiguration': InstanceMysqlreplicaconfiguration(self.request.get('mysql_replica_configuration', {}), self.module).to_request(),
u'replicaNames': self.request.get('replica_names'),
u'serviceAccountEmailAddress': self.request.get('service_account_email_address')
})
return remove_nones_from_dict(
{
u'failoverTarget': self.request.get('failover_target'),
u'mysqlReplicaConfiguration': InstanceMysqlreplicaconfiguration(self.request.get('mysql_replica_configuration', {}), self.module).to_request(),
u'replicaNames': self.request.get('replica_names'),
u'serviceAccountEmailAddress': self.request.get('service_account_email_address'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'failoverTarget': self.request.get(u'failoverTarget'),
u'mysqlReplicaConfiguration': InstanceMysqlreplicaconfiguration(self.request.get(u'mysqlReplicaConfiguration', {}), self.module).from_response(),
u'replicaNames': self.request.get(u'replicaNames'),
u'serviceAccountEmailAddress': self.request.get(u'serviceAccountEmailAddress')
})
return remove_nones_from_dict(
{
u'failoverTarget': self.request.get(u'failoverTarget'),
u'mysqlReplicaConfiguration': InstanceMysqlreplicaconfiguration(
self.request.get(u'mysqlReplicaConfiguration', {}), self.module
).from_response(),
u'replicaNames': self.request.get(u'replicaNames'),
u'serviceAccountEmailAddress': self.request.get(u'serviceAccountEmailAddress'),
}
)
class InstanceMysqlreplicaconfiguration(object):
@ -884,32 +882,36 @@ class InstanceMysqlreplicaconfiguration(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'caCertificate': self.request.get('ca_certificate'),
u'clientCertificate': self.request.get('client_certificate'),
u'clientKey': self.request.get('client_key'),
u'connectRetryInterval': self.request.get('connect_retry_interval'),
u'dumpFilePath': self.request.get('dump_file_path'),
u'masterHeartbeatPeriod': self.request.get('master_heartbeat_period'),
u'password': self.request.get('password'),
u'sslCipher': self.request.get('ssl_cipher'),
u'username': self.request.get('username'),
u'verifyServerCertificate': self.request.get('verify_server_certificate')
})
return remove_nones_from_dict(
{
u'caCertificate': self.request.get('ca_certificate'),
u'clientCertificate': self.request.get('client_certificate'),
u'clientKey': self.request.get('client_key'),
u'connectRetryInterval': self.request.get('connect_retry_interval'),
u'dumpFilePath': self.request.get('dump_file_path'),
u'masterHeartbeatPeriod': self.request.get('master_heartbeat_period'),
u'password': self.request.get('password'),
u'sslCipher': self.request.get('ssl_cipher'),
u'username': self.request.get('username'),
u'verifyServerCertificate': self.request.get('verify_server_certificate'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'caCertificate': self.request.get(u'caCertificate'),
u'clientCertificate': self.request.get(u'clientCertificate'),
u'clientKey': self.request.get(u'clientKey'),
u'connectRetryInterval': self.request.get(u'connectRetryInterval'),
u'dumpFilePath': self.request.get(u'dumpFilePath'),
u'masterHeartbeatPeriod': self.request.get(u'masterHeartbeatPeriod'),
u'password': self.request.get(u'password'),
u'sslCipher': self.request.get(u'sslCipher'),
u'username': self.request.get(u'username'),
u'verifyServerCertificate': self.request.get(u'verifyServerCertificate')
})
return remove_nones_from_dict(
{
u'caCertificate': self.request.get(u'caCertificate'),
u'clientCertificate': self.request.get(u'clientCertificate'),
u'clientKey': self.request.get(u'clientKey'),
u'connectRetryInterval': self.request.get(u'connectRetryInterval'),
u'dumpFilePath': self.request.get(u'dumpFilePath'),
u'masterHeartbeatPeriod': self.request.get(u'masterHeartbeatPeriod'),
u'password': self.request.get(u'password'),
u'sslCipher': self.request.get(u'sslCipher'),
u'username': self.request.get(u'username'),
u'verifyServerCertificate': self.request.get(u'verifyServerCertificate'),
}
)
class InstanceSettings(object):
@ -921,18 +923,22 @@ class InstanceSettings(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'ipConfiguration': InstanceIpconfiguration(self.request.get('ip_configuration', {}), self.module).to_request(),
u'tier': self.request.get('tier'),
u'settingsVersion': self.request.get('settings_version')
})
return remove_nones_from_dict(
{
u'ipConfiguration': InstanceIpconfiguration(self.request.get('ip_configuration', {}), self.module).to_request(),
u'tier': self.request.get('tier'),
u'settingsVersion': self.request.get('settings_version'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'ipConfiguration': InstanceIpconfiguration(self.request.get(u'ipConfiguration', {}), self.module).from_response(),
u'tier': self.request.get(u'tier'),
u'settingsVersion': self.request.get(u'settingsVersion')
})
return remove_nones_from_dict(
{
u'ipConfiguration': InstanceIpconfiguration(self.request.get(u'ipConfiguration', {}), self.module).from_response(),
u'tier': self.request.get(u'tier'),
u'settingsVersion': self.request.get(u'settingsVersion'),
}
)
class InstanceIpconfiguration(object):
@ -944,18 +950,22 @@ class InstanceIpconfiguration(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'ipv4Enabled': self.request.get('ipv4_enabled'),
u'authorizedNetworks': InstanceAuthorizednetworksArray(self.request.get('authorized_networks', []), self.module).to_request(),
u'requireSsl': self.request.get('require_ssl')
})
return remove_nones_from_dict(
{
u'ipv4Enabled': self.request.get('ipv4_enabled'),
u'authorizedNetworks': InstanceAuthorizednetworksArray(self.request.get('authorized_networks', []), self.module).to_request(),
u'requireSsl': self.request.get('require_ssl'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'ipv4Enabled': self.request.get(u'ipv4Enabled'),
u'authorizedNetworks': InstanceAuthorizednetworksArray(self.request.get(u'authorizedNetworks', []), self.module).from_response(),
u'requireSsl': self.request.get(u'requireSsl')
})
return remove_nones_from_dict(
{
u'ipv4Enabled': self.request.get(u'ipv4Enabled'),
u'authorizedNetworks': InstanceAuthorizednetworksArray(self.request.get(u'authorizedNetworks', []), self.module).from_response(),
u'requireSsl': self.request.get(u'requireSsl'),
}
)
class InstanceAuthorizednetworksArray(object):
@ -979,18 +989,10 @@ class InstanceAuthorizednetworksArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'expirationTime': item.get('expiration_time'),
u'name': item.get('name'),
u'value': item.get('value')
})
return remove_nones_from_dict({u'expirationTime': item.get('expiration_time'), u'name': item.get('name'), u'value': item.get('value')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'expirationTime': item.get(u'expirationTime'),
u'name': item.get(u'name'),
u'value': item.get(u'value')
})
return remove_nones_from_dict({u'expirationTime': item.get(u'expirationTime'), u'name': item.get(u'name'), u'value': item.get(u'value')})
if __name__ == '__main__':

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -335,10 +334,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
)
)
module = GcpModule(argument_spec=dict())
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin']
@ -348,9 +344,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -149,7 +148,7 @@ def main():
host=dict(required=True, type='str'),
name=dict(required=True, type='str'),
instance=dict(required=True),
password=dict(type='str')
password=dict(type='str'),
)
)
@ -159,9 +158,7 @@ def main():
state = module.params['state']
kind = 'sql#user'
fetch = fetch_wrapped_resource(module, 'sql#user',
'sql#usersList',
'items')
fetch = fetch_wrapped_resource(module, 'sql#user', 'sql#usersList', 'items')
changed = False
if fetch:
@ -202,12 +199,7 @@ def delete(module, link, kind):
def resource_to_request(module):
request = {
u'kind': 'sql#user',
u'password': module.params.get('password'),
u'host': module.params.get('host'),
u'name': module.params.get('name')
}
request = {u'kind': 'sql#user', u'password': module.params.get('password'), u'host': module.params.get('host'), u'name': module.params.get('name')}
return_vals = {}
for k, v in request.items():
if v or v is False:
@ -217,10 +209,7 @@ def resource_to_request(module):
def unwrap_resource_filter(module):
return {
'host': module.params['host'],
'name': module.params['name']
}
return {'host': module.params['host'], 'name': module.params['name']}
def unwrap_resource(result, module):
@ -264,16 +253,13 @@ def self_link(module):
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name'),
'name': module.params['name'],
'host': module.params['host']
'host': module.params['host'],
}
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users?name={name}&host={host}".format(**res)
def collection(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name')
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users".format(**res)
@ -322,10 +308,7 @@ def is_different(module, response):
# Remove unnecessary properties from the response.
# This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response):
return {
u'host': response.get(u'host'),
u'name': response.get(u'name')
}
return {u'host': response.get(u'host'), u'name': response.get(u'name')}
def async_op_url(module, extra_data=None):
@ -350,7 +333,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'sql#operation')
status = navigate_hash(op_result, ['status'])

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -103,11 +102,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
instance=dict(required=True)
)
)
module = GcpModule(argument_spec=dict(instance=dict(required=True)))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/sqlservice.admin']
@ -117,17 +112,12 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)
def collection(module):
res = {
'project': module.params['project'],
'instance': replace_resource_dict(module.params['instance'], 'name')
}
res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
return "https://www.googleapis.com/sql/v1beta4/projects/{project}/instances/{instance}/users".format(**res)

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -790,81 +789,86 @@ def main():
module = GcpModule(
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
acl=dict(type='list', elements='dict', options=dict(
bucket=dict(required=True),
domain=dict(type='str'),
email=dict(type='str'),
entity=dict(required=True, type='str'),
entity_id=dict(type='str'),
id=dict(type='str'),
project_team=dict(type='dict', options=dict(
project_number=dict(type='str'),
team=dict(type='str', choices=['editors', 'owners', 'viewers'])
)),
role=dict(type='str', choices=['OWNER', 'READER', 'WRITER'])
)),
cors=dict(type='list', elements='dict', options=dict(
max_age_seconds=dict(type='int'),
method=dict(type='list', elements='str'),
origin=dict(type='list', elements='str'),
response_header=dict(type='list', elements='str')
)),
default_object_acl=dict(type='list', elements='dict', options=dict(
bucket=dict(required=True),
domain=dict(type='str'),
email=dict(type='str'),
entity=dict(required=True, type='str'),
entity_id=dict(type='str'),
generation=dict(type='int'),
id=dict(type='str'),
object=dict(type='str'),
project_team=dict(type='dict', options=dict(
project_number=dict(type='str'),
team=dict(type='str', choices=['editors', 'owners', 'viewers'])
)),
role=dict(required=True, type='str', choices=['OWNER', 'READER'])
)),
lifecycle=dict(type='dict', options=dict(
rule=dict(type='list', elements='dict', options=dict(
action=dict(type='dict', options=dict(
storage_class=dict(type='str'),
type=dict(type='str', choices=['Delete', 'SetStorageClass'])
)),
condition=dict(type='dict', options=dict(
age_days=dict(type='int'),
created_before=dict(type='str'),
is_live=dict(type='bool'),
matches_storage_class=dict(type='list', elements='str'),
num_newer_versions=dict(type='int')
))
))
)),
acl=dict(
type='list',
elements='dict',
options=dict(
bucket=dict(required=True),
domain=dict(type='str'),
email=dict(type='str'),
entity=dict(required=True, type='str'),
entity_id=dict(type='str'),
id=dict(type='str'),
project_team=dict(
type='dict', options=dict(project_number=dict(type='str'), team=dict(type='str', choices=['editors', 'owners', 'viewers']))
),
role=dict(type='str', choices=['OWNER', 'READER', 'WRITER']),
),
),
cors=dict(
type='list',
elements='dict',
options=dict(
max_age_seconds=dict(type='int'),
method=dict(type='list', elements='str'),
origin=dict(type='list', elements='str'),
response_header=dict(type='list', elements='str'),
),
),
default_object_acl=dict(
type='list',
elements='dict',
options=dict(
bucket=dict(required=True),
domain=dict(type='str'),
email=dict(type='str'),
entity=dict(required=True, type='str'),
entity_id=dict(type='str'),
generation=dict(type='int'),
id=dict(type='str'),
object=dict(type='str'),
project_team=dict(
type='dict', options=dict(project_number=dict(type='str'), team=dict(type='str', choices=['editors', 'owners', 'viewers']))
),
role=dict(required=True, type='str', choices=['OWNER', 'READER']),
),
),
lifecycle=dict(
type='dict',
options=dict(
rule=dict(
type='list',
elements='dict',
options=dict(
action=dict(
type='dict', options=dict(storage_class=dict(type='str'), type=dict(type='str', choices=['Delete', 'SetStorageClass']))
),
condition=dict(
type='dict',
options=dict(
age_days=dict(type='int'),
created_before=dict(type='str'),
is_live=dict(type='bool'),
matches_storage_class=dict(type='list', elements='str'),
num_newer_versions=dict(type='int'),
),
),
),
)
),
),
location=dict(type='str'),
logging=dict(type='dict', options=dict(
log_bucket=dict(type='str'),
log_object_prefix=dict(type='str')
)),
logging=dict(type='dict', options=dict(log_bucket=dict(type='str'), log_object_prefix=dict(type='str'))),
metageneration=dict(type='int'),
name=dict(type='str'),
owner=dict(type='dict', options=dict(
entity=dict(type='str'),
entity_id=dict(type='str')
)),
owner=dict(type='dict', options=dict(entity=dict(type='str'), entity_id=dict(type='str'))),
storage_class=dict(type='str', choices=['MULTI_REGIONAL', 'REGIONAL', 'STANDARD', 'NEARLINE', 'COLDLINE', 'DURABLE_REDUCED_AVAILABILITY']),
versioning=dict(type='dict', options=dict(
enabled=dict(type='bool')
)),
website=dict(type='dict', options=dict(
main_page_suffix=dict(type='str'),
not_found_page=dict(type='str')
)),
versioning=dict(type='dict', options=dict(enabled=dict(type='bool'))),
website=dict(type='dict', options=dict(main_page_suffix=dict(type='str'), not_found_page=dict(type='str'))),
project=dict(type='str'),
predefined_default_object_acl=dict(type='str', choices=['authenticatedRead',
'bucketOwnerFullControl',
'bucketOwnerRead',
'private',
'projectPrivate',
'publicRead'])
predefined_default_object_acl=dict(
type='str', choices=['authenticatedRead', 'bucketOwnerFullControl', 'bucketOwnerRead', 'private', 'projectPrivate', 'publicRead']
),
)
)
@ -930,7 +934,7 @@ def resource_to_request(module):
u'owner': BucketOwner(module.params.get('owner', {}), module).to_request(),
u'storageClass': module.params.get('storage_class'),
u'versioning': BucketVersioning(module.params.get('versioning', {}), module).to_request(),
u'website': BucketWebsite(module.params.get('website', {}), module).to_request()
u'website': BucketWebsite(module.params.get('website', {}), module).to_request(),
}
return_vals = {}
for k, v in request.items():
@ -965,8 +969,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -1011,7 +1015,7 @@ def response_to_hash(module, response):
u'timeCreated': response.get(u'timeCreated'),
u'updated': response.get(u'updated'),
u'versioning': BucketVersioning(response.get(u'versioning', {}), module).from_response(),
u'website': BucketWebsite(response.get(u'website', {}), module).from_response()
u'website': BucketWebsite(response.get(u'website', {}), module).from_response(),
}
@ -1036,28 +1040,32 @@ class BucketAclArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'bucket': replace_resource_dict(item.get(u'bucket', {}), 'name'),
u'domain': item.get('domain'),
u'email': item.get('email'),
u'entity': item.get('entity'),
u'entityId': item.get('entity_id'),
u'id': item.get('id'),
u'projectTeam': BucketProjectteam(item.get('project_team', {}), self.module).to_request(),
u'role': item.get('role')
})
return remove_nones_from_dict(
{
u'bucket': replace_resource_dict(item.get(u'bucket', {}), 'name'),
u'domain': item.get('domain'),
u'email': item.get('email'),
u'entity': item.get('entity'),
u'entityId': item.get('entity_id'),
u'id': item.get('id'),
u'projectTeam': BucketProjectteam(item.get('project_team', {}), self.module).to_request(),
u'role': item.get('role'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'bucket': item.get(u'bucket'),
u'domain': item.get(u'domain'),
u'email': item.get(u'email'),
u'entity': item.get(u'entity'),
u'entityId': item.get(u'entityId'),
u'id': item.get(u'id'),
u'projectTeam': BucketProjectteam(item.get(u'projectTeam', {}), self.module).from_response(),
u'role': item.get(u'role')
})
return remove_nones_from_dict(
{
u'bucket': item.get(u'bucket'),
u'domain': item.get(u'domain'),
u'email': item.get(u'email'),
u'entity': item.get(u'entity'),
u'entityId': item.get(u'entityId'),
u'id': item.get(u'id'),
u'projectTeam': BucketProjectteam(item.get(u'projectTeam', {}), self.module).from_response(),
u'role': item.get(u'role'),
}
)
class BucketProjectteam(object):
@ -1069,16 +1077,10 @@ class BucketProjectteam(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'projectNumber': self.request.get('project_number'),
u'team': self.request.get('team')
})
return remove_nones_from_dict({u'projectNumber': self.request.get('project_number'), u'team': self.request.get('team')})
def from_response(self):
return remove_nones_from_dict({
u'projectNumber': self.request.get(u'projectNumber'),
u'team': self.request.get(u'team')
})
return remove_nones_from_dict({u'projectNumber': self.request.get(u'projectNumber'), u'team': self.request.get(u'team')})
class BucketCorsArray(object):
@ -1102,20 +1104,24 @@ class BucketCorsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'maxAgeSeconds': item.get('max_age_seconds'),
u'method': item.get('method'),
u'origin': item.get('origin'),
u'responseHeader': item.get('response_header')
})
return remove_nones_from_dict(
{
u'maxAgeSeconds': item.get('max_age_seconds'),
u'method': item.get('method'),
u'origin': item.get('origin'),
u'responseHeader': item.get('response_header'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'maxAgeSeconds': item.get(u'maxAgeSeconds'),
u'method': item.get(u'method'),
u'origin': item.get(u'origin'),
u'responseHeader': item.get(u'responseHeader')
})
return remove_nones_from_dict(
{
u'maxAgeSeconds': item.get(u'maxAgeSeconds'),
u'method': item.get(u'method'),
u'origin': item.get(u'origin'),
u'responseHeader': item.get(u'responseHeader'),
}
)
class BucketDefaultobjectaclArray(object):
@ -1139,32 +1145,36 @@ class BucketDefaultobjectaclArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'bucket': replace_resource_dict(item.get(u'bucket', {}), 'name'),
u'domain': item.get('domain'),
u'email': item.get('email'),
u'entity': item.get('entity'),
u'entityId': item.get('entity_id'),
u'generation': item.get('generation'),
u'id': item.get('id'),
u'object': item.get('object'),
u'projectTeam': BucketProjectteam(item.get('project_team', {}), self.module).to_request(),
u'role': item.get('role')
})
return remove_nones_from_dict(
{
u'bucket': replace_resource_dict(item.get(u'bucket', {}), 'name'),
u'domain': item.get('domain'),
u'email': item.get('email'),
u'entity': item.get('entity'),
u'entityId': item.get('entity_id'),
u'generation': item.get('generation'),
u'id': item.get('id'),
u'object': item.get('object'),
u'projectTeam': BucketProjectteam(item.get('project_team', {}), self.module).to_request(),
u'role': item.get('role'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'bucket': item.get(u'bucket'),
u'domain': item.get(u'domain'),
u'email': item.get(u'email'),
u'entity': item.get(u'entity'),
u'entityId': item.get(u'entityId'),
u'generation': item.get(u'generation'),
u'id': item.get(u'id'),
u'object': item.get(u'object'),
u'projectTeam': BucketProjectteam(item.get(u'projectTeam', {}), self.module).from_response(),
u'role': item.get(u'role')
})
return remove_nones_from_dict(
{
u'bucket': item.get(u'bucket'),
u'domain': item.get(u'domain'),
u'email': item.get(u'email'),
u'entity': item.get(u'entity'),
u'entityId': item.get(u'entityId'),
u'generation': item.get(u'generation'),
u'id': item.get(u'id'),
u'object': item.get(u'object'),
u'projectTeam': BucketProjectteam(item.get(u'projectTeam', {}), self.module).from_response(),
u'role': item.get(u'role'),
}
)
class BucketProjectteam(object):
@ -1176,16 +1186,10 @@ class BucketProjectteam(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'projectNumber': self.request.get('project_number'),
u'team': self.request.get('team')
})
return remove_nones_from_dict({u'projectNumber': self.request.get('project_number'), u'team': self.request.get('team')})
def from_response(self):
return remove_nones_from_dict({
u'projectNumber': self.request.get(u'projectNumber'),
u'team': self.request.get(u'team')
})
return remove_nones_from_dict({u'projectNumber': self.request.get(u'projectNumber'), u'team': self.request.get(u'team')})
class BucketLifecycle(object):
@ -1197,14 +1201,10 @@ class BucketLifecycle(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rule': BucketRuleArray(self.request.get('rule', []), self.module).to_request()
})
return remove_nones_from_dict({u'rule': BucketRuleArray(self.request.get('rule', []), self.module).to_request()})
def from_response(self):
return remove_nones_from_dict({
u'rule': BucketRuleArray(self.request.get(u'rule', []), self.module).from_response()
})
return remove_nones_from_dict({u'rule': BucketRuleArray(self.request.get(u'rule', []), self.module).from_response()})
class BucketRuleArray(object):
@ -1228,16 +1228,20 @@ class BucketRuleArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'action': BucketAction(item.get('action', {}), self.module).to_request(),
u'condition': BucketCondition(item.get('condition', {}), self.module).to_request()
})
return remove_nones_from_dict(
{
u'action': BucketAction(item.get('action', {}), self.module).to_request(),
u'condition': BucketCondition(item.get('condition', {}), self.module).to_request(),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'action': BucketAction(item.get(u'action', {}), self.module).from_response(),
u'condition': BucketCondition(item.get(u'condition', {}), self.module).from_response()
})
return remove_nones_from_dict(
{
u'action': BucketAction(item.get(u'action', {}), self.module).from_response(),
u'condition': BucketCondition(item.get(u'condition', {}), self.module).from_response(),
}
)
class BucketAction(object):
@ -1249,16 +1253,10 @@ class BucketAction(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'storageClass': self.request.get('storage_class'),
u'type': self.request.get('type')
})
return remove_nones_from_dict({u'storageClass': self.request.get('storage_class'), u'type': self.request.get('type')})
def from_response(self):
return remove_nones_from_dict({
u'storageClass': self.request.get(u'storageClass'),
u'type': self.request.get(u'type')
})
return remove_nones_from_dict({u'storageClass': self.request.get(u'storageClass'), u'type': self.request.get(u'type')})
class BucketCondition(object):
@ -1270,22 +1268,26 @@ class BucketCondition(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'age': self.request.get('age_days'),
u'createdBefore': self.request.get('created_before'),
u'isLive': self.request.get('is_live'),
u'matchesStorageClass': self.request.get('matches_storage_class'),
u'numNewerVersions': self.request.get('num_newer_versions')
})
return remove_nones_from_dict(
{
u'age': self.request.get('age_days'),
u'createdBefore': self.request.get('created_before'),
u'isLive': self.request.get('is_live'),
u'matchesStorageClass': self.request.get('matches_storage_class'),
u'numNewerVersions': self.request.get('num_newer_versions'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'age': self.request.get(u'ageDays'),
u'createdBefore': self.request.get(u'createdBefore'),
u'isLive': self.request.get(u'isLive'),
u'matchesStorageClass': self.request.get(u'matchesStorageClass'),
u'numNewerVersions': self.request.get(u'numNewerVersions')
})
return remove_nones_from_dict(
{
u'age': self.request.get(u'ageDays'),
u'createdBefore': self.request.get(u'createdBefore'),
u'isLive': self.request.get(u'isLive'),
u'matchesStorageClass': self.request.get(u'matchesStorageClass'),
u'numNewerVersions': self.request.get(u'numNewerVersions'),
}
)
class BucketLogging(object):
@ -1297,16 +1299,10 @@ class BucketLogging(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'logBucket': self.request.get('log_bucket'),
u'logObjectPrefix': self.request.get('log_object_prefix')
})
return remove_nones_from_dict({u'logBucket': self.request.get('log_bucket'), u'logObjectPrefix': self.request.get('log_object_prefix')})
def from_response(self):
return remove_nones_from_dict({
u'logBucket': self.request.get(u'logBucket'),
u'logObjectPrefix': self.request.get(u'logObjectPrefix')
})
return remove_nones_from_dict({u'logBucket': self.request.get(u'logBucket'), u'logObjectPrefix': self.request.get(u'logObjectPrefix')})
class BucketOwner(object):
@ -1318,16 +1314,10 @@ class BucketOwner(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'entity': self.request.get('entity'),
u'entityId': self.request.get('entity_id')
})
return remove_nones_from_dict({u'entity': self.request.get('entity'), u'entityId': self.request.get('entity_id')})
def from_response(self):
return remove_nones_from_dict({
u'entity': self.request.get(u'entity'),
u'entityId': self.request.get(u'entityId')
})
return remove_nones_from_dict({u'entity': self.request.get(u'entity'), u'entityId': self.request.get(u'entityId')})
class BucketVersioning(object):
@ -1339,14 +1329,10 @@ class BucketVersioning(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'enabled': self.request.get('enabled')
})
return remove_nones_from_dict({u'enabled': self.request.get('enabled')})
def from_response(self):
return remove_nones_from_dict({
u'enabled': self.request.get(u'enabled')
})
return remove_nones_from_dict({u'enabled': self.request.get(u'enabled')})
class BucketWebsite(object):
@ -1358,16 +1344,10 @@ class BucketWebsite(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'mainPageSuffix': self.request.get('main_page_suffix'),
u'notFoundPage': self.request.get('not_found_page')
})
return remove_nones_from_dict({u'mainPageSuffix': self.request.get('main_page_suffix'), u'notFoundPage': self.request.get('not_found_page')})
def from_response(self):
return remove_nones_from_dict({
u'mainPageSuffix': self.request.get(u'mainPageSuffix'),
u'notFoundPage': self.request.get(u'notFoundPage')
})
return remove_nones_from_dict({u'mainPageSuffix': self.request.get(u'mainPageSuffix'), u'notFoundPage': self.request.get(u'notFoundPage')})
if __name__ == '__main__':

View file

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -207,11 +206,8 @@ def main():
bucket=dict(required=True),
entity=dict(required=True, type='str'),
entity_id=dict(type='str'),
project_team=dict(type='dict', options=dict(
project_number=dict(type='str'),
team=dict(type='str', choices=['editors', 'owners', 'viewers'])
)),
role=dict(type='str', choices=['OWNER', 'READER', 'WRITER'])
project_team=dict(type='dict', options=dict(project_number=dict(type='str'), team=dict(type='str', choices=['editors', 'owners', 'viewers']))),
role=dict(type='str', choices=['OWNER', 'READER', 'WRITER']),
)
)
@ -268,7 +264,7 @@ def resource_to_request(module):
u'entity': module.params.get('entity'),
u'entityId': module.params.get('entity_id'),
u'projectTeam': BucketAccessControlProjectteam(module.params.get('project_team', {}), module).to_request(),
u'role': module.params.get('role')
u'role': module.params.get('role'),
}
return_vals = {}
for k, v in request.items():
@ -303,8 +299,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -341,7 +337,7 @@ def response_to_hash(module, response):
u'entityId': response.get(u'entityId'),
u'id': response.get(u'id'),
u'projectTeam': BucketAccessControlProjectteam(response.get(u'projectTeam', {}), module).from_response(),
u'role': response.get(u'role')
u'role': response.get(u'role'),
}
@ -354,16 +350,10 @@ class BucketAccessControlProjectteam(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'projectNumber': self.request.get('project_number'),
u'team': self.request.get('team')
})
return remove_nones_from_dict({u'projectNumber': self.request.get('project_number'), u'team': self.request.get('team')})
def from_response(self):
return remove_nones_from_dict({
u'projectNumber': self.request.get(u'projectNumber'),
u'team': self.request.get(u'team')
})
return remove_nones_from_dict({u'projectNumber': self.request.get(u'projectNumber'), u'team': self.request.get(u'team')})
if __name__ == '__main__':