class AWS::EC2::VPC

@attr_reader [Symbol] state @attr_reader [String] cidr_block @attr_reader [String] dhcp_options_id @attr_reader [Symbol] instance_tenancy

Attributes

id[R]

@return [String]

vpc_id[R]

@return [String]

Public Class Methods

new(vpc_id, options = {}) click to toggle source
Calls superclass method AWS::Core::Resource::new
# File lib/aws/ec2/vpc.rb, line 25
def initialize vpc_id, options = {}
  @vpc_id = vpc_id
  super
end

Public Instance Methods

delete() click to toggle source

Deletes the current VPC. The VPC must be empty before it can be deleted. @return [nil]

# File lib/aws/ec2/vpc.rb, line 64
def delete
  client.delete_vpc(:vpc_id => vpc_id)
  nil
end
dhcp_options() click to toggle source

@return [DHCPOptions] Returns the dhcp options associated with

this VPC.
# File lib/aws/ec2/vpc.rb, line 163
def dhcp_options
  DHCPOptions.new(dhcp_options_id, :config => config)
end
dhcp_options=(dhcp_options) click to toggle source

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'

@param [DHCPOptions,String] dhcp_options A {DHCPOptions} object

or a dhcp options id string.
# File lib/aws/ec2/vpc.rb, line 179
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
dns_hostnames() click to toggle source

@return [Boolean] Returns true if instances launched in the VPC get

DNS hostnames in this VPC
# File lib/aws/ec2/vpc.rb, line 211
def dns_hostnames
  resp = client.describe_vpc_attribute(:vpc_id => vpc_id, :attribute => 'enableDnsHostnames')
  resp.enable_dns_hostnames
end
dns_hostnames=(enable_dns_hostnames) click to toggle source

Enables DNS hostnames for this VPC

# File lib/aws/ec2/vpc.rb, line 217
def dns_hostnames= enable_dns_hostnames
  client.modify_vpc_attribute(:vpc_id => vpc_id, :enable_dns_hostnames => { :value => enable_dns_hostnames } )
  enable_dns_hostnames
end
dns_support() click to toggle source

@return [Boolean] Returns true if DNS resolution is supported for

this VPC
# File lib/aws/ec2/vpc.rb, line 198
def dns_support
  resp = client.describe_vpc_attribute(:vpc_id => vpc_id, :attribute => 'enableDnsSupport')
  resp.enable_dns_support
end
dns_support=(enable_dns_support) click to toggle source

Enables DNS resolution support for this VPC

# File lib/aws/ec2/vpc.rb, line 204
def dns_support= enable_dns_support
  client.modify_vpc_attribute(:vpc_id => vpc_id, :enable_dns_support => { :value => enable_dns_support } )
  enable_dns_support
end
exists?() click to toggle source

@return [Boolean] Returns `true` if the resource exists.

# File lib/aws/ec2/vpc.rb, line 54
def exists?
  get_resource
  true
rescue Errors::InvalidVpcID::NotFound
  false
end
instances() click to toggle source

@return [InstanceCollection] Returns a filtered collection of

instances that are in this VPC.
# File lib/aws/ec2/vpc.rb, line 71
def instances
  InstanceCollection.new(:config => config).filter('vpc-id', vpc_id)
end
internet_gateway() click to toggle source

@return [InternetGateway,nil] Returns the internet gateway attached to

this VPC.  If no internet gateway has been attached, then
nil is returned.
# File lib/aws/ec2/vpc.rb, line 120
def internet_gateway
  gateways = InternetGatewayCollection.new(:config => config)
  gateways.filter('attachment.vpc-id', vpc_id).first
end
internet_gateway=(internet_gateway) click to toggle source

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

@param [InternetGateway,String] internet_gateway An {InternetGateway}

object or internet gateway id string.
# File lib/aws/ec2/vpc.rb, line 137
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_acls() click to toggle source

@return [NetworkACLCollection] Returns a filtered collection of

network ACLs that are in this VPC.
# File lib/aws/ec2/vpc.rb, line 89
def network_acls
  NetworkACLCollection.new(:config => config).filter('vpc-id', vpc_id)
end
network_interfaces() click to toggle source

@return [NetworkInterfaceCollection] Returns a filtered collection of

network interfaces that are in this VPC.
# File lib/aws/ec2/vpc.rb, line 101
def network_interfaces
  NetworkInterfaceCollection.new(:config => config).filter('vpc-id', id)
end
peer_to(vpc) click to toggle source

Create a VPC peering connection between this VPC and another

VPC owned by the same user, and accept it.

@return [VPCPeeringConnection] Returns the VPC peering connection

that was created
# File lib/aws/ec2/vpc.rb, line 190
def peer_to vpc
  peering_connection = peering_connections.create(self, vpc)
  peering_connection.accept
  peering_connection
end
peering_connections() click to toggle source

@return [VPCPeeringConnectionCollection] Returns a filtered collection

of VPC peering connection from this VPC.
# File lib/aws/ec2/vpc.rb, line 107
def peering_connections
  VPCPeeringConnectionCollection.new(:config => config).filter('requester-vpc-info.vpc-id', vpc_id)
end
route_tables() click to toggle source

@return [RouteTableCollection] Returns a filtered collection of

route tables that are in this VPC.
# File lib/aws/ec2/vpc.rb, line 95
def route_tables
  RouteTableCollection.new(:config => config).filter('vpc-id', vpc_id)
end
security_groups() click to toggle source

@return [SecurityGroupCollection] Returns a filtered collection of

security groups that are in this VPC.
# File lib/aws/ec2/vpc.rb, line 77
def security_groups
  SecurityGroupCollection.new(:config => config).filter('vpc-id', vpc_id)
end
subnets() click to toggle source

@return [SubnetCollection] Returns a filtered collection of

subnets that are in this VPC.
# File lib/aws/ec2/vpc.rb, line 83
def subnets
  SubnetCollection.new(:config => config).filter('vpc-id', vpc_id)
end
vpn_gateway() click to toggle source

@return [VPNGateway,nil] Returns the vpn gateway attached to

this VPC.  If no vpn gateway has been attached, then
nil is returned.
# File lib/aws/ec2/vpc.rb, line 156
def vpn_gateway
  gateways = VPNGatewayCollection.new(:config => config)
  gateways.filter('attachment.vpc-id', vpc_id).first
end