Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Fix Network updating, improve docs. (#204)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rambleraptor committed May 20, 2019
1 parent 4e46f89 commit 7902350
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 56 deletions.
95 changes: 53 additions & 42 deletions lib/ansible/modules/cloud/google/gcp_compute_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,7 @@
---
module: gcp_compute_network
description:
- Represents a Network resource.
- Your Cloud Platform Console project can contain multiple networks, and each network
can have multiple instances attached to it. A network allows you to define a gateway
IP and the network range for the instances attached to that network. Every project
is provided with a default network with preset configurations and firewall rules.
You can choose to customize the default network by adding or removing rules, or
you can create new networks in that project. Generally, most users only need one
network, although you can have up to five networks per project by default.
- A network belongs to only one project, and each instance can only belong to one
network. All Compute Engine networks use the IPv4 protocol. Compute Engine currently
does not support IPv6. However, Google is a major advocate of IPv6 and it is an
important future direction.
- Manages a VPC network or legacy network resource on GCP.
short_description: Creates a GCP Network
version_added: 2.6
author: Google Inc. (@googlecloudplatform)
Expand All @@ -60,14 +49,18 @@
default: present
description:
description:
- An optional description of this resource. Provide this property when you create
the resource.
- An optional description of this resource. The resource must be recreated to
modify this field.
required: false
ipv4_range:
description:
- 'The range of internal addresses that are legal on this network. This range
is a CIDR specification, for example: 192.168.0.0/16. Provided by the client
when the network is created.'
- If this field is specified, a deprecated legacy network is created.
- You will no longer be able to create a legacy network on Feb 1, 2020.
- See the [legacy network docs](U(https://cloud.google.com/vpc/docs/legacy)) for
more details.
- The range of internal addresses that are legal on this legacy network.
- 'This range is a CIDR specification, for example: `192.168.0.0/16`.'
- The resource must be recreated to modify this field.
required: false
name:
description:
Expand All @@ -80,10 +73,11 @@
required: true
auto_create_subnetworks:
description:
- When set to true, the network is created in "auto subnet mode". When set to
false, the network is in "custom subnet mode".
- In "auto subnet mode", a newly created network is assigned the default CIDR
of 10.128.0.0/9 and it automatically creates one subnetwork per region.
- When set to `true`, the network is created in "auto subnet mode" and it will
create a subnet for each region automatically across the `10.128.0.0/9` address
range.
- When set to `false`, the network is created in "custom subnet mode" so the user
can explicitly connect subnetwork resources.
required: false
type: bool
routing_config:
Expand All @@ -95,9 +89,9 @@
suboptions:
routing_mode:
description:
- The network-wide routing mode to use. If set to REGIONAL, this network's
- The network-wide routing mode to use. If set to `REGIONAL`, this network's
cloud routers will only advertise routes with subnetworks of this network
in the same region as the router. If set to GLOBAL, this network's cloud
in the same region as the router. If set to `GLOBAL`, this network's cloud
routers will advertise routes with all subnetworks of this network, across
regions.
required: true
Expand All @@ -124,15 +118,14 @@
RETURN = '''
description:
description:
- An optional description of this resource. Provide this property when you create
the resource.
- An optional description of this resource. The resource must be recreated to modify
this field.
returned: success
type: str
gateway_ipv4:
description:
- A gateway address for default routing to other networks. This value is read only
and is selected by the Google Compute Engine, typically as the first usable address
in the IPv4Range.
- The gateway address for default routing out of the network. This value is selected
by GCP.
returned: success
type: str
id:
Expand All @@ -142,9 +135,13 @@
type: int
ipv4_range:
description:
- 'The range of internal addresses that are legal on this network. This range is
a CIDR specification, for example: 192.168.0.0/16. Provided by the client when
the network is created.'
- If this field is specified, a deprecated legacy network is created.
- You will no longer be able to create a legacy network on Feb 1, 2020.
- See the [legacy network docs](U(https://cloud.google.com/vpc/docs/legacy)) for
more details.
- The range of internal addresses that are legal on this legacy network.
- 'This range is a CIDR specification, for example: `192.168.0.0/16`.'
- The resource must be recreated to modify this field.
returned: success
type: str
name:
Expand All @@ -164,10 +161,10 @@
type: list
autoCreateSubnetworks:
description:
- When set to true, the network is created in "auto subnet mode". When set to false,
the network is in "custom subnet mode".
- In "auto subnet mode", a newly created network is assigned the default CIDR of
10.128.0.0/9 and it automatically creates one subnetwork per region.
- When set to `true`, the network is created in "auto subnet mode" and it will create
a subnet for each region automatically across the `10.128.0.0/9` address range.
- When set to `false`, the network is created in "custom subnet mode" so the user
can explicitly connect subnetwork resources.
returned: success
type: bool
creationTimestamp:
Expand All @@ -184,10 +181,11 @@
contains:
routingMode:
description:
- The network-wide routing mode to use. If set to REGIONAL, this network's cloud
routers will only advertise routes with subnetworks of this network in the
same region as the router. If set to GLOBAL, this network's cloud routers
will advertise routes with all subnetworks of this network, across regions.
- The network-wide routing mode to use. If set to `REGIONAL`, this network's
cloud routers will only advertise routes with subnetworks of this network
in the same region as the router. If set to `GLOBAL`, this network's cloud
routers will advertise routes with all subnetworks of this network, across
regions.
returned: success
type: str
'''
Expand Down Expand Up @@ -232,7 +230,7 @@ def main():
if fetch:
if state == 'present':
if is_different(module, fetch):
update(module, self_link(module), kind)
update(module, self_link(module), kind, fetch)
fetch = fetch_resource(module, self_link(module), kind)
changed = True
else:
Expand All @@ -256,9 +254,22 @@ def create(module, link, kind):
return wait_for_operation(module, auth.post(link, resource_to_request(module)))


def update(module, link, kind):
def update(module, link, kind, fetch):
update_fields(module, resource_to_request(module), response_to_hash(module, fetch))
return fetch_resource(module, self_link(module), kind)


def update_fields(module, request, response):
if response.get('routingConfig') != request.get('routingConfig'):
routing_config_update(module, request, response)


def routing_config_update(module, request, response):
auth = GcpSession(module, 'compute')
return wait_for_operation(module, auth.patch(link, resource_to_request(module)))
auth.patch(
''.join(["https://www.googleapis.com/compute/v1/", "projects/{project}/global/networks/{name}"]).format(**module.params),
{u'routingConfig': NetworkRoutingconfig(module.params.get('routing_config', {}), module).to_request()},
)


def delete(module, link, kind):
Expand Down
32 changes: 18 additions & 14 deletions lib/ansible/modules/cloud/google/gcp_compute_network_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,14 @@
contains:
description:
description:
- An optional description of this resource. Provide this property when you create
the resource.
- An optional description of this resource. The resource must be recreated to
modify this field.
returned: success
type: str
gateway_ipv4:
description:
- A gateway address for default routing to other networks. This value is read
only and is selected by the Google Compute Engine, typically as the first
usable address in the IPv4Range.
- The gateway address for default routing out of the network. This value is
selected by GCP.
returned: success
type: str
id:
Expand All @@ -85,9 +84,13 @@
type: int
ipv4_range:
description:
- 'The range of internal addresses that are legal on this network. This range
is a CIDR specification, for example: 192.168.0.0/16. Provided by the client
when the network is created.'
- If this field is specified, a deprecated legacy network is created.
- You will no longer be able to create a legacy network on Feb 1, 2020.
- See the [legacy network docs](U(https://cloud.google.com/vpc/docs/legacy))
for more details.
- The range of internal addresses that are legal on this legacy network.
- 'This range is a CIDR specification, for example: `192.168.0.0/16`.'
- The resource must be recreated to modify this field.
returned: success
type: str
name:
Expand All @@ -107,10 +110,11 @@
type: list
autoCreateSubnetworks:
description:
- When set to true, the network is created in "auto subnet mode". When set to
false, the network is in "custom subnet mode".
- In "auto subnet mode", a newly created network is assigned the default CIDR
of 10.128.0.0/9 and it automatically creates one subnetwork per region.
- When set to `true`, the network is created in "auto subnet mode" and it will
create a subnet for each region automatically across the `10.128.0.0/9` address
range.
- When set to `false`, the network is created in "custom subnet mode" so the
user can explicitly connect subnetwork resources.
returned: success
type: bool
creationTimestamp:
Expand All @@ -127,9 +131,9 @@
contains:
routingMode:
description:
- The network-wide routing mode to use. If set to REGIONAL, this network's
- The network-wide routing mode to use. If set to `REGIONAL`, this network's
cloud routers will only advertise routes with subnetworks of this network
in the same region as the router. If set to GLOBAL, this network's cloud
in the same region as the router. If set to `GLOBAL`, this network's cloud
routers will advertise routes with all subnetworks of this network, across
regions.
returned: success
Expand Down

0 comments on commit 7902350

Please sign in to comment.