Class: BuildCloud::Route
- Inherits:
-
Object
- Object
- BuildCloud::Route
- Includes:
- Component
- Defined in:
- lib/build-cloud/route.rb
Constant Summary collapse
- @@objects =
[]
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ Route
constructor
A new instance of Route.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ Route
Returns a new instance of Route.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/build-cloud/route.rb', line 7 def initialize ( fog_interfaces, log, = {} ) @compute = fog_interfaces[:compute] @log = log @options = @log.debug( .inspect ) (:name, :route_table_name, :destination_cidr_block) require_one_of(:internet_gateway_name, :network_interface_name, :internet_gateway_id, :network_interface_id) require_one_of(:route_table_id, :route_table_name) end |
Instance Method Details
#create ⇒ Object
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 65 66 |
# File 'lib/build-cloud/route.rb', line 21 def create return if exists? @log.info("Creating route #{@options[:name]}") = @options.dup [:tags] = { 'Name' => .delete(:name) } unless [:network_interface_name].nil? [:network_interface_id] = BuildCloud::NetworkInterface.get_id_by_name( [:network_interface_name] ) .delete(:network_interface_name) end if [:internet_gateway_name] [:internet_gateway_id] = BuildCloud::InternetGateway.get_id_by_name( [:internet_gateway_name] ) .delete(:internet_gateway_name) end if [:route_table_name] [:route_table_id] = BuildCloud::RouteTable.get_id_by_name( [:route_table_name] ) .delete(:route_table_name) end route_table_id = [:route_table_id] destination_cidr_block = [:destination_cidr_block] internet_gateway_id = [:internet_gateway_id] network_interface_id = [:network_interface_id] ||= nil # Using requests instead of model here, because the model # doesn't support associations. begin if @compute.create_route(route_table_id, destination_cidr_block, internet_gateway_id, nil, network_interface_id) @log.debug("route created successfully") else @log.debug("failed to create route") end rescue Exception => e @log.error( "An exception - #{e} - occured") end end |
#delete ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/build-cloud/route.rb', line 78 def delete return unless exists? = @options.dup @log.info("Deleting route #{[:name]}") unless [:route_table_name].nil? [:route_table_id] = BuildCloud::RouteTable.get_id_by_name( [:route_table_name] ) .delete(:route_table_name) end route_table_id = [:route_table_id] destination_cidr_block = [:destination_cidr_block] begin if @compute.delete_route(route_table_id, destination_cidr_block) @log.debug("route deleted successfully") else @log.debug("failed to delet route") end rescue Exception => e @log.error( "An exception - #{e} - occured") end end |
#read ⇒ Object Also known as: fog_object
68 69 70 71 72 73 74 |
# File 'lib/build-cloud/route.rb', line 68 def read rt = @compute.route_tables.select { |rt| rt.['Name'] == @options[:name] }.first @log.debug( rt.inspect ) route = rt.routes.select { |t| t['destinationCidrBlock'] == @options[:destination_cidr_block]}.first unless rt.nil? @log.debug( route.inspect ) return true unless route.nil? end |