Class: Piculet::EC2Wrapper::SecurityGroupCollection

Inherits:
Object
  • Object
show all
Includes:
Logger::ClientHelper
Defined in:
lib/piculet/wrapper/permission.rb,
lib/piculet/wrapper/security-group.rb,
lib/piculet/wrapper/permission-collection.rb,
lib/piculet/wrapper/security-group-collection.rb

Defined Under Namespace

Classes: SecurityGroup

Instance Method Summary collapse

Methods included from Logger::ClientHelper

#log

Constructor Details

#initialize(security_groups, options) ⇒ SecurityGroupCollection

Returns a new instance of SecurityGroupCollection.



10
11
12
13
# File 'lib/piculet/wrapper/security-group-collection.rb', line 10

def initialize(security_groups, options)
  @security_groups = security_groups
  @options = options
end

Instance Method Details

#create(name, opts = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/piculet/wrapper/security-group-collection.rb', line 21

def create(name, opts = {})
  log(:info, 'Create SecurityGroup', :cyan, "#{opts[:vpc] || :classic} > #{name}")
  log(:warn, '`egress any 0.0.0.0/0` is implicitly defined', :yellow) if @options.dry_run && opts[:vpc]

  if @options.dry_run
    sg = OpenStruct.new({:id => '<new security group>', :name => name}.merge(opts))
  else
    sg = @security_groups.create(name, opts)
    @options.updated = true
  end

  SecurityGroup.new(sg, @options)
end

#eachObject



15
16
17
18
19
# File 'lib/piculet/wrapper/security-group-collection.rb', line 15

def each
  @security_groups.each do |sg|
    yield(SecurityGroup.new(sg, @options))
  end
end