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

View file

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

View file

@ -18,15 +18,14 @@
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
################################################################################ ################################################################################
# Documentation # Documentation
################################################################################ ################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
'status': ["preview"],
'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -108,11 +107,7 @@ import json
def main(): def main():
module = GcpModule( module = GcpModule(argument_spec=dict(managed_zone=dict(required=True)))
argument_spec=dict(
managed_zone=dict(required=True)
)
)
if not module.params['scopes']: if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite'] module.params['scopes'] = ['https://www.googleapis.com/auth/ndev.clouddns.readwrite']
@ -122,17 +117,12 @@ def main():
items = items.get('rrsets') items = items.get('rrsets')
else: else:
items = [] items = []
return_value = { return_value = {'items': items}
'items': items
}
module.exit_json(**return_value) module.exit_json(**return_value)
def collection(module): def collection(module):
res = { res = {'project': module.params['project'], 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')}
'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) 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 from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
################################################################################ ################################################################################
# Documentation # Documentation
################################################################################ ################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
'status': ["preview"],
'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -121,11 +120,7 @@ def main():
"""Main function""" """Main function"""
module = GcpModule( module = GcpModule(
argument_spec=dict( argument_spec=dict(state=dict(default='present', choices=['present', 'absent'], type='str'), name=dict(type='str'), display_name=dict(type='str'))
state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'),
display_name=dict(type='str')
)
) )
if not module.params['scopes']: if not module.params['scopes']:
@ -174,10 +169,7 @@ def delete(module, link):
def resource_to_request(module): def resource_to_request(module):
request = { request = {u'name': module.params.get('name'), u'displayName': module.params.get('display_name')}
u'name': module.params.get('name'),
u'displayName': module.params.get('display_name')
}
request = encode_request(request, module) request = encode_request(request, module)
return_vals = {} return_vals = {}
for k, v in request.items(): for k, v in request.items():
@ -212,8 +204,8 @@ def return_if_object(module, response, allow_not_found=False):
try: try:
module.raise_for_status(response) module.raise_for_status(response)
result = response.json() result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst: except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % inst) module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module) result = decode_response(result, module)
@ -251,7 +243,7 @@ def response_to_hash(module, response):
u'uniqueId': response.get(u'uniqueId'), u'uniqueId': response.get(u'uniqueId'),
u'email': response.get(u'email'), u'email': response.get(u'email'),
u'displayName': response.get(u'displayName'), 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""" """Structures the request as accountId + rest of request"""
account_id = resource_request['name'].split('@')[0] account_id = resource_request['name'].split('@')[0]
del resource_request['name'] del resource_request['name']
return { return {'accountId': account_id, 'serviceAccount': resource_request}
'accountId': account_id,
'serviceAccount': resource_request
}
def decode_response(response, module): def decode_response(response, module):

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,15 +18,14 @@
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
################################################################################ ################################################################################
# Documentation # Documentation
################################################################################ ################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
'status': ["preview"],
'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -70,8 +69,7 @@ items:
name: name:
description: description:
- A unique identifier for the database, which cannot be changed after the instance - 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]. is created. Values are of the form [a-z][-a-z0-9]*[a-z0-9].
The final segment of the name must be between 6 and 30 characters in length.
returned: success returned: success
type: str type: str
extraStatements: extraStatements:
@ -101,11 +99,7 @@ import json
def main(): def main():
module = GcpModule( module = GcpModule(argument_spec=dict(instance=dict(required=True)))
argument_spec=dict(
instance=dict(required=True)
)
)
if not module.params['scopes']: if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin']
@ -115,17 +109,12 @@ def main():
items = items.get('databases') items = items.get('databases')
else: else:
items = [] items = []
return_value = { return_value = {'items': items}
'items': items
}
module.exit_json(**return_value) module.exit_json(**return_value)
def collection(module): def collection(module):
res = { res = {'project': module.params['project'], 'instance': replace_resource_dict(module.params['instance'], 'name')}
'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) 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 from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
################################################################################ ################################################################################
# Documentation # Documentation
################################################################################ ################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
'status': ["preview"],
'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -51,13 +50,17 @@ options:
name: name:
description: description:
- A unique identifier for the instance, which cannot be changed after the instance - 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]. is created. The name must be between 6 and 30 characters in length.
The final segment of the name must be between 6 and 30 characters in length. required: true
required: false
config: config:
description: description:
- A reference to the instance configuration. - The name of the instance's configuration (similar but not quite the same as
required: false 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: display_name:
description: description:
- The descriptive name for this instance as it appears in UIs. Must be unique - The descriptive name for this instance as it appears in UIs. Must be unique
@ -67,28 +70,16 @@ options:
description: description:
- The number of nodes allocated to this instance. - The number of nodes allocated to this instance.
required: false required: false
default: '1'
labels: labels:
description: 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.' - 'An object containing a list of "key": value pairs.'
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
required: false required: false
extends_documentation_fragment: gcp 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 = ''' EXAMPLES = '''
@ -110,13 +101,17 @@ RETURN = '''
name: name:
description: description:
- A unique identifier for the instance, which cannot be changed after the instance - 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]. is created. The name must be between 6 and 30 characters in length.
The final segment of the name must be between 6 and 30 characters in length.
returned: success returned: success
type: str type: str
config: config:
description: 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 returned: success
type: str type: str
displayName: displayName:
@ -132,22 +127,6 @@ nodeCount:
type: int type: int
labels: labels:
description: 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.' - 'An object containing a list of "key": value pairs.'
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
returned: success returned: success
@ -160,6 +139,7 @@ labels:
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest, replace_resource_dict
import json import json
import time
################################################################################ ################################################################################
# Main # Main
@ -172,11 +152,11 @@ def main():
module = GcpModule( module = GcpModule(
argument_spec=dict( argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'), state=dict(default='present', choices=['present', 'absent'], type='str'),
name=dict(type='str'), name=dict(required=True, type='str'),
config=dict(type='str'), config=dict(required=True, type='str'),
display_name=dict(required=True, type='str'), display_name=dict(required=True, type='str'),
node_count=dict(type='int'), node_count=dict(default=1, type='int'),
labels=dict(type='dict') labels=dict(type='dict'),
) )
) )
@ -212,17 +192,17 @@ def main():
def create(module, link): def create(module, link):
auth = GcpSession(module, 'spanner') 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): def update(module, link):
auth = GcpSession(module, 'spanner') 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): def delete(module, link):
auth = GcpSession(module, 'spanner') 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): def resource_to_request(module):
@ -231,7 +211,7 @@ def resource_to_request(module):
u'config': module.params.get('config'), u'config': module.params.get('config'),
u'displayName': module.params.get('display_name'), u'displayName': module.params.get('display_name'),
u'nodeCount': module.params.get('node_count'), u'nodeCount': module.params.get('node_count'),
u'labels': module.params.get('labels') u'labels': module.params.get('labels'),
} }
return_vals = {} return_vals = {}
for k, v in request.items(): for k, v in request.items():
@ -266,8 +246,8 @@ def return_if_object(module, response, allow_not_found=False):
try: try:
module.raise_for_status(response) module.raise_for_status(response)
result = response.json() result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst: except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % inst) module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module) result = decode_response(result, module)
@ -300,36 +280,61 @@ def is_different(module, response):
# This is for doing comparisons with Ansible's current parameters. # This is for doing comparisons with Ansible's current parameters.
def response_to_hash(module, response): def response_to_hash(module, response):
return { return {
u'name': response.get(u'name'), u'name': module.params.get('name'),
u'config': response.get(u'config'), u'config': response.get(u'config'),
u'displayName': response.get(u'displayName'), u'displayName': response.get(u'displayName'),
u'nodeCount': response.get(u'nodeCount'), 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): def resource_to_create(module):
instance = resource_to_request(module) instance = resource_to_request(module)
instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'], instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'], module.params['name'])
module.params['name']) instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'], instance['config'])
instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'], return {'instanceId': module.params['name'], 'instance': instance}
instance['config'])
return {
'instanceId': module.params['name'],
'instance': instance
}
def resource_to_update(module): def resource_to_update(module):
instance = resource_to_request(module) instance = resource_to_request(module)
instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'], instance['name'] = "projects/{0}/instances/{1}".format(module.params['project'], module.params['name'])
module.params['name']) instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'], instance['config'])
instance['config'] = "projects/{0}/instanceConfigs/{1}".format(module.params['project'], return {'instance': instance, 'fieldMask': "'name' ,'config' ,'displayName' ,'nodeCount' ,'labels'"}
instance['config'])
return {
'instance': instance,
'fieldMask': "'name' ,'config' ,'displayName' ,'nodeCount' ,'labels'"
}
def decode_response(response, module): def decode_response(response, module):

View file

@ -18,15 +18,14 @@
# ---------------------------------------------------------------------------- # ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function from __future__ import absolute_import, division, print_function
__metaclass__ = type __metaclass__ = type
################################################################################ ################################################################################
# Documentation # Documentation
################################################################################ ################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
'status': ["preview"],
'supported_by': 'community'}
DOCUMENTATION = ''' DOCUMENTATION = '''
--- ---
@ -61,13 +60,17 @@ items:
name: name:
description: description:
- A unique identifier for the instance, which cannot be changed after the instance - 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]. is created. The name must be between 6 and 30 characters in length.
The final segment of the name must be between 6 and 30 characters in length.
returned: success returned: success
type: str type: str
config: config:
description: 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 returned: success
type: str type: str
displayName: displayName:
@ -83,23 +86,6 @@ items:
type: int type: int
labels: labels:
description: 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.' - 'An object containing a list of "key": value pairs.'
- 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.' - 'Example: { "name": "wrench", "mass": "1.3kg", "count": "3" }.'
returned: success returned: success
@ -118,10 +104,7 @@ import json
def main(): def main():
module = GcpModule( module = GcpModule(argument_spec=dict())
argument_spec=dict(
)
)
if not module.params['scopes']: if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin'] module.params['scopes'] = ['https://www.googleapis.com/auth/spanner.admin']
@ -131,9 +114,7 @@ def main():
items = items.get('instances') items = items.get('instances')
else: else:
items = [] items = []
return_value = { return_value = {'items': items}
'items': items
}
module.exit_json(**return_value) module.exit_json(**return_value)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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