Class: BuildCloud::VPC
- Inherits:
-
Object
- Object
- BuildCloud::VPC
- Includes:
- Component
- Defined in:
- lib/build-cloud/vpc.rb
Constant Summary collapse
- @@objects =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #create ⇒ Object
- #create_tags(tags) ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ VPC
constructor
A new instance of VPC.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ VPC
Returns a new instance of VPC.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/build-cloud/vpc.rb', line 25 def initialize ( fog_interfaces, log, = {} ) @compute = fog_interfaces[:compute] @log = log @options = @log.debug( .inspect ) (:cidr_block) 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/vpc.rb', line 7 def self.get_id_by_name( name ) vpc = self.search( :name => name ).first unless vpc raise "Couldn't get a VPC object for #{name} - is it defined?" end vpc_fog = vpc.read unless vpc_fog raise "Couldn't get a VPC fog object for #{name} - is it created?" end vpc_fog.id end |
Instance Method Details
#[](key) ⇒ Object
91 92 93 |
# File 'lib/build-cloud/vpc.rb', line 91 def [](key) @options[key] end |
#create ⇒ Object
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 67 68 69 70 71 72 73 |
# File 'lib/build-cloud/vpc.rb', line 37 def create = @options.dup tag_name = .delete(:name) if ![:tags] [:tags] = { 'Name' => tag_name } end if exists? # If exists update tags ([:tags]) return end @log.info( "Creating new VPC for #{[:cidr_block]}" ) vpc = @compute.vpcs.new( ) vpc.save () wait_until_ready if [:dhcp_options_set_name] dhcp_option_set_id = BuildCloud::DHCPOptionsSet.get_id_by_name( [:dhcp_options_set_name] ) @log.info( "Associating DHCP Options Set #{dhcp_option_set_id} with new VPC ID #{vpc.id}" ) @compute.( dhcp_option_set_id, vpc.id ) end @log.debug( vpc.inspect ) @compute.modify_vpc_attribute( vpc.id, { 'EnableDnsHostnames.Value' => true } ) end |
#create_tags(tags) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/build-cloud/vpc.rb', line 95 def () # force symbols to strings in yaml tags = fog_object..dup.merge(.collect{|k,v| [k.to_s, v]}.to_h) if != fog_object. @log.info("Updating tags for VPC #{fog_object.id}") @compute.( fog_object.id, ) end end |
#delete ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/build-cloud/vpc.rb', line 81 def delete return unless exists? @log.info( "Deleting VPC for #{@options[:cidr_block]}" ) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
75 76 77 |
# File 'lib/build-cloud/vpc.rb', line 75 def read @compute.vpcs.select { |v| v.cidr_block == @options[:cidr_block] }.first end |