Skip to content

Commit

Permalink
[DM] network_peering: refactoring (#214)
Browse files Browse the repository at this point in the history
#145

- Added version, links to docs
- Added support for cross-project resource creation
- Fixed resource names
- Added support for "networkPeering" field
  • Loading branch information
bohdanyurov-gl authored and ocsig committed Jul 11, 2019
1 parent 65a5096 commit 2517803
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
16 changes: 11 additions & 5 deletions dm/templates/network_peering/network_peering.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,39 @@ def generate_config(context):

resources = []
properties = context.properties
peer_name = properties['name'] or context.env['name']
name = properties.get('name', context.env['name'])
project_id = properties.get('project', context.env['project'])

peer_create = {
'name': peer_name + '-createPeer',
'name': context.env['name'] + '-create-peer',
# https://cloud.google.com/compute/docs/reference/rest/v1/networks/addPeering
'action': 'gcp-types/compute-v1:compute.networks.addPeering',
'metadata': {
'runtimePolicy': ['CREATE',
]
},
'properties':
{
'name': peer_name,
'name': name,
'project': project_id,
'network': properties['network'],
'peerNetwork': properties['peerNetwork'],
'autoCreateRoutes': properties.get('autoCreateRoutes')
}
}

peer_delete = {
'name': peer_name + '-deletePeer',
'name': context.env['name'] + '-delete-peer',
# https://cloud.google.com/compute/docs/reference/rest/v1/networks/removePeering
'action': 'gcp-types/compute-v1:compute.networks.removePeering',
'metadata': {
'runtimePolicy': ['DELETE',
]
},
'properties':
{
'name': peer_name,
'name': name,
'project': project_id,
'network': properties['network'],
'peerNetwork': properties['peerNetwork']
}
Expand Down
20 changes: 17 additions & 3 deletions dm/templates/network_peering/network_peering.py.schema
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@

info:
title: VPC Network Peering
version: 1.0.0
author: Sourced Group Inc.
description: |
Creates peering between VPC networks.

For more information on this resource, see
https://cloud.google.com/compute/docs/reference/rest/beta/networks/addPeering.
For more information on this resource:
https://cloud.google.com/compute/docs/reference/rest/beta/networks/addPeering

APIs endpoints used by this template:
- gcp-types/compute-v1:compute.networks.addPeering =>
https://cloud.google.com/compute/docs/reference/rest/v1/networks/addPeering
- gcp-types/compute-v1:compute.networks.removePeering =>
https://cloud.google.com/compute/docs/reference/rest/v1/networks/removePeering

imports:
- path: network_peering.py
Expand All @@ -34,7 +41,14 @@ required:
properties:
name:
type: string
description: The peering name. Must conform to RFC1035.
description: |
The peering name. Must conform to RFC1035.
Resource name would be used if omitted.
project:
type: string
description: |
The project ID of the project containing resources. The
Google apps domain is prefixed if applicable.
network:
type: string
description: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function teardown() {
run gcloud deployment-manager deployments create "${DEPLOYMENT_NAME}" \
--config "${CONFIG}" \
--project "${CLOUD_FOUNDATION_PROJECT_ID}"
echo $output
[[ "$status" -eq 0 ]]
}

Expand Down

0 comments on commit 2517803

Please sign in to comment.