Sha256: 26bbdfec1537b5bc31358cc4b087c72a9915001228a63f7c7e74052ef66fc6ed

Contents?: true

Size: 1.86 KB

Versions: 23

Compression:

Stored size: 1.86 KB

Contents

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

23 entries across 23 versions & 2 rubygems

Version Path
fog-aws-0.11.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.10.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.9.4 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.9.3 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.9.2 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.9.1 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.9.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.8.1 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.8.0 lib/fog/aws/models/compute/vpc.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/fog-aws-0.7.5/lib/fog/aws/models/compute/vpc.rb
fog-aws-0.7.6 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.7.5 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.7.4 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.7.3 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.7.2 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.6.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.5.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.4.1 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.4.0 lib/fog/aws/models/compute/vpc.rb
fog-aws-0.3.0 lib/fog/aws/models/compute/vpc.rb