Skip to content

Commit

Permalink
Add router resource
Browse files Browse the repository at this point in the history
  • Loading branch information
danawillow authored and modular-magician committed Jul 3, 2018
1 parent e13cb8a commit 7b08998
Show file tree
Hide file tree
Showing 13 changed files with 2,834 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ chef-codegen:
* libraries/google/compute/property/region_deprecated.rb
* libraries/google/compute/property/region_name.rb
* libraries/google/compute/property/region_selflink.rb
* libraries/google/compute/property/router_advertised_ip_ranges.rb
* libraries/google/compute/property/router_bgp.rb
* libraries/google/compute/property/snapshot_snapshot_encryption_key.rb
* libraries/google/compute/property/snapshot_source_disk_encryption_key.rb
* libraries/google/compute/property/sslcertificate_selflink.rb
Expand Down Expand Up @@ -328,6 +330,7 @@ chef-codegen:
* resources/network.rb
* resources/region.rb
* resources/route.rb
* resources/router.rb
* resources/snapshot.rb
* resources/ssl_certificate.rb
* resources/subnetwork.rb
Expand Down Expand Up @@ -475,6 +478,12 @@ chef-codegen:
* spec/data/network/gcompute_route/success2~title.yaml
* spec/data/network/gcompute_route/success3~name.yaml
* spec/data/network/gcompute_route/success3~title.yaml
* spec/data/network/gcompute_router/success1~name.yaml
* spec/data/network/gcompute_router/success1~title.yaml
* spec/data/network/gcompute_router/success2~name.yaml
* spec/data/network/gcompute_router/success2~title.yaml
* spec/data/network/gcompute_router/success3~name.yaml
* spec/data/network/gcompute_router/success3~title.yaml
* spec/data/network/gcompute_snapshot/success1~name.yaml
* spec/data/network/gcompute_snapshot/success1~title.yaml
* spec/data/network/gcompute_snapshot/success2~name.yaml
Expand Down Expand Up @@ -563,6 +572,7 @@ chef-codegen:
* spec/network_spec.rb
* spec/region_spec.rb
* spec/route_spec.rb
* spec/router_spec.rb
* spec/snapshot_spec.rb
* spec/spec_helper.rb
* spec/ssl_certificate_spec.rb
Expand Down
140 changes: 140 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ For complete details of the authentication cookbook, visit the
sending virtual machine's routing table will be dropped.
A Route resource must have exactly one specification of either
nextHopGateway, nextHopInstance, nextHopIp, or nextHopVpnTunnel.
* [`gcompute_router`](#gcompute_router) -
Represents a Router resource.
* [`gcompute_snapshot`](#gcompute_snapshot) -
Represents a Persistent Disk Snapshot resource.
Use snapshots to back up data from your persistent disks. Snapshots are
Expand Down Expand Up @@ -4321,6 +4323,144 @@ Set the `r_label` property when attempting to set primary key
of this object. The primary key will always be referred to by the initials of
the resource followed by "_label"

### gcompute_router
Represents a Router resource.


#### Example

```ruby
# Router requires a network and a region, so define them in your recipe:
# - gcompute_network 'my-network' do ... end
# - gcompute_region 'some-region' do ... end
gcompute_router 'my-router' do
action :create
bgp(
asn 64514
advertise_mode 'CUSTOM'
advertised_groups ['ALL_SUBNETS']
advertised_ip_ranges [
{
range '1.2.3.4'
}
{
range '6.7.0.0/16'
}
]
)
network 'my-network'
region 'some-region'
project ENV['PROJECT'] # ex: 'my-test-project'
credential 'mycred'
end

```

#### Reference

```ruby
gcompute_router 'id-for-resource' do
bgp {
advertise_mode 'DEFAULT' or 'CUSTOM',
advertised_groups [
string,
...
],
advertised_ip_ranges [
{
description string,
range string,
},
...
],
asn integer,
}
creation_timestamp time
description string
id integer
name string
network reference to gcompute_network
region reference to gcompute_region
project string
credential reference to gauth_credential
end
```

#### Actions

* `create` -
Converges the `gcompute_router` resource into the final
state described within the block. If the resource does not exist, Chef will
attempt to create it.
* `delete` -
Ensures the `gcompute_router` resource is not present.
If the resource already exists Chef will attempt to delete it.

#### Properties

* `id` -
Output only. The unique identifier for the resource.

* `creation_timestamp` -
Output only. Creation timestamp in RFC3339 text format.

* `name` -
Required. Name of the resource. The name must be 1-63 characters long, and
comply with RFC1035. Specifically, the name must be 1-63 characters
long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?`
which means the first character must be a lowercase letter, and all
following characters must be a dash, lowercase letter, or digit,
except the last character, which cannot be a dash.

* `description` -
An optional description of this resource.

* `network` -
Required. A reference to the network to which this router belongs.

* `bgp` -
BGP information specific to this router.

* `bgp/asn`
Required. Local BGP Autonomous System Number (ASN). Must be an RFC6996
private ASN, either 16-bit or 32-bit. The value will be fixed for
this router resource. All VPN tunnels that link to this router
will have the same local ASN.

* `bgp/advertise_mode`
User-specified flag to indicate which mode to use for advertisement.
Valid values of this enum field are: DEFAULT, CUSTOM

* `bgp/advertised_groups`
User-specified list of prefix groups to advertise in custom mode.
This field can only be populated if advertiseMode is CUSTOM and
is advertised to all peers of the router. These groups will be
advertised in addition to any specified prefixes. Leave this field
blank to advertise no custom groups.
This enum field has the one valid value: ALL_SUBNETS

* `bgp/advertised_ip_ranges`
User-specified list of individual IP ranges to advertise in
custom mode. This field can only be populated if advertiseMode
is CUSTOM and is advertised to all peers of the router. These IP
ranges will be advertised in addition to any specified groups.
Leave this field blank to advertise no custom IP ranges.

* `bgp/advertised_ip_ranges[]/range`
The IP range to advertise. The value must be a
CIDR-formatted string.

* `bgp/advertised_ip_ranges[]/description`
User-specified description for the IP range.

* `region` -
Required. Region where the router resides.

#### Label
Set the `r_label` property when attempting to set primary key
of this object. The primary key will always be referred to by the initials of
the resource followed by "_label"

### gcompute_snapshot
Represents a Persistent Disk Snapshot resource.

Expand Down
157 changes: 157 additions & 0 deletions libraries/google/compute/property/router_advertised_ip_ranges.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Copyright 2018 Google Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file in README.md and
# CONTRIBUTING.md located at the root of this package.
#
# ----------------------------------------------------------------------------

require 'google/compute/property/array'
module Google
module Compute
module Data
# A class to manage data for advertised_ip_ranges for router.
class RouteAdverIpRange
include Comparable

attr_reader :range
attr_reader :description

def to_json(_arg = nil)
{
'range' => range,
'description' => description
}.reject { |_k, v| v.nil? }.to_json
end

def to_s
{
range: range.to_s,
description: description.to_s
}.map { |k, v| "#{k}: #{v}" }.join(', ')
end

def ==(other)
return false unless other.is_a? RouteAdverIpRange
compare_fields(other).each do |compare|
next if compare[:self].nil? || compare[:other].nil?
return false if compare[:self] != compare[:other]
end
true
end

def <=>(other)
return false unless other.is_a? RouteAdverIpRange
compare_fields(other).each do |compare|
next if compare[:self].nil? || compare[:other].nil?
result = compare[:self] <=> compare[:other]
return result unless result.zero?
end
0
end

def inspect
to_json
end

private

def compare_fields(other)
[
{ self: range, other: other.range },
{ self: description, other: other.description }
]
end
end

# Manages a RouteAdverIpRange nested object
# Data is coming from the GCP API
class RouteAdverIpRangeApi < RouteAdverIpRange
def initialize(args)
@range = Google::Compute::Property::String.api_parse(args['range'])
@description =
Google::Compute::Property::String.api_parse(args['description'])
end
end

# Manages a RouteAdverIpRange nested object
# Data is coming from the Chef catalog
class RouteAdverIpRangeCatalog < RouteAdverIpRange
def initialize(args)
@range = Google::Compute::Property::String.catalog_parse(args[:range])
@description =
Google::Compute::Property::String.catalog_parse(args[:description])
end
end
end

module Property
# A class to manage input to advertised_ip_ranges for router.
class RouteAdverIpRange
def self.coerce
lambda do |x|
::Google::Compute::Property::RouteAdverIpRange.catalog_parse(x)
end
end

# Used for parsing Chef catalog
def self.catalog_parse(value)
return if value.nil?
return value if value.is_a? Data::RouteAdverIpRange
Data::RouteAdverIpRangeCatalog.new(value)
end

# Used for parsing GCP API responses
def self.api_parse(value)
return if value.nil?
return value if value.is_a? Data::RouteAdverIpRange
Data::RouteAdverIpRangeApi.new(value)
end
end

# A Chef property that holds an integer
class RouteAdverIpRangeArray < Google::Compute::Property::Array
def self.coerce
lambda do |x|
::Google::Compute::Property::RouteAdverIpRangeArray.catalog_parse(x)
end
end

# Used for parsing Chef catalog
def self.catalog_parse(value)
return if value.nil?
return RouteAdverIpRange.catalog_parse(value) \
unless value.is_a?(::Array)
value.map { |v| RouteAdverIpRange.catalog_parse(v) }
end

# Used for parsing GCP API responses
def self.api_parse(value)
return if value.nil?
return RouteAdverIpRange.api_parse(value) \
unless value.is_a?(::Array)
value.map { |v| RouteAdverIpRange.api_parse(v) }
end
end
end
end
end
Loading

0 comments on commit 7b08998

Please sign in to comment.