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

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

Instance Attribute Summary

Attributes inherited from Model

#collection, #service

Instance Method Summary collapse

Methods inherited from Model

#inspect, #reload, #symbolize_keys, #to_json, #wait_for

Methods included from Attributes::ClassMethods

#_load, #aliases, #attribute, #attributes, #identity, #ignore_attributes, #ignored_attributes

Methods included from Fog::Core::DeprecatedConnectionAccessors

#connection, #connection=, #prepare_service_value

Methods included from Attributes::InstanceMethods

#_dump, #attributes, #dup, #identity, #identity=, #merge_attributes, #new_record?, #persisted?, #requires, #requires_one

Constructor Details

#initialize(attributes = {}) ⇒ VPC

Returns a new instance of VPC.



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

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



32
33
34
35
36
37
# File 'lib/fog/aws/models/compute/vpc.rb', line 32

def destroy
  requires :id

  service.delete_vpc(id)
  true
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.



50
51
52
53
54
55
56
57
# File 'lib/fog/aws/models/compute/vpc.rb', line 50

def save
  requires :cidr_block

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