You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::EC2::VPC

Inherits:
Resource
  • Object
show all
Includes:
TaggedItem
Defined in:
lib/aws/ec2/vpc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from TaggedItem

#add_tag, #clear_tags, #tags

Constructor Details

#initialize(vpc_id, options = {}) ⇒ VPC

Returns a new instance of VPC



25
26
27
28
# File 'lib/aws/ec2/vpc.rb', line 25

def initialize vpc_id, options = {}
  @vpc_id = vpc_id
  super
end

Instance Attribute Details

#cidr_blockString (readonly)

Returns the current value of cidr_block

Returns:

  • (String)

    the current value of cidr_block



21
22
23
# File 'lib/aws/ec2/vpc.rb', line 21

def cidr_block
  @cidr_block
end

#dhcp_options_idString (readonly)

Returns the current value of dhcp_options_id

Returns:

  • (String)

    the current value of dhcp_options_id



21
22
23
# File 'lib/aws/ec2/vpc.rb', line 21

def dhcp_options_id
  @dhcp_options_id
end

#instance_tenancySymbol (readonly)

Returns the current value of instance_tenancy

Returns:

  • (Symbol)

    the current value of instance_tenancy



21
22
23
# File 'lib/aws/ec2/vpc.rb', line 21

def instance_tenancy
  @instance_tenancy
end

#stateSymbol (readonly)

Returns the current value of state

Returns:

  • (Symbol)

    the current value of state



21
22
23
# File 'lib/aws/ec2/vpc.rb', line 21

def state
  @state
end

#vpc_idString (readonly) Also known as: id

Returns:

  • (String)


31
32
33
# File 'lib/aws/ec2/vpc.rb', line 31

def vpc_id
  @vpc_id
end

Instance Method Details

#deletenil

Deletes the current VPC. The VPC must be empty before it can be deleted.

Returns:

  • (nil)


64
65
66
67
# File 'lib/aws/ec2/vpc.rb', line 64

def delete
  client.delete_vpc(:vpc_id => vpc_id)
  nil
end

#dhcp_optionsDHCPOptions

Returns the dhcp options associated with this VPC.

Returns:

  • (DHCPOptions)

    Returns the dhcp options associated with this VPC.



151
152
153
# File 'lib/aws/ec2/vpc.rb', line 151

def dhcp_options
  DHCPOptions.new(dhcp_options_id, :config => config)
end

#dhcp_options=(dhcp_options) ⇒ Object

Associates the given dhcp options with this VPC.

vpc.dhcp_optinos = ec2.dhcp_options['dopt-a1234abc']

You can also specify the string 'default' to use Amazon's default dhcp options.

vpc.dhcp_optinos = 'default'

Parameters:



167
168
169
170
171
172
# File 'lib/aws/ec2/vpc.rb', line 167

def dhcp_options= dhcp_options
  unless dhcp_options.is_a?(DHCPOptions)
    dhcp_options = DHCPOptions.new(dhcp_options, :config => config)
  end
  dhcp_options.associate(self)
end

#exists?Boolean

Returns true if the resource exists.

Returns:

  • (Boolean)

    Returns true if the resource exists.



54
55
56
57
58
59
# File 'lib/aws/ec2/vpc.rb', line 54

def exists?
  get_resource
  true
rescue Errors::InvalidVpcID::NotFound
  false
end

#instancesInstanceCollection

Returns a filtered collection of instances that are in this VPC.

Returns:

  • (InstanceCollection)

    Returns a filtered collection of instances that are in this VPC.



71
72
73
# File 'lib/aws/ec2/vpc.rb', line 71

def instances
  InstanceCollection.new(:config => config).filter('vpc-id', vpc_id)
end

#internet_gatewayInternetGateway?

Returns the internet gateway attached to this VPC. If no internet gateway has been attached, then nil is returned.

Returns:

  • (InternetGateway, nil)

    Returns the internet gateway attached to this VPC. If no internet gateway has been attached, then nil is returned.



108
109
110
111
# File 'lib/aws/ec2/vpc.rb', line 108

def internet_gateway
  gateways = InternetGatewayCollection.new(:config => config)
  gateways.filter('attachment.vpc-id', vpc_id).first
end

#internet_gateway=(internet_gateway) ⇒ Object

Attaches the given internet gateway to this VPC. If there is already an internet gateway attached, it will be detached from this VPC first. If you pass nil, this will leave the current VPC without an attached internet gateway.

vpc.internet_gateway = gateway_1 vpc.internet_gateway = gateway_2 # detaches gateway_1 first vpc.internet_gateway = nil # detaches gateway_2

Parameters:



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/aws/ec2/vpc.rb', line 125

def internet_gateway= internet_gateway

  # remove currently attached internet gateway
  gateway = self.internet_gateway
  gateway.detach(self) if gateway

  if internet_gateway
    unless internet_gateway.is_a?(InternetGateway)
      internet_gateway = InternetGateway.new(internet_gateway,
        :config => config)
    end
    internet_gateway.attach(self)
  end

end

#network_aclsNetworkACLCollection

Returns a filtered collection of network ACLs that are in this VPC.

Returns:



89
90
91
# File 'lib/aws/ec2/vpc.rb', line 89

def network_acls
  NetworkACLCollection.new(:config => config).filter('vpc-id', vpc_id)
end

#network_interfacesNetworkInterfaceCollection

Returns a filtered collection of network interfaces that are in this VPC.

Returns:



101
102
103
# File 'lib/aws/ec2/vpc.rb', line 101

def network_interfaces
  NetworkInterfaceCollection.new(:config => config).filter('vpc-id', id)
end

#route_tablesRouteTableCollection

Returns a filtered collection of route tables that are in this VPC.

Returns:



95
96
97
# File 'lib/aws/ec2/vpc.rb', line 95

def route_tables
  RouteTableCollection.new(:config => config).filter('vpc-id', vpc_id)
end

#security_groupsSecurityGroupCollection

Returns a filtered collection of security groups that are in this VPC.

Returns:



77
78
79
# File 'lib/aws/ec2/vpc.rb', line 77

def security_groups
  SecurityGroupCollection.new(:config => config).filter('vpc-id', vpc_id)
end

#subnetsSubnetCollection

Returns a filtered collection of subnets that are in this VPC.

Returns:

  • (SubnetCollection)

    Returns a filtered collection of subnets that are in this VPC.



83
84
85
# File 'lib/aws/ec2/vpc.rb', line 83

def subnets
  SubnetCollection.new(:config => config).filter('vpc-id', vpc_id)
end

#vpn_gatewayVPNGateway?

Returns the vpn gateway attached to this VPC. If no vpn gateway has been attached, then nil is returned.

Returns:

  • (VPNGateway, nil)

    Returns the vpn gateway attached to this VPC. If no vpn gateway has been attached, then nil is returned.



144
145
146
147
# File 'lib/aws/ec2/vpc.rb', line 144

def vpn_gateway
  gateways = VPNGatewayCollection.new(:config => config)
  gateways.filter('attachment.vpc-id', vpc_id).first
end