Class: BuildCloud::InternetGateway
- Inherits:
-
Object
- Object
- BuildCloud::InternetGateway
- Includes:
- Component
- Defined in:
- lib/build-cloud/internetgateway.rb
Constant Summary collapse
- @@objects =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ InternetGateway
constructor
A new instance of InternetGateway.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ InternetGateway
Returns a new instance of InternetGateway.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/build-cloud/internetgateway.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) 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/internetgateway.rb', line 7 def self.get_id_by_name( name ) internet_gateway = self.search( :name => name ).first unless internet_gateway raise "Couldn't get an InternetGateway object for #{name} - is it defined?" end internet_gateway_fog = internet_gateway.read unless internet_gateway_fog raise "Couldn't get an InternetGateway fog object for #{name} - is it created?" end internet_gateway_fog.id end |
Instance Method Details
#create ⇒ Object
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 |
# File 'lib/build-cloud/internetgateway.rb', line 38 def create return if exists? @log.info("Creating Internet Gateway #{@options[:name]}") = @options.dup unless [:vpc_id] [:vpc_id] = BuildCloud::VPC.get_id_by_name( [:vpc_name] ) .delete(:vpc_name) end [:tags] = { 'Name' => .delete(:name) } ig = @compute.internet_gateways.new() ig.save @log.debug(ig.inspect) @compute.( ig.id, [:tags] ) ig.attach([:vpc_id]) end |
#delete ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/build-cloud/internetgateway.rb', line 72 def delete return unless exists? @log.info("Deleting Internet Gateway #{@options[:name]}") read.detach(read.['vpcId']) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
66 67 68 |
# File 'lib/build-cloud/internetgateway.rb', line 66 def read @compute.internet_gateways.select { |r| r.tag_set['Name'] == @options[:name] }.first end |