class BuildCloud::RouteTable

Public Class Methods

get_id_by_name( name ) click to toggle source
# File lib/build-cloud/routetable.rb, line 7
def self.get_id_by_name( name )

    route_table = self.search( :name => name ).first

    unless route_table
        raise "Couldn't get a RouteTable object for #{name} - is it defined?"
    end

    route_table_fog = route_table.read

    unless route_table_fog
        raise "Couldn't get a RouteTable fog object for #{name} - is it created?"
    end

    route_table_fog.id

end
new( fog_interfaces, log, options = {} ) click to toggle source
# File lib/build-cloud/routetable.rb, line 25
def initialize ( fog_interfaces, log, options = {} )

    @compute = fog_interfaces[:compute]
    @log     = log
    @options = options

    @log.debug( options.inspect )

    required_options(:name)
    require_one_of(:vpc_id, :vpc_name)
    require_one_of(:subnet_ids, :subnet_names)


end

Public Instance Methods

create() click to toggle source
# File lib/build-cloud/routetable.rb, line 40
def create

    return if exists?

    @log.info("Creating route table #{@options[:name]}")

    options = @options.dup

    unless options[:subnet_ids]

        options[:subnet_ids] = []

        options[:subnet_names].each do |sn|
            options[:subnet_ids] << BuildCloud::Subnet.get_id_by_name( sn )
        end

        options.delete(:subnet_names)

    end

    unless options[:vpc_id]

        options[:vpc_id] = BuildCloud::VPC.get_id_by_name( options[:vpc_name] )
        options.delete(:vpc_name)

    end

    options[:tags] = { 'Name' => options.delete(:name) }

    # Using requests instead of model here, because the model
    #  doesn't support associations.
 
    rt = @compute.route_tables.new ( options )
    rt.save
    @log.debug(rt.inspect)

    ### sometimes tag creation will fail unless we wait until the API catches up:
    wait_until_ready

    @compute.create_tags( rt.id, options[:tags] )
   
    options[:subnet_ids].each do |s|
        @compute.associate_route_table( rt.id, s )
    end

end
delete() click to toggle source
# File lib/build-cloud/routetable.rb, line 93
def delete

    return unless exists?

    @log.info("Deleting route table #{@options[:name]}")

    read.associations.each do |ra|
        @compute.disassociate_route_table( ra['routeTableAssociationId'] )
    end

    fog_object.destroy

end
fog_object()
Alias for: read
read() click to toggle source
# File lib/build-cloud/routetable.rb, line 87
def read
    @compute.route_tables.select { |r| r.tags['Name'] == @options[:name] }.first
end
Also aliased as: fog_object