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

pull/51253/head
Alex Stephen 6 years ago committed by ansibot
parent 395fbce194
commit 47ce9ecd2e

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -220,7 +219,7 @@ def main():
port=dict(type='int'),
request_path=dict(type='str'),
timeout_sec=dict(type='int', aliases=['timeout_seconds']),
unhealthy_threshold=dict(type='int')
unhealthy_threshold=dict(type='int'),
)
)
@ -281,7 +280,7 @@ def resource_to_request(module):
u'port': module.params.get('port'),
u'requestPath': module.params.get('request_path'),
u'timeoutSec': module.params.get('timeout_sec'),
u'unhealthyThreshold': module.params.get('unhealthy_threshold')
u'unhealthyThreshold': module.params.get('unhealthy_threshold'),
}
return_vals = {}
for k, v in request.items():
@ -316,8 +315,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -357,7 +356,7 @@ def response_to_hash(module, response):
u'port': response.get(u'port'),
u'requestPath': response.get(u'requestPath'),
u'timeoutSec': response.get(u'timeoutSec'),
u'unhealthyThreshold': response.get(u'unhealthyThreshold')
u'unhealthyThreshold': response.get(u'unhealthyThreshold'),
}
@ -383,7 +382,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])

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

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -452,28 +451,19 @@ def main():
description=dict(type='str'),
disk_size_gb=dict(type='int'),
family=dict(type='str'),
guest_os_features=dict(type='list', elements='dict', options=dict(
type=dict(type='str', choices=['VIRTIO_SCSI_MULTIQUEUE'])
)),
image_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
)),
guest_os_features=dict(type='list', elements='dict', options=dict(type=dict(type='str', choices=['VIRTIO_SCSI_MULTIQUEUE']))),
image_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), sha256=dict(type='str'))),
labels=dict(type='dict'),
licenses=dict(type='list', elements='str'),
name=dict(required=True, type='str'),
raw_disk=dict(type='dict', options=dict(
container_type=dict(type='str', choices=['TAR']),
sha1_checksum=dict(type='str'),
source=dict(required=True, type='str')
)),
raw_disk=dict(
type='dict',
options=dict(container_type=dict(type='str', choices=['TAR']), sha1_checksum=dict(type='str'), source=dict(required=True, type='str')),
),
source_disk=dict(),
source_disk_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
)),
source_disk_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), sha256=dict(type='str'))),
source_disk_id=dict(type='str'),
source_type=dict(type='str', choices=['RAW'])
source_type=dict(type='str', choices=['RAW']),
)
)
@ -514,8 +504,7 @@ def create(module, link, kind):
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)
@ -527,14 +516,8 @@ def update_fields(module, request, response):
def labels_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/global/images/{name}/setLabels"
]).format(**module.params),
{
u'labels': module.params.get('labels'),
u'labelFingerprint': response.get('labelFingerprint')
}
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/images/{name}/setLabels"]).format(**module.params),
{u'labels': module.params.get('labels'), u'labelFingerprint': response.get('labelFingerprint')},
)
@ -558,7 +541,7 @@ def resource_to_request(module):
u'sourceDisk': replace_resource_dict(module.params.get(u'source_disk', {}), 'selfLink'),
u'sourceDiskEncryptionKey': ImageSourcediskencryptionkey(module.params.get('source_disk_encryption_key', {}), module).to_request(),
u'sourceDiskId': module.params.get('source_disk_id'),
u'sourceType': module.params.get('source_type')
u'sourceType': module.params.get('source_type'),
}
return_vals = {}
for k, v in request.items():
@ -593,8 +576,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -641,7 +624,7 @@ def response_to_hash(module, response):
u'sourceDisk': response.get(u'sourceDisk'),
u'sourceDiskEncryptionKey': ImageSourcediskencryptionkey(response.get(u'sourceDiskEncryptionKey', {}), module).from_response(),
u'sourceDiskId': response.get(u'sourceDiskId'),
u'sourceType': response.get(u'sourceType')
u'sourceType': response.get(u'sourceType'),
}
@ -667,7 +650,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -689,22 +672,26 @@ class ImageDeprecated(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'deleted': self.request.get('deleted'),
u'deprecated': self.request.get('deprecated'),
u'obsolete': self.request.get('obsolete'),
u'replacement': self.request.get('replacement'),
u'state': self.request.get('state')
})
return remove_nones_from_dict(
{
u'deleted': self.request.get('deleted'),
u'deprecated': self.request.get('deprecated'),
u'obsolete': self.request.get('obsolete'),
u'replacement': self.request.get('replacement'),
u'state': self.request.get('state'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'deleted': self.request.get(u'deleted'),
u'deprecated': self.request.get(u'deprecated'),
u'obsolete': self.request.get(u'obsolete'),
u'replacement': self.request.get(u'replacement'),
u'state': self.request.get(u'state')
})
return remove_nones_from_dict(
{
u'deleted': self.request.get(u'deleted'),
u'deprecated': self.request.get(u'deprecated'),
u'obsolete': self.request.get(u'obsolete'),
u'replacement': self.request.get(u'replacement'),
u'state': self.request.get(u'state'),
}
)
class ImageGuestosfeaturesArray(object):
@ -728,14 +715,10 @@ class ImageGuestosfeaturesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'type': item.get('type')
})
return remove_nones_from_dict({u'type': item.get('type')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'type': item.get(u'type')
})
return remove_nones_from_dict({u'type': item.get(u'type')})
class ImageImageencryptionkey(object):
@ -747,16 +730,10 @@ class ImageImageencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get('raw_key'), u'sha256': self.request.get('sha256')})
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get(u'rawKey'), u'sha256': self.request.get(u'sha256')})
class ImageRawdisk(object):
@ -768,18 +745,14 @@ class ImageRawdisk(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'containerType': self.request.get('container_type'),
u'sha1Checksum': self.request.get('sha1_checksum'),
u'source': self.request.get('source')
})
return remove_nones_from_dict(
{u'containerType': self.request.get('container_type'), u'sha1Checksum': self.request.get('sha1_checksum'), u'source': self.request.get('source')}
)
def from_response(self):
return remove_nones_from_dict({
u'containerType': self.request.get(u'containerType'),
u'sha1Checksum': self.request.get(u'sha1Checksum'),
u'source': self.request.get(u'source')
})
return remove_nones_from_dict(
{u'containerType': self.request.get(u'containerType'), u'sha1Checksum': self.request.get(u'sha1Checksum'), u'source': self.request.get(u'source')}
)
class ImageSourcediskencryptionkey(object):
@ -791,16 +764,10 @@ class ImageSourcediskencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get('raw_key'), u'sha256': self.request.get('sha256')})
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get(u'rawKey'), u'sha256': self.request.get(u'sha256')})
if __name__ == '__main__':

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

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -891,70 +890,60 @@ def main():
argument_spec=dict(
state=dict(default='present', choices=['present', 'absent'], type='str'),
can_ip_forward=dict(type='bool'),
disks=dict(type='list', elements='dict', options=dict(
auto_delete=dict(type='bool'),
boot=dict(type='bool'),
device_name=dict(type='str'),
disk_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
rsa_encrypted_key=dict(type='str'),
sha256=dict(type='str')
)),
index=dict(type='int'),
initialize_params=dict(type='dict', options=dict(
disk_name=dict(type='str'),
disk_size_gb=dict(type='int'),
disk_type=dict(type='str'),
source_image=dict(type='str'),
source_image_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
))
)),
interface=dict(type='str', choices=['SCSI', 'NVME']),
mode=dict(type='str', choices=['READ_WRITE', 'READ_ONLY']),
source=dict(),
type=dict(type='str', choices=['SCRATCH', 'PERSISTENT'])
)),
guest_accelerators=dict(type='list', elements='dict', options=dict(
accelerator_count=dict(type='int'),
accelerator_type=dict(type='str')
)),
disks=dict(
type='list',
elements='dict',
options=dict(
auto_delete=dict(type='bool'),
boot=dict(type='bool'),
device_name=dict(type='str'),
disk_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), rsa_encrypted_key=dict(type='str'), sha256=dict(type='str'))),
index=dict(type='int'),
initialize_params=dict(
type='dict',
options=dict(
disk_name=dict(type='str'),
disk_size_gb=dict(type='int'),
disk_type=dict(type='str'),
source_image=dict(type='str'),
source_image_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), sha256=dict(type='str'))),
),
),
interface=dict(type='str', choices=['SCSI', 'NVME']),
mode=dict(type='str', choices=['READ_WRITE', 'READ_ONLY']),
source=dict(),
type=dict(type='str', choices=['SCRATCH', 'PERSISTENT']),
),
),
guest_accelerators=dict(type='list', elements='dict', options=dict(accelerator_count=dict(type='int'), accelerator_type=dict(type='str'))),
label_fingerprint=dict(type='str'),
metadata=dict(type='dict'),
machine_type=dict(type='str'),
min_cpu_platform=dict(type='str'),
name=dict(type='str'),
network_interfaces=dict(type='list', elements='dict', options=dict(
access_configs=dict(type='list', elements='dict', options=dict(
name=dict(required=True, type='str'),
nat_ip=dict(),
type=dict(required=True, type='str', choices=['ONE_TO_ONE_NAT'])
)),
alias_ip_ranges=dict(type='list', elements='dict', options=dict(
ip_cidr_range=dict(type='str'),
subnetwork_range_name=dict(type='str')
)),
name=dict(type='str'),
network=dict(),
network_ip=dict(type='str'),
subnetwork=dict()
)),
scheduling=dict(type='dict', options=dict(
automatic_restart=dict(type='bool'),
on_host_maintenance=dict(type='str'),
preemptible=dict(type='bool')
)),
service_accounts=dict(type='list', elements='dict', options=dict(
email=dict(type='str'),
scopes=dict(type='list', elements='str')
)),
network_interfaces=dict(
type='list',
elements='dict',
options=dict(
access_configs=dict(
type='list',
elements='dict',
options=dict(name=dict(required=True, type='str'), nat_ip=dict(), type=dict(required=True, type='str', choices=['ONE_TO_ONE_NAT'])),
),
alias_ip_ranges=dict(type='list', elements='dict', options=dict(ip_cidr_range=dict(type='str'), subnetwork_range_name=dict(type='str'))),
name=dict(type='str'),
network=dict(),
network_ip=dict(type='str'),
subnetwork=dict(),
),
),
scheduling=dict(
type='dict', options=dict(automatic_restart=dict(type='bool'), on_host_maintenance=dict(type='str'), preemptible=dict(type='bool'))
),
service_accounts=dict(type='list', elements='dict', options=dict(email=dict(type='str'), scopes=dict(type='list', elements='str'))),
status=dict(type='str', choices=['PROVISIONING', 'STAGING', 'RUNNING', 'STOPPING', 'SUSPENDING', 'SUSPENDED', 'TERMINATED']),
tags=dict(type='dict', options=dict(
fingerprint=dict(type='str'),
items=dict(type='list', elements='str')
)),
zone=dict(required=True, type='str')
tags=dict(type='dict', options=dict(fingerprint=dict(type='str'), items=dict(type='list', elements='str'))),
zone=dict(required=True, type='str'),
)
)
@ -1000,8 +989,7 @@ def create(module, link, kind):
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)
@ -1013,13 +1001,8 @@ def update_fields(module, request, response):
def machine_type_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/zones/{zone}/instances/{name}/setMachineType"
]).format(**module.params),
{
u'machineType': machine_type_selflink(module.params.get('machine_type'), module.params)
}
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/zones/{zone}/instances/{name}/setMachineType"]).format(**module.params),
{u'machineType': machine_type_selflink(module.params.get('machine_type'), module.params)},
)
@ -1043,7 +1026,7 @@ def resource_to_request(module):
u'scheduling': InstanceScheduling(module.params.get('scheduling', {}), module).to_request(),
u'serviceAccounts': InstanceServiceaccountsArray(module.params.get('service_accounts', []), module).to_request(),
u'status': module.params.get('status'),
u'tags': InstanceTags(module.params.get('tags', {}), module).to_request()
u'tags': InstanceTags(module.params.get('tags', {}), module).to_request(),
}
request = encode_request(request, module)
return_vals = {}
@ -1079,8 +1062,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module)
@ -1129,7 +1112,7 @@ def response_to_hash(module, response):
u'serviceAccounts': InstanceServiceaccountsArray(response.get(u'serviceAccounts', []), module).from_response(),
u'status': response.get(u'status'),
u'statusMessage': response.get(u'statusMessage'),
u'tags': InstanceTags(response.get(u'tags', {}), module).from_response()
u'tags': InstanceTags(response.get(u'tags', {}), module).from_response(),
}
@ -1173,7 +1156,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -1218,13 +1201,8 @@ def metadata_encoder(metadata):
metadata_new = []
for key in metadata:
value = metadata[key]
metadata_new.append({
"key": key,
"value": value
})
return {
'items': metadata_new
}
metadata_new.append({"key": key, "value": value})
return {'items': metadata_new}
# Map metadata.items[]{key:,value:} => metadata[key]=value
@ -1290,32 +1268,36 @@ class InstanceDisksArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'autoDelete': item.get('auto_delete'),
u'boot': item.get('boot'),
u'deviceName': item.get('device_name'),
u'diskEncryptionKey': InstanceDiskencryptionkey(item.get('disk_encryption_key', {}), self.module).to_request(),
u'index': item.get('index'),
u'initializeParams': InstanceInitializeparams(item.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get('interface'),
u'mode': item.get('mode'),
u'source': replace_resource_dict(item.get(u'source', {}), 'selfLink'),
u'type': item.get('type')
})
return remove_nones_from_dict(
{
u'autoDelete': item.get('auto_delete'),
u'boot': item.get('boot'),
u'deviceName': item.get('device_name'),
u'diskEncryptionKey': InstanceDiskencryptionkey(item.get('disk_encryption_key', {}), self.module).to_request(),
u'index': item.get('index'),
u'initializeParams': InstanceInitializeparams(item.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get('interface'),
u'mode': item.get('mode'),
u'source': replace_resource_dict(item.get(u'source', {}), 'selfLink'),
u'type': item.get('type'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'autoDelete': item.get(u'autoDelete'),
u'boot': item.get(u'boot'),
u'deviceName': item.get(u'deviceName'),
u'diskEncryptionKey': InstanceDiskencryptionkey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
u'index': item.get(u'index'),
u'initializeParams': InstanceInitializeparams(self.module.params.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get(u'interface'),
u'mode': item.get(u'mode'),
u'source': item.get(u'source'),
u'type': item.get(u'type')
})
return remove_nones_from_dict(
{
u'autoDelete': item.get(u'autoDelete'),
u'boot': item.get(u'boot'),
u'deviceName': item.get(u'deviceName'),
u'diskEncryptionKey': InstanceDiskencryptionkey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
u'index': item.get(u'index'),
u'initializeParams': InstanceInitializeparams(self.module.params.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get(u'interface'),
u'mode': item.get(u'mode'),
u'source': item.get(u'source'),
u'type': item.get(u'type'),
}
)
class InstanceDiskencryptionkey(object):
@ -1327,18 +1309,14 @@ class InstanceDiskencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'rsaEncryptedKey': self.request.get('rsa_encrypted_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict(
{u'rawKey': self.request.get('raw_key'), u'rsaEncryptedKey': self.request.get('rsa_encrypted_key'), u'sha256': self.request.get('sha256')}
)
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'rsaEncryptedKey': self.request.get(u'rsaEncryptedKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict(
{u'rawKey': self.request.get(u'rawKey'), u'rsaEncryptedKey': self.request.get(u'rsaEncryptedKey'), u'sha256': self.request.get(u'sha256')}
)
class InstanceInitializeparams(object):
@ -1350,22 +1328,26 @@ class InstanceInitializeparams(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'diskName': self.request.get('disk_name'),
u'diskSizeGb': self.request.get('disk_size_gb'),
u'diskType': disk_type_selflink(self.request.get('disk_type'), self.module.params),
u'sourceImage': self.request.get('source_image'),
u'sourceImageEncryptionKey': InstanceSourceimageencryptionkey(self.request.get('source_image_encryption_key', {}), self.module).to_request()
})
return remove_nones_from_dict(
{
u'diskName': self.request.get('disk_name'),
u'diskSizeGb': self.request.get('disk_size_gb'),
u'diskType': disk_type_selflink(self.request.get('disk_type'), self.module.params),
u'sourceImage': self.request.get('source_image'),
u'sourceImageEncryptionKey': InstanceSourceimageencryptionkey(self.request.get('source_image_encryption_key', {}), self.module).to_request(),
}
)
def from_response(self):
return remove_nones_from_dict({
u'diskName': self.request.get(u'diskName'),
u'diskSizeGb': self.request.get(u'diskSizeGb'),
u'diskType': self.request.get(u'diskType'),
u'sourceImage': self.request.get(u'sourceImage'),
u'sourceImageEncryptionKey': InstanceSourceimageencryptionkey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response()
})
return remove_nones_from_dict(
{
u'diskName': self.request.get(u'diskName'),
u'diskSizeGb': self.request.get(u'diskSizeGb'),
u'diskType': self.request.get(u'diskType'),
u'sourceImage': self.request.get(u'sourceImage'),
u'sourceImageEncryptionKey': InstanceSourceimageencryptionkey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response(),
}
)
class InstanceSourceimageencryptionkey(object):
@ -1377,16 +1359,10 @@ class InstanceSourceimageencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get('raw_key'), u'sha256': self.request.get('sha256')})
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get(u'rawKey'), u'sha256': self.request.get(u'sha256')})
class InstanceGuestacceleratorsArray(object):
@ -1410,16 +1386,10 @@ class InstanceGuestacceleratorsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'acceleratorCount': item.get('accelerator_count'),
u'acceleratorType': item.get('accelerator_type')
})
return remove_nones_from_dict({u'acceleratorCount': item.get('accelerator_count'), u'acceleratorType': item.get('accelerator_type')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'acceleratorCount': item.get(u'acceleratorCount'),
u'acceleratorType': item.get(u'acceleratorType')
})
return remove_nones_from_dict({u'acceleratorCount': item.get(u'acceleratorCount'), u'acceleratorType': item.get(u'acceleratorType')})
class InstanceNetworkinterfacesArray(object):
@ -1443,24 +1413,28 @@ class InstanceNetworkinterfacesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'accessConfigs': InstanceAccessconfigsArray(item.get('access_configs', []), self.module).to_request(),
u'aliasIpRanges': InstanceAliasiprangesArray(item.get('alias_ip_ranges', []), self.module).to_request(),
u'name': item.get('name'),
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
u'networkIP': item.get('network_ip'),
u'subnetwork': replace_resource_dict(item.get(u'subnetwork', {}), 'selfLink')
})
return remove_nones_from_dict(
{
u'accessConfigs': InstanceAccessconfigsArray(item.get('access_configs', []), self.module).to_request(),
u'aliasIpRanges': InstanceAliasiprangesArray(item.get('alias_ip_ranges', []), self.module).to_request(),
u'name': item.get('name'),
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
u'networkIP': item.get('network_ip'),
u'subnetwork': replace_resource_dict(item.get(u'subnetwork', {}), 'selfLink'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'accessConfigs': InstanceAccessconfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
u'aliasIpRanges': InstanceAliasiprangesArray(item.get(u'aliasIpRanges', []), self.module).from_response(),
u'name': item.get(u'name'),
u'network': item.get(u'network'),
u'networkIP': item.get(u'networkIP'),
u'subnetwork': item.get(u'subnetwork')
})
return remove_nones_from_dict(
{
u'accessConfigs': InstanceAccessconfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
u'aliasIpRanges': InstanceAliasiprangesArray(item.get(u'aliasIpRanges', []), self.module).from_response(),
u'name': item.get(u'name'),
u'network': item.get(u'network'),
u'networkIP': item.get(u'networkIP'),
u'subnetwork': item.get(u'subnetwork'),
}
)
class InstanceAccessconfigsArray(object):
@ -1484,18 +1458,12 @@ class InstanceAccessconfigsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'name': item.get('name'),
u'natIP': replace_resource_dict(item.get(u'nat_ip', {}), 'address'),
u'type': item.get('type')
})
return remove_nones_from_dict(
{u'name': item.get('name'), u'natIP': replace_resource_dict(item.get(u'nat_ip', {}), 'address'), u'type': item.get('type')}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'name': item.get(u'name'),
u'natIP': item.get(u'natIP'),
u'type': item.get(u'type')
})
return remove_nones_from_dict({u'name': item.get(u'name'), u'natIP': item.get(u'natIP'), u'type': item.get(u'type')})
class InstanceAliasiprangesArray(object):
@ -1519,16 +1487,10 @@ class InstanceAliasiprangesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'ipCidrRange': item.get('ip_cidr_range'),
u'subnetworkRangeName': item.get('subnetwork_range_name')
})
return remove_nones_from_dict({u'ipCidrRange': item.get('ip_cidr_range'), u'subnetworkRangeName': item.get('subnetwork_range_name')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'ipCidrRange': item.get(u'ipCidrRange'),
u'subnetworkRangeName': item.get(u'subnetworkRangeName')
})
return remove_nones_from_dict({u'ipCidrRange': item.get(u'ipCidrRange'), u'subnetworkRangeName': item.get(u'subnetworkRangeName')})
class InstanceScheduling(object):
@ -1540,18 +1502,22 @@ class InstanceScheduling(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'automaticRestart': self.request.get('automatic_restart'),
u'onHostMaintenance': self.request.get('on_host_maintenance'),
u'preemptible': self.request.get('preemptible')
})
return remove_nones_from_dict(
{
u'automaticRestart': self.request.get('automatic_restart'),
u'onHostMaintenance': self.request.get('on_host_maintenance'),
u'preemptible': self.request.get('preemptible'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'automaticRestart': self.request.get(u'automaticRestart'),
u'onHostMaintenance': self.request.get(u'onHostMaintenance'),
u'preemptible': self.request.get(u'preemptible')
})
return remove_nones_from_dict(
{
u'automaticRestart': self.request.get(u'automaticRestart'),
u'onHostMaintenance': self.request.get(u'onHostMaintenance'),
u'preemptible': self.request.get(u'preemptible'),
}
)
class InstanceServiceaccountsArray(object):
@ -1575,16 +1541,10 @@ class InstanceServiceaccountsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'email': item.get('email'),
u'scopes': item.get('scopes')
})
return remove_nones_from_dict({u'email': item.get('email'), u'scopes': item.get('scopes')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'email': item.get(u'email'),
u'scopes': item.get(u'scopes')
})
return remove_nones_from_dict({u'email': item.get(u'email'), u'scopes': item.get(u'scopes')})
class InstanceTags(object):
@ -1596,16 +1556,10 @@ class InstanceTags(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'fingerprint': self.request.get('fingerprint'),
u'items': self.request.get('items')
})
return remove_nones_from_dict({u'fingerprint': self.request.get('fingerprint'), u'items': self.request.get('items')})
def from_response(self):
return remove_nones_from_dict({
u'fingerprint': self.request.get(u'fingerprint'),
u'items': self.request.get(u'items')
})
return remove_nones_from_dict({u'fingerprint': self.request.get(u'fingerprint'), u'items': self.request.get(u'items')})
if __name__ == '__main__':

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -484,12 +483,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
zone=dict(required=True, type='str')
)
)
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), zone=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
@ -499,9 +493,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -238,15 +237,12 @@ def main():
state=dict(default='present', choices=['present', 'absent'], type='str'),
description=dict(type='str'),
name=dict(type='str'),
named_ports=dict(type='list', elements='dict', options=dict(
name=dict(type='str'),
port=dict(type='int')
)),
named_ports=dict(type='list', elements='dict', options=dict(name=dict(type='str'), port=dict(type='int'))),
network=dict(),
region=dict(type='str'),
subnetwork=dict(),
zone=dict(required=True, type='str'),
instances=dict(type='list')
instances=dict(type='list'),
)
)
@ -308,7 +304,7 @@ def resource_to_request(module):
u'namedPorts': InstanceGroupNamedportsArray(module.params.get('named_ports', []), module).to_request(),
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
u'region': region_selflink(module.params.get('region'), module.params),
u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink')
u'subnetwork': replace_resource_dict(module.params.get(u'subnetwork', {}), 'selfLink'),
}
return_vals = {}
for k, v in request.items():
@ -343,8 +339,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -381,7 +377,7 @@ def response_to_hash(module, response):
u'namedPorts': InstanceGroupNamedportsArray(response.get(u'namedPorts', []), module).from_response(),
u'network': response.get(u'network'),
u'region': response.get(u'region'),
u'subnetwork': response.get(u'subnetwork')
u'subnetwork': response.get(u'subnetwork'),
}
@ -416,7 +412,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -454,8 +450,7 @@ class InstanceLogic(object):
def list_instances(self):
auth = GcpSession(self.module, 'compute')
response = return_if_object(self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}),
'compute#instanceGroupsListInstances')
response = return_if_object(self.module, auth.post(self._list_instances_url(), {'instanceState': 'ALL'}), 'compute#instanceGroupsListInstances')
# Transform instance list into a list of selfLinks for diffing with module parameters
instances = []
@ -481,9 +476,7 @@ class InstanceLogic(object):
return "https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/instanceGroups/{name}/addInstances".format(**self.module.params)
def _build_request(self, instances):
request = {
'instances': []
}
request = {'instances': []}
for instance in instances:
request['instances'].append({'instance': instance})
return request
@ -510,16 +503,10 @@ class InstanceGroupNamedportsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'name': item.get('name'),
u'port': item.get('port')
})
return remove_nones_from_dict({u'name': item.get('name'), u'port': item.get('port')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'name': item.get(u'name'),
u'port': item.get(u'port')
})
return remove_nones_from_dict({u'name': item.get(u'name'), u'port': item.get(u'port')})
if __name__ == '__main__':

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -157,12 +156,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
zone=dict(required=True, type='str')
)
)
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), zone=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
@ -172,9 +166,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -342,13 +341,10 @@ def main():
description=dict(type='str'),
instance_template=dict(required=True),
name=dict(required=True, type='str'),
named_ports=dict(type='list', elements='dict', options=dict(
name=dict(type='str'),
port=dict(type='int')
)),
named_ports=dict(type='list', elements='dict', options=dict(name=dict(type='str'), port=dict(type='int'))),
target_pools=dict(type='list'),
target_size=dict(type='int'),
zone=dict(required=True, type='str')
zone=dict(required=True, type='str'),
)
)
@ -407,7 +403,7 @@ def resource_to_request(module):
u'name': module.params.get('name'),
u'namedPorts': InstanceGroupManagerNamedportsArray(module.params.get('named_ports', []), module).to_request(),
u'targetPools': replace_resource_dict(module.params.get('target_pools', []), 'selfLink'),
u'targetSize': module.params.get('target_size')
u'targetSize': module.params.get('target_size'),
}
return_vals = {}
for k, v in request.items():
@ -442,8 +438,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -484,7 +480,7 @@ def response_to_hash(module, response):
u'namedPorts': InstanceGroupManagerNamedportsArray(response.get(u'namedPorts', []), module).from_response(),
u'region': response.get(u'region'),
u'targetPools': response.get(u'targetPools'),
u'targetSize': response.get(u'targetSize')
u'targetSize': response.get(u'targetSize'),
}
@ -519,7 +515,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -541,28 +537,32 @@ class InstanceGroupManagerCurrentactions(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'abandoning': self.request.get('abandoning'),
u'creating': self.request.get('creating'),
u'creatingWithoutRetries': self.request.get('creating_without_retries'),
u'deleting': self.request.get('deleting'),
u'none': self.request.get('none'),
u'recreating': self.request.get('recreating'),
u'refreshing': self.request.get('refreshing'),
u'restarting': self.request.get('restarting')
})
return remove_nones_from_dict(
{
u'abandoning': self.request.get('abandoning'),
u'creating': self.request.get('creating'),
u'creatingWithoutRetries': self.request.get('creating_without_retries'),
u'deleting': self.request.get('deleting'),
u'none': self.request.get('none'),
u'recreating': self.request.get('recreating'),
u'refreshing': self.request.get('refreshing'),
u'restarting': self.request.get('restarting'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'abandoning': self.request.get(u'abandoning'),
u'creating': self.request.get(u'creating'),
u'creatingWithoutRetries': self.request.get(u'creatingWithoutRetries'),
u'deleting': self.request.get(u'deleting'),
u'none': self.request.get(u'none'),
u'recreating': self.request.get(u'recreating'),
u'refreshing': self.request.get(u'refreshing'),
u'restarting': self.request.get(u'restarting')
})
return remove_nones_from_dict(
{
u'abandoning': self.request.get(u'abandoning'),
u'creating': self.request.get(u'creating'),
u'creatingWithoutRetries': self.request.get(u'creatingWithoutRetries'),
u'deleting': self.request.get(u'deleting'),
u'none': self.request.get(u'none'),
u'recreating': self.request.get(u'recreating'),
u'refreshing': self.request.get(u'refreshing'),
u'restarting': self.request.get(u'restarting'),
}
)
class InstanceGroupManagerNamedportsArray(object):
@ -586,16 +586,10 @@ class InstanceGroupManagerNamedportsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'name': item.get('name'),
u'port': item.get('port')
})
return remove_nones_from_dict({u'name': item.get('name'), u'port': item.get('port')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'name': item.get(u'name'),
u'port': item.get(u'port')
})
return remove_nones_from_dict({u'name': item.get(u'name'), u'port': item.get(u'port')})
if __name__ == '__main__':

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -232,12 +231,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
zone=dict(required=True, type='str')
)
)
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), zone=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
@ -247,9 +241,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -867,70 +866,69 @@ def main():
state=dict(default='present', choices=['present', 'absent'], type='str'),
description=dict(type='str'),
name=dict(required=True, type='str'),
properties=dict(type='dict', options=dict(
can_ip_forward=dict(type='bool'),
description=dict(type='str'),
disks=dict(type='list', elements='dict', options=dict(
auto_delete=dict(type='bool'),
boot=dict(type='bool'),
device_name=dict(type='str'),
disk_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
rsa_encrypted_key=dict(type='str'),
sha256=dict(type='str')
)),
index=dict(type='int'),
initialize_params=dict(type='dict', options=dict(
disk_name=dict(type='str'),
disk_size_gb=dict(type='int'),
disk_type=dict(type='str'),
source_image=dict(type='str'),
source_image_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
))
)),
interface=dict(type='str', choices=['SCSI', 'NVME']),
mode=dict(type='str', choices=['READ_WRITE', 'READ_ONLY']),
source=dict(),
type=dict(type='str', choices=['SCRATCH', 'PERSISTENT'])
)),
machine_type=dict(required=True, type='str'),
min_cpu_platform=dict(type='str'),
metadata=dict(type='dict'),
guest_accelerators=dict(type='list', elements='dict', options=dict(
accelerator_count=dict(type='int'),
accelerator_type=dict(type='str')
)),
network_interfaces=dict(type='list', elements='dict', options=dict(
access_configs=dict(type='list', elements='dict', options=dict(
name=dict(required=True, type='str'),
nat_ip=dict(),
type=dict(required=True, type='str', choices=['ONE_TO_ONE_NAT'])
)),
alias_ip_ranges=dict(type='list', elements='dict', options=dict(
ip_cidr_range=dict(type='str'),
subnetwork_range_name=dict(type='str')
)),
name=dict(type='str'),
network=dict(),
network_ip=dict(type='str'),
subnetwork=dict()
)),
scheduling=dict(type='dict', options=dict(
automatic_restart=dict(type='bool'),
on_host_maintenance=dict(type='str'),
preemptible=dict(type='bool')
)),
service_accounts=dict(type='list', elements='dict', options=dict(
email=dict(type='str'),
scopes=dict(type='list', elements='str')
)),
tags=dict(type='dict', options=dict(
fingerprint=dict(type='str'),
items=dict(type='list', elements='str')
))
))
properties=dict(
type='dict',
options=dict(
can_ip_forward=dict(type='bool'),
description=dict(type='str'),
disks=dict(
type='list',
elements='dict',
options=dict(
auto_delete=dict(type='bool'),
boot=dict(type='bool'),
device_name=dict(type='str'),
disk_encryption_key=dict(
type='dict', options=dict(raw_key=dict(type='str'), rsa_encrypted_key=dict(type='str'), sha256=dict(type='str'))
),
index=dict(type='int'),
initialize_params=dict(
type='dict',
options=dict(
disk_name=dict(type='str'),
disk_size_gb=dict(type='int'),
disk_type=dict(type='str'),
source_image=dict(type='str'),
source_image_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), sha256=dict(type='str'))),
),
),
interface=dict(type='str', choices=['SCSI', 'NVME']),
mode=dict(type='str', choices=['READ_WRITE', 'READ_ONLY']),
source=dict(),
type=dict(type='str', choices=['SCRATCH', 'PERSISTENT']),
),
),
machine_type=dict(required=True, type='str'),
min_cpu_platform=dict(type='str'),
metadata=dict(type='dict'),
guest_accelerators=dict(type='list', elements='dict', options=dict(accelerator_count=dict(type='int'), accelerator_type=dict(type='str'))),
network_interfaces=dict(
type='list',
elements='dict',
options=dict(
access_configs=dict(
type='list',
elements='dict',
options=dict(
name=dict(required=True, type='str'), nat_ip=dict(), type=dict(required=True, type='str', choices=['ONE_TO_ONE_NAT'])
),
),
alias_ip_ranges=dict(
type='list', elements='dict', options=dict(ip_cidr_range=dict(type='str'), subnetwork_range_name=dict(type='str'))
),
name=dict(type='str'),
network=dict(),
network_ip=dict(type='str'),
subnetwork=dict(),
),
),
scheduling=dict(
type='dict', options=dict(automatic_restart=dict(type='bool'), on_host_maintenance=dict(type='str'), preemptible=dict(type='bool'))
),
service_accounts=dict(type='list', elements='dict', options=dict(email=dict(type='str'), scopes=dict(type='list', elements='str'))),
tags=dict(type='dict', options=dict(fingerprint=dict(type='str'), items=dict(type='list', elements='str'))),
),
),
)
)
@ -984,7 +982,7 @@ def resource_to_request(module):
u'kind': 'compute#instanceTemplate',
u'description': module.params.get('description'),
u'name': module.params.get('name'),
u'properties': InstanceTemplateProperties(module.params.get('properties', {}), module).to_request()
u'properties': InstanceTemplateProperties(module.params.get('properties', {}), module).to_request(),
}
request = encode_request(request, module)
return_vals = {}
@ -1020,8 +1018,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
result = decode_response(result, module)
@ -1058,7 +1056,7 @@ def response_to_hash(module, response):
u'description': response.get(u'description'),
u'id': response.get(u'id'),
u'name': response.get(u'name'),
u'properties': InstanceTemplateProperties(response.get(u'properties', {}), module).from_response()
u'properties': InstanceTemplateProperties(response.get(u'properties', {}), module).from_response(),
}
@ -1093,7 +1091,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -1138,13 +1136,8 @@ def metadata_encoder(metadata):
metadata_new = []
for key in metadata:
value = metadata[key]
metadata_new.append({
"key": key,
"value": value
})
return {
'items': metadata_new
}
metadata_new.append({"key": key, "value": value})
return {'items': metadata_new}
# Map metadata.items[]{key:,value:} => metadata[key]=value
@ -1166,34 +1159,38 @@ class InstanceTemplateProperties(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'canIpForward': self.request.get('can_ip_forward'),
u'description': self.request.get('description'),
u'disks': InstanceTemplateDisksArray(self.request.get('disks', []), self.module).to_request(),
u'machineType': self.request.get('machine_type'),
u'minCpuPlatform': self.request.get('min_cpu_platform'),
u'metadata': self.request.get('metadata'),
u'guestAccelerators': InstanceTemplateGuestacceleratorsArray(self.request.get('guest_accelerators', []), self.module).to_request(),
u'networkInterfaces': InstanceTemplateNetworkinterfacesArray(self.request.get('network_interfaces', []), self.module).to_request(),
u'scheduling': InstanceTemplateScheduling(self.request.get('scheduling', {}), self.module).to_request(),
u'serviceAccounts': InstanceTemplateServiceaccountsArray(self.request.get('service_accounts', []), self.module).to_request(),
u'tags': InstanceTemplateTags(self.request.get('tags', {}), self.module).to_request()
})
return remove_nones_from_dict(
{
u'canIpForward': self.request.get('can_ip_forward'),
u'description': self.request.get('description'),
u'disks': InstanceTemplateDisksArray(self.request.get('disks', []), self.module).to_request(),
u'machineType': self.request.get('machine_type'),
u'minCpuPlatform': self.request.get('min_cpu_platform'),
u'metadata': self.request.get('metadata'),
u'guestAccelerators': InstanceTemplateGuestacceleratorsArray(self.request.get('guest_accelerators', []), self.module).to_request(),
u'networkInterfaces': InstanceTemplateNetworkinterfacesArray(self.request.get('network_interfaces', []), self.module).to_request(),
u'scheduling': InstanceTemplateScheduling(self.request.get('scheduling', {}), self.module).to_request(),
u'serviceAccounts': InstanceTemplateServiceaccountsArray(self.request.get('service_accounts', []), self.module).to_request(),
u'tags': InstanceTemplateTags(self.request.get('tags', {}), self.module).to_request(),
}
)
def from_response(self):
return remove_nones_from_dict({
u'canIpForward': self.request.get(u'canIpForward'),
u'description': self.request.get(u'description'),
u'disks': InstanceTemplateDisksArray(self.request.get(u'disks', []), self.module).from_response(),
u'machineType': self.request.get(u'machineType'),
u'minCpuPlatform': self.request.get(u'minCpuPlatform'),
u'metadata': self.request.get(u'metadata'),
u'guestAccelerators': InstanceTemplateGuestacceleratorsArray(self.request.get(u'guestAccelerators', []), self.module).from_response(),
u'networkInterfaces': InstanceTemplateNetworkinterfacesArray(self.request.get(u'networkInterfaces', []), self.module).from_response(),
u'scheduling': InstanceTemplateScheduling(self.request.get(u'scheduling', {}), self.module).from_response(),
u'serviceAccounts': InstanceTemplateServiceaccountsArray(self.request.get(u'serviceAccounts', []), self.module).from_response(),
u'tags': InstanceTemplateTags(self.request.get(u'tags', {}), self.module).from_response()
})
return remove_nones_from_dict(
{
u'canIpForward': self.request.get(u'canIpForward'),
u'description': self.request.get(u'description'),
u'disks': InstanceTemplateDisksArray(self.request.get(u'disks', []), self.module).from_response(),
u'machineType': self.request.get(u'machineType'),
u'minCpuPlatform': self.request.get(u'minCpuPlatform'),
u'metadata': self.request.get(u'metadata'),
u'guestAccelerators': InstanceTemplateGuestacceleratorsArray(self.request.get(u'guestAccelerators', []), self.module).from_response(),
u'networkInterfaces': InstanceTemplateNetworkinterfacesArray(self.request.get(u'networkInterfaces', []), self.module).from_response(),
u'scheduling': InstanceTemplateScheduling(self.request.get(u'scheduling', {}), self.module).from_response(),
u'serviceAccounts': InstanceTemplateServiceaccountsArray(self.request.get(u'serviceAccounts', []), self.module).from_response(),
u'tags': InstanceTemplateTags(self.request.get(u'tags', {}), self.module).from_response(),
}
)
class InstanceTemplateDisksArray(object):
@ -1217,32 +1214,36 @@ class InstanceTemplateDisksArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'autoDelete': item.get('auto_delete'),
u'boot': item.get('boot'),
u'deviceName': item.get('device_name'),
u'diskEncryptionKey': InstanceTemplateDiskencryptionkey(item.get('disk_encryption_key', {}), self.module).to_request(),
u'index': item.get('index'),
u'initializeParams': InstanceTemplateInitializeparams(item.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get('interface'),
u'mode': item.get('mode'),
u'source': replace_resource_dict(item.get(u'source', {}), 'name'),
u'type': item.get('type')
})
return remove_nones_from_dict(
{
u'autoDelete': item.get('auto_delete'),
u'boot': item.get('boot'),
u'deviceName': item.get('device_name'),
u'diskEncryptionKey': InstanceTemplateDiskencryptionkey(item.get('disk_encryption_key', {}), self.module).to_request(),
u'index': item.get('index'),
u'initializeParams': InstanceTemplateInitializeparams(item.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get('interface'),
u'mode': item.get('mode'),
u'source': replace_resource_dict(item.get(u'source', {}), 'name'),
u'type': item.get('type'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'autoDelete': item.get(u'autoDelete'),
u'boot': item.get(u'boot'),
u'deviceName': item.get(u'deviceName'),
u'diskEncryptionKey': InstanceTemplateDiskencryptionkey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
u'index': item.get(u'index'),
u'initializeParams': InstanceTemplateInitializeparams(self.module.params.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get(u'interface'),
u'mode': item.get(u'mode'),
u'source': item.get(u'source'),
u'type': item.get(u'type')
})
return remove_nones_from_dict(
{
u'autoDelete': item.get(u'autoDelete'),
u'boot': item.get(u'boot'),
u'deviceName': item.get(u'deviceName'),
u'diskEncryptionKey': InstanceTemplateDiskencryptionkey(item.get(u'diskEncryptionKey', {}), self.module).from_response(),
u'index': item.get(u'index'),
u'initializeParams': InstanceTemplateInitializeparams(self.module.params.get('initialize_params', {}), self.module).to_request(),
u'interface': item.get(u'interface'),
u'mode': item.get(u'mode'),
u'source': item.get(u'source'),
u'type': item.get(u'type'),
}
)
class InstanceTemplateDiskencryptionkey(object):
@ -1254,18 +1255,14 @@ class InstanceTemplateDiskencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'rsaEncryptedKey': self.request.get('rsa_encrypted_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict(
{u'rawKey': self.request.get('raw_key'), u'rsaEncryptedKey': self.request.get('rsa_encrypted_key'), u'sha256': self.request.get('sha256')}
)
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'rsaEncryptedKey': self.request.get(u'rsaEncryptedKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict(
{u'rawKey': self.request.get(u'rawKey'), u'rsaEncryptedKey': self.request.get(u'rsaEncryptedKey'), u'sha256': self.request.get(u'sha256')}
)
class InstanceTemplateInitializeparams(object):
@ -1277,23 +1274,30 @@ class InstanceTemplateInitializeparams(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'diskName': self.request.get('disk_name'),
u'diskSizeGb': self.request.get('disk_size_gb'),
u'diskType': disk_type_selflink(self.request.get('disk_type'), self.module.params),
u'sourceImage': self.request.get('source_image'),
u'sourceImageEncryptionKey': InstanceTemplateSourceimageencryptionkey(self.request.get('source_image_encryption_key', {}), self.module).to_request()
})
return remove_nones_from_dict(
{
u'diskName': self.request.get('disk_name'),
u'diskSizeGb': self.request.get('disk_size_gb'),
u'diskType': disk_type_selflink(self.request.get('disk_type'), self.module.params),
u'sourceImage': self.request.get('source_image'),
u'sourceImageEncryptionKey': InstanceTemplateSourceimageencryptionkey(
self.request.get('source_image_encryption_key', {}), self.module
).to_request(),
}
)
def from_response(self):
return remove_nones_from_dict({
u'diskName': self.request.get(u'diskName'),
u'diskSizeGb': self.request.get(u'diskSizeGb'),
u'diskType': self.request.get(u'diskType'),
u'sourceImage': self.request.get(u'sourceImage'),
u'sourceImageEncryptionKey':
InstanceTemplateSourceimageencryptionkey(self.request.get(u'sourceImageEncryptionKey', {}), self.module).from_response()
})
return remove_nones_from_dict(
{
u'diskName': self.request.get(u'diskName'),
u'diskSizeGb': self.request.get(u'diskSizeGb'),
u'diskType': self.request.get(u'diskType'),
u'sourceImage': self.request.get(u'sourceImage'),
u'sourceImageEncryptionKey': InstanceTemplateSourceimageencryptionkey(
self.request.get(u'sourceImageEncryptionKey', {}), self.module
).from_response(),
}
)
class InstanceTemplateSourceimageencryptionkey(object):
@ -1305,16 +1309,10 @@ class InstanceTemplateSourceimageencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get('raw_key'), u'sha256': self.request.get('sha256')})
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get(u'rawKey'), u'sha256': self.request.get(u'sha256')})
class InstanceTemplateGuestacceleratorsArray(object):
@ -1338,16 +1336,10 @@ class InstanceTemplateGuestacceleratorsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'acceleratorCount': item.get('accelerator_count'),
u'acceleratorType': item.get('accelerator_type')
})
return remove_nones_from_dict({u'acceleratorCount': item.get('accelerator_count'), u'acceleratorType': item.get('accelerator_type')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'acceleratorCount': item.get(u'acceleratorCount'),
u'acceleratorType': item.get(u'acceleratorType')
})
return remove_nones_from_dict({u'acceleratorCount': item.get(u'acceleratorCount'), u'acceleratorType': item.get(u'acceleratorType')})
class InstanceTemplateNetworkinterfacesArray(object):
@ -1371,24 +1363,28 @@ class InstanceTemplateNetworkinterfacesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'accessConfigs': InstanceTemplateAccessconfigsArray(item.get('access_configs', []), self.module).to_request(),
u'aliasIpRanges': InstanceTemplateAliasiprangesArray(item.get('alias_ip_ranges', []), self.module).to_request(),
u'name': item.get('name'),
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
u'networkIP': item.get('network_ip'),
u'subnetwork': replace_resource_dict(item.get(u'subnetwork', {}), 'selfLink')
})
return remove_nones_from_dict(
{
u'accessConfigs': InstanceTemplateAccessconfigsArray(item.get('access_configs', []), self.module).to_request(),
u'aliasIpRanges': InstanceTemplateAliasiprangesArray(item.get('alias_ip_ranges', []), self.module).to_request(),
u'name': item.get('name'),
u'network': replace_resource_dict(item.get(u'network', {}), 'selfLink'),
u'networkIP': item.get('network_ip'),
u'subnetwork': replace_resource_dict(item.get(u'subnetwork', {}), 'selfLink'),
}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'accessConfigs': InstanceTemplateAccessconfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
u'aliasIpRanges': InstanceTemplateAliasiprangesArray(item.get(u'aliasIpRanges', []), self.module).from_response(),
u'name': item.get(u'name'),
u'network': item.get(u'network'),
u'networkIP': item.get(u'networkIP'),
u'subnetwork': item.get(u'subnetwork')
})
return remove_nones_from_dict(
{
u'accessConfigs': InstanceTemplateAccessconfigsArray(item.get(u'accessConfigs', []), self.module).from_response(),
u'aliasIpRanges': InstanceTemplateAliasiprangesArray(item.get(u'aliasIpRanges', []), self.module).from_response(),
u'name': item.get(u'name'),
u'network': item.get(u'network'),
u'networkIP': item.get(u'networkIP'),
u'subnetwork': item.get(u'subnetwork'),
}
)
class InstanceTemplateAccessconfigsArray(object):
@ -1412,18 +1408,12 @@ class InstanceTemplateAccessconfigsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'name': item.get('name'),
u'natIP': replace_resource_dict(item.get(u'nat_ip', {}), 'address'),
u'type': item.get('type')
})
return remove_nones_from_dict(
{u'name': item.get('name'), u'natIP': replace_resource_dict(item.get(u'nat_ip', {}), 'address'), u'type': item.get('type')}
)
def _response_from_item(self, item):
return remove_nones_from_dict({
u'name': item.get(u'name'),
u'natIP': item.get(u'natIP'),
u'type': item.get(u'type')
})
return remove_nones_from_dict({u'name': item.get(u'name'), u'natIP': item.get(u'natIP'), u'type': item.get(u'type')})
class InstanceTemplateAliasiprangesArray(object):
@ -1447,16 +1437,10 @@ class InstanceTemplateAliasiprangesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'ipCidrRange': item.get('ip_cidr_range'),
u'subnetworkRangeName': item.get('subnetwork_range_name')
})
return remove_nones_from_dict({u'ipCidrRange': item.get('ip_cidr_range'), u'subnetworkRangeName': item.get('subnetwork_range_name')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'ipCidrRange': item.get(u'ipCidrRange'),
u'subnetworkRangeName': item.get(u'subnetworkRangeName')
})
return remove_nones_from_dict({u'ipCidrRange': item.get(u'ipCidrRange'), u'subnetworkRangeName': item.get(u'subnetworkRangeName')})
class InstanceTemplateScheduling(object):
@ -1468,18 +1452,22 @@ class InstanceTemplateScheduling(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'automaticRestart': self.request.get('automatic_restart'),
u'onHostMaintenance': self.request.get('on_host_maintenance'),
u'preemptible': self.request.get('preemptible')
})
return remove_nones_from_dict(
{
u'automaticRestart': self.request.get('automatic_restart'),
u'onHostMaintenance': self.request.get('on_host_maintenance'),
u'preemptible': self.request.get('preemptible'),
}
)
def from_response(self):
return remove_nones_from_dict({
u'automaticRestart': self.request.get(u'automaticRestart'),
u'onHostMaintenance': self.request.get(u'onHostMaintenance'),
u'preemptible': self.request.get(u'preemptible')
})
return remove_nones_from_dict(
{
u'automaticRestart': self.request.get(u'automaticRestart'),
u'onHostMaintenance': self.request.get(u'onHostMaintenance'),
u'preemptible': self.request.get(u'preemptible'),
}
)
class InstanceTemplateServiceaccountsArray(object):
@ -1503,16 +1491,10 @@ class InstanceTemplateServiceaccountsArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'email': item.get('email'),
u'scopes': item.get('scopes')
})
return remove_nones_from_dict({u'email': item.get('email'), u'scopes': item.get('scopes')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'email': item.get(u'email'),
u'scopes': item.get(u'scopes')
})
return remove_nones_from_dict({u'email': item.get(u'email'), u'scopes': item.get(u'scopes')})
class InstanceTemplateTags(object):
@ -1524,16 +1506,10 @@ class InstanceTemplateTags(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'fingerprint': self.request.get('fingerprint'),
u'items': self.request.get('items')
})
return remove_nones_from_dict({u'fingerprint': self.request.get('fingerprint'), u'items': self.request.get('items')})
def from_response(self):
return remove_nones_from_dict({
u'fingerprint': self.request.get(u'fingerprint'),
u'items': self.request.get(u'items')
})
return remove_nones_from_dict({u'fingerprint': self.request.get(u'fingerprint'), u'items': self.request.get(u'items')})
if __name__ == '__main__':

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

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -78,6 +77,20 @@ options:
characters must be a dash, lowercase letter, or digit, except the last character,
which cannot be a dash.
required: true
candidate_subnets:
description:
- Up to 16 candidate prefixes that can be used to restrict the allocation of cloudRouterIpAddress
and customerRouterIpAddress for this attachment.
- All prefixes must be within link-local address space (169.254.0.0/16) and must
be /29 or shorter (/28, /27, etc). Google will attempt to select an unused /29
from the supplied candidate prefix(es). The request will fail if all possible
/29s are in use on Google's edge. If not supplied, Google will randomly select
an unused /29 from all of link-local space.
required: false
vlan_tag8021q:
description:
- The IEEE 802.1Q VLAN tag for this attachment, in the range 2-4094.
required: false
region:
description:
- Region where the regional interconnect attachment resides.
@ -170,6 +183,22 @@ name:
which cannot be a dash.
returned: success
type: str
candidateSubnets:
description:
- Up to 16 candidate prefixes that can be used to restrict the allocation of cloudRouterIpAddress
and customerRouterIpAddress for this attachment.
- All prefixes must be within link-local address space (169.254.0.0/16) and must
be /29 or shorter (/28, /27, etc). Google will attempt to select an unused /29
from the supplied candidate prefix(es). The request will fail if all possible
/29s are in use on Google's edge. If not supplied, Google will randomly select
an unused /29 from all of link-local space.
returned: success
type: list
vlanTag8021q:
description:
- The IEEE 802.1Q VLAN tag for this attachment, in the range 2-4094.
returned: success
type: int
region:
description:
- Region where the regional interconnect attachment resides.
@ -201,7 +230,9 @@ def main():
description=dict(type='str'),
router=dict(required=True),
name=dict(required=True, type='str'),
region=dict(required=True, type='str')
candidate_subnets=dict(type='list', elements='str'),
vlan_tag8021q=dict(type='int'),
region=dict(required=True, type='str'),
)
)
@ -256,7 +287,9 @@ def resource_to_request(module):
u'interconnect': module.params.get('interconnect'),
u'description': module.params.get('description'),
u'router': replace_resource_dict(module.params.get(u'router', {}), 'selfLink'),
u'name': module.params.get('name')
u'name': module.params.get('name'),
u'candidateSubnets': module.params.get('candidate_subnets'),
u'vlanTag8021q': module.params.get('vlan_tag8021q'),
}
return_vals = {}
for k, v in request.items():
@ -291,8 +324,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -331,7 +364,9 @@ def response_to_hash(module, response):
u'router': response.get(u'router'),
u'creationTimestamp': response.get(u'creationTimestamp'),
u'id': response.get(u'id'),
u'name': response.get(u'name')
u'name': response.get(u'name'),
u'candidateSubnets': response.get(u'candidateSubnets'),
u'vlanTag8021q': response.get(u'vlanTag8021q'),
}
@ -366,7 +401,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -388,14 +423,10 @@ class InterconnectAttachmentPrivateinterconnectinfo(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'tag8021q': self.request.get('tag8021q')
})
return remove_nones_from_dict({u'tag8021q': self.request.get('tag8021q')})
def from_response(self):
return remove_nones_from_dict({
u'tag8021q': self.request.get(u'tag8021q')
})
return remove_nones_from_dict({u'tag8021q': self.request.get(u'tag8021q')})
if __name__ == '__main__':

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -141,6 +140,22 @@ items:
which cannot be a dash.
returned: success
type: str
candidateSubnets:
description:
- Up to 16 candidate prefixes that can be used to restrict the allocation of
cloudRouterIpAddress and customerRouterIpAddress for this attachment.
- All prefixes must be within link-local address space (169.254.0.0/16) and
must be /29 or shorter (/28, /27, etc). Google will attempt to select an unused
/29 from the supplied candidate prefix(es). The request will fail if all possible
/29s are in use on Google's edge. If not supplied, Google will randomly select
an unused /29 from all of link-local space.
returned: success
type: list
vlanTag8021q:
description:
- The IEEE 802.1Q VLAN tag for this attachment, in the range 2-4094.
returned: success
type: int
region:
description:
- Region where the regional interconnect attachment resides.
@ -160,12 +175,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
region=dict(required=True, type='str')
)
)
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
@ -175,9 +185,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -216,11 +215,9 @@ def main():
ipv4_range=dict(type='str'),
name=dict(required=True, type='str'),
auto_create_subnetworks=dict(type='bool'),
routing_config=dict(type='dict', options=dict(
routing_mode=dict(required=True, type='str', choices=['REGIONAL', 'GLOBAL'])
))
routing_config=dict(type='dict', options=dict(routing_mode=dict(required=True, type='str', choices=['REGIONAL', 'GLOBAL']))),
),
mutually_exclusive=[['auto_create_subnetworks', 'ipv4_range']]
mutually_exclusive=[['auto_create_subnetworks', 'ipv4_range']],
)
if not module.params['scopes']:
@ -276,7 +273,7 @@ def resource_to_request(module):
u'IPv4Range': module.params.get('ipv4_range'),
u'name': module.params.get('name'),
u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'),
u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request()
u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request(),
}
return_vals = {}
for k, v in request.items():
@ -311,8 +308,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -350,7 +347,7 @@ def response_to_hash(module, response):
u'subnetworks': response.get(u'subnetworks'),
u'autoCreateSubnetworks': module.params.get('auto_create_subnetworks'),
u'creationTimestamp': response.get(u'creationTimestamp'),
u'routingConfig': NetworkRoutingconfig(response.get(u'routingConfig', {}), module).from_response()
u'routingConfig': NetworkRoutingconfig(response.get(u'routingConfig', {}), module).from_response(),
}
@ -376,7 +373,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -398,14 +395,10 @@ class NetworkRoutingconfig(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'routingMode': self.request.get('routing_mode')
})
return remove_nones_from_dict({u'routingMode': self.request.get('routing_mode')})
def from_response(self):
return remove_nones_from_dict({
u'routingMode': self.request.get(u'routingMode')
})
return remove_nones_from_dict({u'routingMode': self.request.get(u'routingMode')})
if __name__ == '__main__':

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

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -346,15 +345,9 @@ def main():
replica_zones=dict(required=True, type='list', elements='str'),
type=dict(type='str'),
region=dict(required=True, type='str'),
disk_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
)),
disk_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), sha256=dict(type='str'))),
source_snapshot=dict(),
source_snapshot_encryption_key=dict(type='dict', options=dict(
raw_key=dict(type='str'),
sha256=dict(type='str')
))
source_snapshot_encryption_key=dict(type='dict', options=dict(raw_key=dict(type='str'), sha256=dict(type='str'))),
)
)
@ -395,8 +388,7 @@ def create(module, link, kind):
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module),
response_to_hash(module, fetch))
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)
@ -410,27 +402,16 @@ def update_fields(module, request, response):
def label_fingerprint_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/regions/{region}/disks/{name}/setLabels"
]).format(**module.params),
{
u'labelFingerprint': response.get('labelFingerprint'),
u'labels': module.params.get('labels')
}
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/disks/{name}/setLabels"]).format(**module.params),
{u'labelFingerprint': response.get('labelFingerprint'), u'labels': module.params.get('labels')},
)
def size_gb_update(module, request, response):
auth = GcpSession(module, 'compute')
auth.post(
''.join([
"https://www.googleapis.com/compute/v1/",
"projects/{project}/regions/{region}/disks/{name}/resize"
]).format(**module.params),
{
u'sizeGb': module.params.get('size_gb')
}
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/regions/{region}/disks/{name}/resize"]).format(**module.params),
{u'sizeGb': module.params.get('size_gb')},
)
@ -450,7 +431,7 @@ def resource_to_request(module):
u'name': module.params.get('name'),
u'sizeGb': module.params.get('size_gb'),
u'replicaZones': module.params.get('replica_zones'),
u'type': region_disk_type_selflink(module.params.get('type'), module.params)
u'type': region_disk_type_selflink(module.params.get('type'), module.params),
}
return_vals = {}
for k, v in request.items():
@ -485,8 +466,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -528,7 +509,7 @@ def response_to_hash(module, response):
u'sizeGb': response.get(u'sizeGb'),
u'users': response.get(u'users'),
u'replicaZones': response.get(u'replicaZones'),
u'type': response.get(u'type')
u'type': response.get(u'type'),
}
@ -572,7 +553,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -594,16 +575,10 @@ class RegionDiskDiskencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get('raw_key'), u'sha256': self.request.get('sha256')})
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get(u'rawKey'), u'sha256': self.request.get(u'sha256')})
class RegionDiskSourcesnapshotencryptionkey(object):
@ -615,16 +590,10 @@ class RegionDiskSourcesnapshotencryptionkey(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'rawKey': self.request.get('raw_key'),
u'sha256': self.request.get('sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get('raw_key'), u'sha256': self.request.get('sha256')})
def from_response(self):
return remove_nones_from_dict({
u'rawKey': self.request.get(u'rawKey'),
u'sha256': self.request.get(u'sha256')
})
return remove_nones_from_dict({u'rawKey': self.request.get(u'rawKey'), u'sha256': self.request.get(u'sha256')})
if __name__ == '__main__':

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -228,12 +227,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
region=dict(required=True, type='str')
)
)
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
@ -243,9 +237,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -269,7 +268,7 @@ def main():
next_hop_gateway=dict(type='str'),
next_hop_instance=dict(),
next_hop_ip=dict(type='str'),
next_hop_vpn_tunnel=dict()
next_hop_vpn_tunnel=dict(),
)
)
@ -330,7 +329,7 @@ def resource_to_request(module):
u'nextHopGateway': module.params.get('next_hop_gateway'),
u'nextHopInstance': replace_resource_dict(module.params.get(u'next_hop_instance', {}), 'selfLink'),
u'nextHopIp': module.params.get('next_hop_ip'),
u'nextHopVpnTunnel': replace_resource_dict(module.params.get(u'next_hop_vpn_tunnel', {}), 'selfLink')
u'nextHopVpnTunnel': replace_resource_dict(module.params.get(u'next_hop_vpn_tunnel', {}), 'selfLink'),
}
return_vals = {}
for k, v in request.items():
@ -365,8 +364,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -406,7 +405,7 @@ def response_to_hash(module, response):
u'nextHopInstance': replace_resource_dict(module.params.get(u'next_hop_instance', {}), 'selfLink'),
u'nextHopIp': module.params.get('next_hop_ip'),
u'nextHopVpnTunnel': replace_resource_dict(module.params.get(u'next_hop_vpn_tunnel', {}), 'selfLink'),
u'nextHopNetwork': response.get(u'nextHopNetwork')
u'nextHopNetwork': response.get(u'nextHopNetwork'),
}
@ -432,7 +431,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])

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

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -260,16 +259,16 @@ def main():
name=dict(required=True, type='str'),
description=dict(type='str'),
network=dict(required=True),
bgp=dict(type='dict', options=dict(
asn=dict(required=True, type='int'),
advertise_mode=dict(default='DEFAULT', type='str', choices=['DEFAULT', 'CUSTOM']),
advertised_groups=dict(type='list', elements='str'),
advertised_ip_ranges=dict(type='list', elements='dict', options=dict(
range=dict(type='str'),
description=dict(type='str')
))
)),
region=dict(required=True, type='str')
bgp=dict(
type='dict',
options=dict(
asn=dict(required=True, type='int'),
advertise_mode=dict(default='DEFAULT', type='str', choices=['DEFAULT', 'CUSTOM']),
advertised_groups=dict(type='list', elements='str'),
advertised_ip_ranges=dict(type='list', elements='dict', options=dict(range=dict(type='str'), description=dict(type='str'))),
),
),
region=dict(required=True, type='str'),
)
)
@ -326,7 +325,7 @@ def resource_to_request(module):
u'name': module.params.get('name'),
u'description': module.params.get('description'),
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
u'bgp': RouterBgp(module.params.get('bgp', {}), module).to_request()
u'bgp': RouterBgp(module.params.get('bgp', {}), module).to_request(),
}
return_vals = {}
for k, v in request.items():
@ -361,8 +360,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -397,7 +396,7 @@ def response_to_hash(module, response):
u'name': module.params.get('name'),
u'description': response.get(u'description'),
u'network': replace_resource_dict(module.params.get(u'network', {}), 'selfLink'),
u'bgp': RouterBgp(response.get(u'bgp', {}), module).from_response()
u'bgp': RouterBgp(response.get(u'bgp', {}), module).from_response(),
}
@ -423,7 +422,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])
@ -445,20 +444,24 @@ class RouterBgp(object):
self.request = {}
def to_request(self):
return remove_nones_from_dict({
u'asn': self.request.get('asn'),
u'advertiseMode': self.request.get('advertise_mode'),
u'advertisedGroups': self.request.get('advertised_groups'),
u'advertisedIpRanges': RouterAdvertisediprangesArray(self.request.get('advertised_ip_ranges', []), self.module).to_request()
})
return remove_nones_from_dict(
{
u'asn': self.request.get('asn'),
u'advertiseMode': self.request.get('advertise_mode'),
u'advertisedGroups': self.request.get('advertised_groups'),
u'advertisedIpRanges': RouterAdvertisediprangesArray(self.request.get('advertised_ip_ranges', []), self.module).to_request(),
}
)
def from_response(self):
return remove_nones_from_dict({
u'asn': self.request.get(u'asn'),
u'advertiseMode': self.request.get(u'advertiseMode'),
u'advertisedGroups': self.request.get(u'advertisedGroups'),
u'advertisedIpRanges': RouterAdvertisediprangesArray(self.request.get(u'advertisedIpRanges', []), self.module).from_response()
})
return remove_nones_from_dict(
{
u'asn': self.request.get(u'asn'),
u'advertiseMode': self.request.get(u'advertiseMode'),
u'advertisedGroups': self.request.get(u'advertisedGroups'),
u'advertisedIpRanges': RouterAdvertisediprangesArray(self.request.get(u'advertisedIpRanges', []), self.module).from_response(),
}
)
class RouterAdvertisediprangesArray(object):
@ -482,16 +485,10 @@ class RouterAdvertisediprangesArray(object):
return items
def _request_for_item(self, item):
return remove_nones_from_dict({
u'range': item.get('range'),
u'description': item.get('description')
})
return remove_nones_from_dict({u'range': item.get('range'), u'description': item.get('description')})
def _response_from_item(self, item):
return remove_nones_from_dict({
u'range': item.get(u'range'),
u'description': item.get(u'description')
})
return remove_nones_from_dict({u'range': item.get(u'range'), u'description': item.get(u'description')})
if __name__ == '__main__':

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -167,12 +166,7 @@ import json
def main():
module = GcpModule(
argument_spec=dict(
filters=dict(type='list', elements='str'),
region=dict(required=True, type='str')
)
)
module = GcpModule(argument_spec=dict(filters=dict(type='list', elements='str'), region=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/compute']
@ -182,9 +176,7 @@ def main():
items = items.get('items')
else:
items = []
return_value = {
'items': items
}
return_value = {'items': items}
module.exit_json(**return_value)

@ -18,15 +18,14 @@
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ["preview"],
'supported_by': 'community'}
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
@ -176,7 +175,7 @@ def main():
certificate=dict(required=True, type='str'),
description=dict(type='str'),
name=dict(type='str'),
private_key=dict(required=True, type='str')
private_key=dict(required=True, type='str'),
)
)
@ -231,7 +230,7 @@ def resource_to_request(module):
u'certificate': module.params.get('certificate'),
u'description': module.params.get('description'),
u'name': module.params.get('name'),
u'privateKey': module.params.get('private_key')
u'privateKey': module.params.get('private_key'),
}
return_vals = {}
for k, v in request.items():
@ -266,8 +265,8 @@ def return_if_object(module, response, kind, allow_not_found=False):
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
except getattr(json.decoder, 'JSONDecodeError', ValueError):
module.fail_json(msg="Invalid JSON response with error: %s" % response.text)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
@ -302,7 +301,7 @@ def response_to_hash(module, response):
u'description': response.get(u'description'),
u'id': response.get(u'id'),
u'name': response.get(u'name'),
u'privateKey': module.params.get('private_key')
u'privateKey': module.params.get('private_key'),
}
@ -328,7 +327,7 @@ def wait_for_completion(status, op_result, module):
op_id = navigate_hash(op_result, ['name'])
op_uri = async_op_url(module, {'op_id': op_id})
while status != 'DONE':
raise_if_errors(op_result, ['error', 'errors'], 'message')
raise_if_errors(op_result, ['error', 'errors'], module)
time.sleep(1.0)
op_result = fetch_resource(module, op_uri, 'compute#operation')
status = navigate_hash(op_result, ['status'])

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

Loading…
Cancel
Save