Class: BuildCloud::SecurityGroup
- Inherits:
-
Object
- Object
- BuildCloud::SecurityGroup
- Includes:
- Component
- Defined in:
- lib/build-cloud/securitygroup.rb
Constant Summary collapse
- @@objects =
[]
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
- #delete ⇒ Object
-
#initialize(fog_interfaces, log, options = {}) ⇒ SecurityGroup
constructor
A new instance of SecurityGroup.
- #read ⇒ Object (also: #fog_object)
Methods included from Component
Constructor Details
#initialize(fog_interfaces, log, options = {}) ⇒ SecurityGroup
Returns a new instance of SecurityGroup.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/build-cloud/securitygroup.rb', line 25 def initialize ( fog_interfaces, log, = {} ) @compute = fog_interfaces[:compute] @log = log @options = @log.debug( .inspect ) (:name, :description) 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/securitygroup.rb', line 7 def self.get_id_by_name( name ) sg = self.search( :name => name ).first unless sg raise "Couldn't get a SecurityGroup object for #{name} - is it defined?" end sg_fog = sg.read unless sg_fog raise "Couldn't get a SecurityGroup fog object for #{name} - is it created?" end sg_fog.group_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 |
# File 'lib/build-cloud/securitygroup.rb', line 38 def create return if exists? @log.info( "Creating security group #{@options[:name]}" ) = @options.dup unless [:vpc_id] [:vpc_id] = BuildCloud::VPC.get_id_by_name( [:vpc_name] ) .delete(:vpc_name) end = [] if [:authorized_ranges] = [:authorized_ranges] .delete(:authorized_ranges) end security_group = @compute.security_groups.new( ) security_group.save .each do |r| security_group.( r.delete(:min_port)..r.delete(:max_port), r ) end @log.debug( security_group.inspect ) end |
#delete ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'lib/build-cloud/securitygroup.rb', line 80 def delete return unless exists? @log.info( "Deleting security group #{@options[:name]}" ) fog_object.destroy end |
#read ⇒ Object Also known as: fog_object
74 75 76 |
# File 'lib/build-cloud/securitygroup.rb', line 74 def read @compute.security_groups.select { |sg| sg.name == @options[:name] }.first end |