Sha256: 2fdc85686011752bca4fdb0f142157a68e80a8e3df53844dff717adbf3065f06

Contents?: true

Size: 1.57 KB

Versions: 19

Compression:

Stored size: 1.57 KB

Contents

require 'fog/core/model'

module Fog
  module Compute
    class AWS

      class VPC < Fog::Model

        identity :id,                :aliases => 'vpcId'

        attribute :state
        attribute :cidr_block,       :aliases => 'cidrBlock'
        attribute :dhcp_options_id,  :aliases => 'dhcpOptionsId'
        attribute :tags,             :aliases => 'tagSet'
        attribute :tenancy,          :aliases => 'instanceTenancy'

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

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

        # Removes an existing vpc
        #
        # vpc.destroy
        #
        # ==== Returns
        #
        # True or false depending on the result
        #

        def destroy
          requires :id

          service.delete_vpc(id)
          true
        end

        # 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.
        #

        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

      end

    end
  end
end

Version data entries

19 entries across 19 versions & 2 rubygems

Version Path
fog-1.22.0 lib/fog/aws/models/compute/vpc.rb
fog-1.21.0 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.20.0.20140305101839 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.20.0.20140305101305 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20140212012611 lib/fog/aws/models/compute/vpc.rb
fog-1.20.0 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/aws/models/compute/vpc.rb
fog-1.19.0 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/aws/models/compute/vpc.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/aws/models/compute/vpc.rb