Skip to content

Commit

Permalink
Merge pull request #402 from engineyard/rz-subnet-default-for-az
Browse files Browse the repository at this point in the history
Add `default_for_az` attribute to subnet
  • Loading branch information
lanej authored Oct 18, 2017
2 parents 298a99d + d689de6 commit b8d9366
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions lib/fog/aws/models/compute/subnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Subnet < Fog::Model
attribute :availability_zone, :aliases => 'availabilityZone'
attribute :tag_set, :aliases => 'tagSet'
attribute :map_public_ip_on_launch, :aliases => 'mapPublicIpOnLaunch'
attribute :default_for_az, :aliases => 'defaultForAz'

def ready?
requires :state
Expand Down
2 changes: 2 additions & 0 deletions lib/fog/aws/parsers/compute/create_subnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def end_element(name)
case name
when 'subnetId', 'state', 'vpcId', 'cidrBlock', 'availableIpAddressCount', 'availabilityZone'
@subnet[name] = value
when 'mapPublicIpOnLaunch', 'defaultForAz'
@subnet[name] = value == 'true' ? true : false
when 'subnet'
@response['subnet'] = @subnet
when 'requestId'
Expand Down
2 changes: 1 addition & 1 deletion lib/fog/aws/parsers/compute/describe_subnets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def end_element(name)
case name
when 'subnetId', 'state', 'vpcId', 'cidrBlock', 'availableIpAddressCount', 'availabilityZone'
@subnet[name] = value
when 'mapPublicIpOnLaunch'
when 'mapPublicIpOnLaunch', 'defaultForAz'
@subnet[name] = value == 'true' ? true : false
when 'item'
@response['subnetSet'] << @subnet
Expand Down
24 changes: 14 additions & 10 deletions lib/fog/aws/requests/compute/create_subnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@ class Real
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'subnet'<~Array>:
# * 'subnetId'<~String> - The Subnet's ID
# * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
# * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
# * 'AvailableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any stopped
# instances are considered unavailable)
# * 'AvailabilityZone'<~String> - The Availability Zone the subnet is in
# * 'tagSet'<~Array>: Tags assigned to the resource.
# * 'key'<~String> - Tag's key
# * 'value'<~String> - Tag's value
# * 'subnetId'<~String> - The Subnet's ID
# * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
# * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
# * 'availableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any stopped
# instances are considered unavailable)
# * 'availabilityZone'<~String> - The Availability Zone the subnet is in
# * 'tagSet'<~Array>: Tags assigned to the resource.
# * 'key'<~String> - Tag's key
# * 'value'<~String> - Tag's value
# * 'mapPublicIpOnLaunch'<~Boolean> - Indicates whether instances launched in this subnet receive a public IPv4 address.
# * 'defaultForAz'<~Boolean> - Indicates whether this is the default subnet for the Availability Zone.
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/ApiReference-query-CreateSubnet.html]
def create_subnet(vpcId, cidrBlock, options = {})
Expand Down Expand Up @@ -65,7 +67,9 @@ def create_subnet(vpcId, cidrBlock, options = {})
'cidrBlock' => cidrBlock,
'availableIpAddressCount' => "255",
'availabilityZone' => av_zone,
'tagSet' => {}
'tagSet' => {},
'mapPublicIpOnLaunch' => true,
'defaultForAz' => true
}

# Add this subnet to the default network ACL
Expand Down
23 changes: 12 additions & 11 deletions lib/fog/aws/requests/compute/describe_subnets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ class Real
# * body<~Hash>:
# * 'requestId'<~String> - Id of request
# * 'subnetSet'<~Array>:
# * 'subnetId'<~String> - The Subnet's ID
# * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
# * 'vpcId'<~String> - The ID of the VPC the subnet is in
# * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
# * 'availableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any
# stopped instances are considered unavailable)
# * 'availabilityZone'<~String> - The Availability Zone the subnet is in.
# * 'tagSet'<~Array>: Tags assigned to the resource.
# * 'key'<~String> - Tag's key
# * 'value'<~String> - Tag's value
# * 'instanceTenancy'<~String> - The allowed tenancy of instances launched into the Subnet.
# * 'subnetId'<~String> - The Subnet's ID
# * 'state'<~String> - The current state of the Subnet. ['pending', 'available']
# * 'vpcId'<~String> - The ID of the VPC the subnet is in
# * 'cidrBlock'<~String> - The CIDR block the Subnet covers.
# * 'availableIpAddressCount'<~Integer> - The number of unused IP addresses in the subnet (the IP addresses for any
# stopped instances are considered unavailable)
# * 'availabilityZone'<~String> - The Availability Zone the subnet is in.
# * 'tagSet'<~Array>: Tags assigned to the resource.
# * 'key'<~String> - Tag's key
# * 'value'<~String> - Tag's value
# * 'mapPublicIpOnLaunch'<~Boolean> - Indicates whether instances launched in this subnet receive a public IPv4 address.
# * 'defaultForAz'<~Boolean> - Indicates whether this is the default subnet for the Availability Zone.
#
# {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/2011-07-15/APIReference/index.html?ApiReference-query-DescribeSubnets.html]
def describe_subnets(filters = {})
Expand Down
4 changes: 3 additions & 1 deletion tests/requests/compute/subnet_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
'availableIpAddressCount' => String,
'availabilityZone' => String,
'tagSet' => Hash,
'mapPublicIpOnLaunch' => Fog::Boolean,
'defaultForAz' => Fog::Boolean,
}

@single_subnet_format = {
Expand All @@ -24,7 +26,7 @@
'requestId' => String,
'return' => Fog::Boolean
}

@vpc_network = '10.0.10.0/24'
@vpc=Fog::Compute[:aws].vpcs.create('cidr_block' => @vpc_network)
@vpc_id = @vpc.id
Expand Down

0 comments on commit b8d9366

Please sign in to comment.