Class: BuildCloud::Subnet
- Inherits:
-
Object
- Object
- BuildCloud::Subnet
- Includes:
- Component
- Defined in:
- lib/build-cloud/subnet.rb
Constant Summary collapse
- @@objects =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #create_tags(tags) ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ Subnet
constructor
A new instance of Subnet.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ Subnet
Returns a new instance of Subnet.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/build-cloud/subnet.rb', line 25 def initialize ( fog_interfaces, log, = {} ) @compute = fog_interfaces[:compute] @log = log @options = @log.debug( .inspect ) (:availability_zone, :cidr_block, :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/subnet.rb', line 7 def self.get_id_by_name( name ) subnet = self.search( :name => name ).first unless subnet raise "Couldn't get a Subnet object for #{name} - is it defined?" end subnet_fog = subnet.read unless subnet_fog raise "Couldn't get a Subnet fog object for #{name} - is it created?" end subnet_fog.subnet_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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/build-cloud/subnet.rb', line 38 def create = @options.dup if exists? # If exists update tags if [:tags] ([:tags]) end return end return if exists? @log.info( "Creating subnet for #{@options[:cidr_block]} ( #{[:name]} )" ) unless [:vpc_id] [:vpc_id] = BuildCloud::VPC.get_id_by_name( [:vpc_name] ) .delete(:vpc_name) end subnet = @compute.subnets.new( ) subnet.save if [:tag_set] [:tag_set].each do | tag | attributes = {} attributes[:resource_id] = subnet.subnet_id.to_s attributes[:key] = tag[:key] attributes[:value] = tag[:value] new_tag = @compute..new( attributes ) new_tag.save end unless [:tag_set].empty? or [:tag_set].nil? end @log.debug( subnet.inspect ) end |
#create_tags(tags) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/build-cloud/subnet.rb', line 97 def () # force symbols to strings in yaml tags = fog_object.tag_set.dup.merge(.collect{|k,v| [k.to_s, v]}.to_h) if != fog_object.tag_set @log.info("Updating tags for subnet #{fog_object.subnet_id.to_s}") @compute.( fog_object.subnet_id.to_s, ) end end |
#delete ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/build-cloud/subnet.rb', line 87 def delete return unless exists? @log.info( "Subnet #{@options[:name]}" ) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
81 82 83 |
# File 'lib/build-cloud/subnet.rb', line 81 def read @compute.subnets.select { |s| s.cidr_block == @options[:cidr_block] }.first end |