Class: BuildCloud::RouteTable
- Inherits:
-
Object
- Object
- BuildCloud::RouteTable
- Includes:
- Component
- Defined in:
- lib/build-cloud/routetable.rb
Constant Summary collapse
- @@objects =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ RouteTable
constructor
A new instance of RouteTable.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ RouteTable
Returns a new instance of RouteTable.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/build-cloud/routetable.rb', line 25 def initialize ( fog_interfaces, log, = {} ) @compute = fog_interfaces[:compute] @log = log @options = @log.debug( .inspect ) (:name) require_one_of(:vpc_id, :vpc_name) require_one_of(:subnet_ids, :subnet_names) end |
Class Method Details
.get_id_by_name(name) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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.route_table_id end |
Instance Method Details
#create ⇒ Object
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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/build-cloud/routetable.rb', line 40 def create return if exists? @log.info("Creating route table #{@options[:name]}") = @options.dup unless [:subnet_ids] [:subnet_ids] = [] [:subnet_names].each do |sn| [:subnet_ids] << BuildCloud::Subnet.get_id_by_name( sn ) end .delete(:subnet_names) end unless [:vpc_id] [:vpc_id] = BuildCloud::VPC.get_id_by_name( [:vpc_name] ) .delete(:vpc_name) end [:tags] = { 'Name' => .delete(:name) } # Using requests instead of model here, because the model # doesn't support associations. rt = @compute.route_tables.new ( ) rt.save @log.debug(rt.inspect) @compute.( rt.id, [:tags] ) [:subnet_ids].each do |s| @compute.associate_route_table( rt.id, s ) end end |
#delete ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/build-cloud/routetable.rb', line 90 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 |
#read ⇒ Object Also known as: fog_object
84 85 86 |
# File 'lib/build-cloud/routetable.rb', line 84 def read @compute.route_tables.select { |r| r.['Name'] == @options[:name] }.first end |