Class: Fog::Compute::AWS::VPC

Inherits:
Model
  • Object
show all
Defined in:
lib/fog/aws/models/compute/vpc.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ VPC

Returns a new instance of VPC.



18
19
20
21
22
# File 'lib/fog/aws/models/compute/vpc.rb', line 18

def initialize(attributes={})
  self.dhcp_options_id ||= "default"
  self.tenancy ||= "default"
  super
end

Instance Method Details

#destroyObject

Removes an existing vpc

vpc.destroy

Returns

True or false depending on the result



43
44
45
46
47
48
# File 'lib/fog/aws/models/compute/vpc.rb', line 43

def destroy
  requires :id

  service.delete_vpc(id)
  true
end

#is_default?Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/fog/aws/models/compute/vpc.rb', line 29

def is_default?
  require :is_default
  is_default
end

#ready?Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/fog/aws/models/compute/vpc.rb', line 24

def ready?
  requires :state
  state == 'available'
end

#saveObject

Create a vpc

>> g = AWS.vpcs.new(:cidr_block => “10.1.2.0/24”) >> g.save

Returns:

True or an exception depending on the result. Keep in mind that this creates a new vpc. As such, it yields an InvalidGroup.Duplicate exception if you attempt to save an existing vpc.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fog/aws/models/compute/vpc.rb', line 61

def save
  requires :cidr_block

  data = service.create_vpc(cidr_block).body['vpcSet'].first
  new_attributes = data.reject {|key,value| key == 'requestId'}
  new_attributes = data.reject {|key,value| key == 'requestId' || key == 'tagSet' }
  merge_attributes(new_attributes)

  if tags = self.tags
    # expect eventual consistency
    Fog.wait_for { self.reload rescue nil }
    service.create_tags(
      self.identity,
      tags
    )
  end

  true
end

#subnetsObject



14
15
16
# File 'lib/fog/aws/models/compute/vpc.rb', line 14

def subnets
  service.subnets(:filters => {'vpcId' => self.identity}).all
end