1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
module Fog
module AWS
class Compute
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'
attribute :map_public_ip_on_launch, :aliases => 'mapPublicIpOnLaunch'
attribute :default_for_az, :aliases => 'defaultForAz'
def ready?
requires :state
state == 'available'
end
def network_interfaces
service.network_interfaces.all('subnet-id' => [self.identity])
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 subnet 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['subnet']
new_attributes = data.reject {|key,value| key == 'requestId'}
merge_attributes(new_attributes)
true
true
end
end
end
end
end
|