Sha256: 698aa3e4c6fda5c0ec4f15dd8b3cd0d90ed3ac44d374725b9b59c25d7f1e6611

Contents?: true

Size: 1.88 KB

Versions: 11

Compression:

Stored size: 1.88 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'}
          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
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
fog-aws-0.1.1 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.1.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.0.8 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.0.7 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.0.6 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.0.5 lib/fog/aws/models/compute/vpc.rb
fog-1.26.0 lib/fog/aws/models/compute/vpc.rb
fog-1.25.0 lib/fog/aws/models/compute/vpc.rb
nsidc-fog-1.24.1 lib/fog/aws/models/compute/vpc.rb
fog-1.24.0 lib/fog/aws/models/compute/vpc.rb
fog-1.23.0 lib/fog/aws/models/compute/vpc.rb