From aa5a221ddc8b9f93385b1d8449979eba030d51f0 Mon Sep 17 00:00:00 2001 From: The Magician Date: Mon, 26 Aug 2019 12:04:52 -0700 Subject: [PATCH] Bug fixes for GCP modules (#61094) --- .../cloud/google/gcp_container_cluster.py | 202 ++++++++++++++++++ .../google/gcp_container_cluster_info.py | 73 +++++++ .../google/gcp_dns_resource_record_set.py | 16 +- .../gcp_dns_resource_record_set_info.py | 15 +- 4 files changed, 291 insertions(+), 15 deletions(-) diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster.py b/lib/ansible/modules/cloud/google/gcp_container_cluster.py index 49df86f23c8..d525a1d962c 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster.py @@ -436,6 +436,80 @@ options: - Constraint enforced on the max num of pods per node. required: false type: str + ip_allocation_policy: + description: + - Configuration for controlling how IPs are allocated in the cluster. + required: false + type: dict + version_added: 2.9 + suboptions: + use_ip_aliases: + description: + - Whether alias IPs will be used for pod IPs in the cluster. + required: false + type: bool + create_subnetwork: + description: + - Whether a new subnetwork will be created automatically for the cluster. + required: false + type: bool + subnetwork_name: + description: + - A custom subnetwork name to be used if createSubnetwork is true. + - If this field is empty, then an automatic name will be chosen for the new + subnetwork. + required: false + type: str + cluster_secondary_range_name: + description: + - The name of the secondary range to be used for the cluster CIDR block. The + secondary range will be used for pod IP addresses. + - This must be an existing secondary range associated with the cluster subnetwork + . + required: false + type: str + services_secondary_range_name: + description: + - The name of the secondary range to be used as for the services CIDR block. + The secondary range will be used for service ClusterIPs. This must be an + existing secondary range associated with the cluster subnetwork. + required: false + type: str + cluster_ipv4_cidr_block: + description: + - The IP address range for the cluster pod IPs. If this field is set, then + cluster.cluster_ipv4_cidr must be left blank. + - This field is only applicable when useIpAliases is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + required: false + type: str + node_ipv4_cidr_block: + description: + - The IP address range of the instance IPs in this cluster. + - This is applicable only if createSubnetwork is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + required: false + type: str + services_ipv4_cidr_block: + description: + - The IP address range of the services IPs in this cluster. If blank, a range + will be automatically chosen with the default size. + - This field is only applicable when useIpAliases is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + required: false + type: str + tpu_ipv4_cidr_block: + description: + - The IP address range of the Cloud TPUs in this cluster. If unspecified, + a range will be automatically chosen with the default size. + - This field is only applicable when useIpAliases is true. + - If unspecified, the range will use the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + required: false + type: str enable_tpu: description: - Enable the ability to use Cloud TPUs in this cluster. @@ -893,6 +967,79 @@ defaultMaxPodsConstraint: - Constraint enforced on the max num of pods per node. returned: success type: str +ipAllocationPolicy: + description: + - Configuration for controlling how IPs are allocated in the cluster. + returned: success + type: complex + contains: + useIpAliases: + description: + - Whether alias IPs will be used for pod IPs in the cluster. + returned: success + type: bool + createSubnetwork: + description: + - Whether a new subnetwork will be created automatically for the cluster. + returned: success + type: bool + subnetworkName: + description: + - A custom subnetwork name to be used if createSubnetwork is true. + - If this field is empty, then an automatic name will be chosen for the new + subnetwork. + returned: success + type: str + clusterSecondaryRangeName: + description: + - The name of the secondary range to be used for the cluster CIDR block. The + secondary range will be used for pod IP addresses. + - This must be an existing secondary range associated with the cluster subnetwork + . + returned: success + type: str + servicesSecondaryRangeName: + description: + - The name of the secondary range to be used as for the services CIDR block. + The secondary range will be used for service ClusterIPs. This must be an existing + secondary range associated with the cluster subnetwork. + returned: success + type: str + clusterIpv4CidrBlock: + description: + - The IP address range for the cluster pod IPs. If this field is set, then cluster.cluster_ipv4_cidr + must be left blank. + - This field is only applicable when useIpAliases is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str + nodeIpv4CidrBlock: + description: + - The IP address range of the instance IPs in this cluster. + - This is applicable only if createSubnetwork is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str + servicesIpv4CidrBlock: + description: + - The IP address range of the services IPs in this cluster. If blank, a range + will be automatically chosen with the default size. + - This field is only applicable when useIpAliases is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str + tpuIpv4CidrBlock: + description: + - The IP address range of the Cloud TPUs in this cluster. If unspecified, a + range will be automatically chosen with the default size. + - This field is only applicable when useIpAliases is true. + - If unspecified, the range will use the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str endpoint: description: - The IP address of this cluster's master endpoint. @@ -1074,6 +1221,20 @@ def main(): legacy_abac=dict(type='dict', options=dict(enabled=dict(type='bool'))), network_policy=dict(type='dict', options=dict(provider=dict(type='str'), enabled=dict(type='bool'))), default_max_pods_constraint=dict(type='dict', options=dict(max_pods_per_node=dict(type='str'))), + ip_allocation_policy=dict( + type='dict', + options=dict( + use_ip_aliases=dict(type='bool'), + create_subnetwork=dict(type='bool'), + subnetwork_name=dict(type='str'), + cluster_secondary_range_name=dict(type='str'), + services_secondary_range_name=dict(type='str'), + cluster_ipv4_cidr_block=dict(type='str'), + node_ipv4_cidr_block=dict(type='str'), + services_ipv4_cidr_block=dict(type='str'), + tpu_ipv4_cidr_block=dict(type='str'), + ), + ), enable_tpu=dict(type='bool'), tpu_ipv4_cidr_block=dict(type='str'), location=dict(required=True, type='str', aliases=['zone']), @@ -1149,6 +1310,7 @@ def resource_to_request(module): u'legacyAbac': ClusterLegacyabac(module.params.get('legacy_abac', {}), module).to_request(), u'networkPolicy': ClusterNetworkpolicy(module.params.get('network_policy', {}), module).to_request(), u'defaultMaxPodsConstraint': ClusterDefaultmaxpodsconstraint(module.params.get('default_max_pods_constraint', {}), module).to_request(), + u'ipAllocationPolicy': ClusterIpallocationpolicy(module.params.get('ip_allocation_policy', {}), module).to_request(), u'enableTpu': module.params.get('enable_tpu'), u'tpuIpv4CidrBlock': module.params.get('tpu_ipv4_cidr_block'), } @@ -1235,6 +1397,7 @@ def response_to_hash(module, response): u'legacyAbac': ClusterLegacyabac(response.get(u'legacyAbac', {}), module).from_response(), u'networkPolicy': ClusterNetworkpolicy(response.get(u'networkPolicy', {}), module).from_response(), u'defaultMaxPodsConstraint': ClusterDefaultmaxpodsconstraint(response.get(u'defaultMaxPodsConstraint', {}), module).from_response(), + u'ipAllocationPolicy': ClusterIpallocationpolicy(response.get(u'ipAllocationPolicy', {}), module).from_response(), u'endpoint': response.get(u'endpoint'), u'initialClusterVersion': response.get(u'initialClusterVersion'), u'currentMasterVersion': response.get(u'currentMasterVersion'), @@ -1672,6 +1835,45 @@ class ClusterDefaultmaxpodsconstraint(object): return remove_nones_from_dict({u'maxPodsPerNode': self.request.get(u'maxPodsPerNode')}) +class ClusterIpallocationpolicy(object): + def __init__(self, request, module): + self.module = module + if request: + self.request = request + else: + self.request = {} + + def to_request(self): + return remove_nones_from_dict( + { + u'useIpAliases': self.request.get('use_ip_aliases'), + u'createSubnetwork': self.request.get('create_subnetwork'), + u'subnetworkName': self.request.get('subnetwork_name'), + u'clusterSecondaryRangeName': self.request.get('cluster_secondary_range_name'), + u'servicesSecondaryRangeName': self.request.get('services_secondary_range_name'), + u'clusterIpv4CidrBlock': self.request.get('cluster_ipv4_cidr_block'), + u'nodeIpv4CidrBlock': self.request.get('node_ipv4_cidr_block'), + u'servicesIpv4CidrBlock': self.request.get('services_ipv4_cidr_block'), + u'tpuIpv4CidrBlock': self.request.get('tpu_ipv4_cidr_block'), + } + ) + + def from_response(self): + return remove_nones_from_dict( + { + u'useIpAliases': self.request.get(u'useIpAliases'), + u'createSubnetwork': self.request.get(u'createSubnetwork'), + u'subnetworkName': self.request.get(u'subnetworkName'), + u'clusterSecondaryRangeName': self.request.get(u'clusterSecondaryRangeName'), + u'servicesSecondaryRangeName': self.request.get(u'servicesSecondaryRangeName'), + u'clusterIpv4CidrBlock': self.request.get(u'clusterIpv4CidrBlock'), + u'nodeIpv4CidrBlock': self.request.get(u'nodeIpv4CidrBlock'), + u'servicesIpv4CidrBlock': self.request.get(u'servicesIpv4CidrBlock'), + u'tpuIpv4CidrBlock': self.request.get(u'tpuIpv4CidrBlock'), + } + ) + + class ClusterConditionsArray(object): def __init__(self, request, module): self.module = module diff --git a/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py b/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py index c23957e0fce..30176feff50 100644 --- a/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py +++ b/lib/ansible/modules/cloud/google/gcp_container_cluster_info.py @@ -470,6 +470,79 @@ resources: - Constraint enforced on the max num of pods per node. returned: success type: str + ipAllocationPolicy: + description: + - Configuration for controlling how IPs are allocated in the cluster. + returned: success + type: complex + contains: + useIpAliases: + description: + - Whether alias IPs will be used for pod IPs in the cluster. + returned: success + type: bool + createSubnetwork: + description: + - Whether a new subnetwork will be created automatically for the cluster. + returned: success + type: bool + subnetworkName: + description: + - A custom subnetwork name to be used if createSubnetwork is true. + - If this field is empty, then an automatic name will be chosen for the + new subnetwork. + returned: success + type: str + clusterSecondaryRangeName: + description: + - The name of the secondary range to be used for the cluster CIDR block. + The secondary range will be used for pod IP addresses. + - This must be an existing secondary range associated with the cluster subnetwork + . + returned: success + type: str + servicesSecondaryRangeName: + description: + - The name of the secondary range to be used as for the services CIDR block. + The secondary range will be used for service ClusterIPs. This must be + an existing secondary range associated with the cluster subnetwork. + returned: success + type: str + clusterIpv4CidrBlock: + description: + - The IP address range for the cluster pod IPs. If this field is set, then + cluster.cluster_ipv4_cidr must be left blank. + - This field is only applicable when useIpAliases is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str + nodeIpv4CidrBlock: + description: + - The IP address range of the instance IPs in this cluster. + - This is applicable only if createSubnetwork is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str + servicesIpv4CidrBlock: + description: + - The IP address range of the services IPs in this cluster. If blank, a + range will be automatically chosen with the default size. + - This field is only applicable when useIpAliases is true. + - Set to blank to have a range chosen with the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str + tpuIpv4CidrBlock: + description: + - The IP address range of the Cloud TPUs in this cluster. If unspecified, + a range will be automatically chosen with the default size. + - This field is only applicable when useIpAliases is true. + - If unspecified, the range will use the default size. + - Set to /netmask (e.g. /14) to have a range chosen with a specific netmask. + returned: success + type: str endpoint: description: - The IP address of this cluster's master endpoint. diff --git a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py index d74ab7cd37a..0e347dedd82 100644 --- a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py +++ b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set.py @@ -76,12 +76,9 @@ options: type: list managed_zone: description: - - Identifies the managed zone addressed by this request. - - 'This field represents a link to a ManagedZone resource in GCP. It can be specified - in two ways. First, you can place a dictionary with key ''name'' and value of - your resource''s name Alternatively, you can add `register: name-of-resource` - to a gcp_dns_managed_zone task and then set this managed_zone field to "{{ name-of-resource - }}"' + - Identifies the managed zone addressed by this request. This must be a dictionary + that contains both a 'name' key and a 'dnsName' key. You can pass in the results + of the gcp_dns_managed_zone module, which will contain both. required: true type: dict extends_documentation_fragment: gcp @@ -137,7 +134,9 @@ target: type: list managed_zone: description: - - Identifies the managed zone addressed by this request. + - Identifies the managed zone addressed by this request. This must be a dictionary + that contains both a 'name' key and a 'dnsName' key. You can pass in the results + of the gcp_dns_managed_zone module, which will contain both. returned: success type: dict ''' @@ -180,6 +179,9 @@ def main(): fetch = fetch_wrapped_resource(module, 'dns#resourceRecordSet', 'dns#resourceRecordSetsListResponse', 'rrsets') changed = False + if 'dnsName' not in module.params.get('managed_zone') or 'name' not in module.params.get('managed_zone'): + module.fail_json(msg="managed_zone dictionary must contain both the name of the zone and the dns name of the zone") + if fetch: if state == 'present': if is_different(module, fetch): diff --git a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py index 9ce382c661d..9b8bc4d7014 100644 --- a/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py +++ b/lib/ansible/modules/cloud/google/gcp_dns_resource_record_set_info.py @@ -44,12 +44,9 @@ requirements: options: managed_zone: description: - - Identifies the managed zone addressed by this request. - - 'This field represents a link to a ManagedZone resource in GCP. It can be specified - in two ways. First, you can place a dictionary with key ''name'' and value of - your resource''s name Alternatively, you can add `register: name-of-resource` - to a gcp_dns_managed_zone task and then set this managed_zone field to "{{ name-of-resource - }}"' + - Identifies the managed zone addressed by this request. This must be a dictionary + that contains both a 'name' key and a 'dnsName' key. You can pass in the results + of the gcp_dns_managed_zone module, which will contain both. required: true type: dict extends_documentation_fragment: gcp @@ -92,7 +89,9 @@ resources: type: list managed_zone: description: - - Identifies the managed zone addressed by this request. + - Identifies the managed zone addressed by this request. This must be a dictionary + that contains both a 'name' key and a 'dnsName' key. You can pass in the results + of the gcp_dns_managed_zone module, which will contain both. returned: success type: dict ''' @@ -123,7 +122,7 @@ def main(): def collection(module): res = {'project': module.params['project'], 'managed_zone': replace_resource_dict(module.params['managed_zone'], 'name')} - return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/changes".format(**res) + return "https://www.googleapis.com/dns/v1/projects/{project}/managedZones/{managed_zone}/rrsets".format(**res) def fetch_list(module, link):