Module: Blimpy::SecurityGroups

Defined in:
lib/blimpy/securitygroups.rb

Class Method Summary collapse

Class Method Details

.create_group(fog, ports) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blimpy/securitygroups.rb', line 30

def self.create_group(fog, ports)
  name = group_id(ports)
  group = fog.security_groups.create(:name => name,
                                     :description => "Custom Blimpy security group for #{ports.to_a}")

  unless ports.is_a? Set
    ports = Set.new(ports)
  end

  ports.each do |port|
    group.authorize_port_range(port .. port)
  end
  name
end

.ensure_group(fog, ports) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/blimpy/securitygroups.rb', line 19

def self.ensure_group(fog, ports)
  name = group_id(ports)

  exists = fog.security_groups.get(name)

  if exists.nil?
    name = create_group(fog, ports)
  end
  name
end

.group_id(ports) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/blimpy/securitygroups.rb', line 6

def self.group_id(ports)
  if ports.nil? or ports.empty?
    return nil
  end

  unless ports.is_a? Set
    ports = Set.new(ports)
  end

  # Lolwut, #hash is inconsistent between ruby processes
  "Blimpy-#{Zlib.crc32(ports.inspect)}"
end