mirror of
https://github.com/ansible-collections/google.cloud.git
synced 2025-04-09 04:10:27 -07:00
Spanner Instances + Databases
This commit is contained in:
parent
75dd36f715
commit
4312d2750d
1 changed files with 44 additions and 1 deletions
|
@ -44,6 +44,7 @@ options:
|
||||||
- machine_type
|
- machine_type
|
||||||
- region
|
- region
|
||||||
- zone
|
- zone
|
||||||
|
- instance_config
|
||||||
return:
|
return:
|
||||||
description: An optional value to describe what part of the attribute should
|
description: An optional value to describe what part of the attribute should
|
||||||
be returned
|
be returned
|
||||||
|
@ -312,6 +313,47 @@ class GcpZone(object):
|
||||||
return response['name']
|
return response['name']
|
||||||
|
|
||||||
|
|
||||||
|
class GcpInstanceConfig(object):
|
||||||
|
def __init__(self, options):
|
||||||
|
self.module = GcpModule(options)
|
||||||
|
|
||||||
|
self.link = "https://spanner.googleapis.com/v1/projects/{project}/instanceConfigs/{name}".format(**self.module.params)
|
||||||
|
|
||||||
|
def _fetch_resource(self):
|
||||||
|
auth = GcpSession(self.module, 'spanner')
|
||||||
|
return self._return_if_object(auth.get(self.link))
|
||||||
|
|
||||||
|
def _return_if_object(self, response):
|
||||||
|
# If not found, return nothing.
|
||||||
|
if response.status_code == 404:
|
||||||
|
return None
|
||||||
|
|
||||||
|
# If no content, return nothing.
|
||||||
|
if response.status_code == 204:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
response.raise_for_status
|
||||||
|
result = response.json()
|
||||||
|
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
|
||||||
|
self.module.fail_json(msg="Invalid JSON response with error: %s" % inst)
|
||||||
|
except GcpRequestException as inst:
|
||||||
|
self.module.fail_json(msg="Network error: %s" % inst)
|
||||||
|
|
||||||
|
if navigate_hash(result, ['error', 'errors']):
|
||||||
|
self.module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
|
||||||
|
if result['kind'] != self.kind:
|
||||||
|
self.module.fail_json(msg="Incorrect result: {kind}".format(**result))
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
response = self._fetch_resource()
|
||||||
|
if 'return' in self.module.params:
|
||||||
|
return response[self.module.params['return']]
|
||||||
|
return response['name']
|
||||||
|
|
||||||
|
|
||||||
class LookupModule(LookupBase):
|
class LookupModule(LookupBase):
|
||||||
def run(self, terms, variables, **kwargs):
|
def run(self, terms, variables, **kwargs):
|
||||||
|
|
||||||
|
@ -321,7 +363,8 @@ class LookupModule(LookupBase):
|
||||||
'license': GcpLicense,
|
'license': GcpLicense,
|
||||||
'machine_type': GcpMachineType,
|
'machine_type': GcpMachineType,
|
||||||
'region': GcpRegion,
|
'region': GcpRegion,
|
||||||
'zone': GcpZone
|
'zone': GcpZone,
|
||||||
|
'instance_config': GcpInstanceConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
return str(options[kwargs['attribute']](kwargs).run())
|
return str(options[kwargs['attribute']](kwargs).run())
|
||||||
|
|
Loading…
Add table
Reference in a new issue