Sha256: 0576b7179a02216e9bef5f110edaadc6e7f4f184784568502c066f969ac9afb9

Contents?: true

Size: 1.6 KB

Versions: 14

Compression:

Stored size: 1.6 KB

Contents

require 'fog/core/model'

module Fog
  module Compute
    class AWS

      class Subnet < Fog::Model

        identity  :subnet_id,                   :aliases => 'subnetId'
        attribute :state
        attribute :vpc_id,                      :aliases => 'vpcId'
        attribute :cidr_block,                  :aliases => 'cidrBlock'
        attribute :available_ip_address_count,  :aliases => 'availableIpAddressCount'
        attribute :availability_zone,           :aliases => 'availabilityZone'
        attribute :tag_set,                     :aliases => 'tagSet'

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

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

        def destroy
          requires :subnet_id

          service.delete_subnet(subnet_id)
          true
        end

        # Create a subnet
        #
        #  >> g = AWS.subnets.new(:vpc_id => "vpc-someId", :cidr_block => "10.0.0.0/24")
        #  >> g.save
        #
        # == Returns:
        #
        # requestId and a subnetSet object
        #

        def save
          requires :vpc_id, :cidr_block
          options = {}
          options['AvailabilityZone'] = availability_zone if availability_zone
          data = service.create_subnet(vpc_id, cidr_block, options).body['subnetSet'].first
          new_attributes = data.reject {|key,value| key == 'requestId'}
          merge_attributes(new_attributes)
          true

          true
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
fog-maestrodev-1.19.0.20140212012611 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.19.0.20140110004459 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.19.0.20140110003812 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.19.0.20140109202555 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.19.0.20140107192102 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.19.0.20140107142106 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.19.0.20131219203941 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.18.0.20131219193542 lib/fog/aws/models/compute/subnet.rb
fog-1.19.0 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.18.0.20131219033443 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.18.0.20131219032002 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.18.0.20131219030716 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.18.0.20131219022322 lib/fog/aws/models/compute/subnet.rb
fog-maestrodev-1.18.0.20131218202447 lib/fog/aws/models/compute/subnet.rb