Class: Piculet::Exporter

Inherits:
Object
  • Object
show all
Defined in:
lib/piculet/exporter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ec2, options = {}) ⇒ Exporter

of class methods



9
10
11
12
# File 'lib/piculet/exporter.rb', line 9

def initialize(ec2, options = {})
  @ec2 = ec2
  @options = options
end

Class Method Details

.export(ec2, options = {}) ⇒ Object



4
5
6
# File 'lib/piculet/exporter.rb', line 4

def export(ec2, options = {})
  self.new(ec2, options).export
end

Instance Method Details

#exportObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/piculet/exporter.rb', line 14

def export
  result = {}
  ec2s = @options[:ec2s]
  sg_names = @options[:sg_names]
  sgs = @ec2.security_groups
  sgs = sgs.filter('group-name', *sg_names) if sg_names
  sgs = sgs.sort_by {|sg| sg.name }

  sgs.each do |sg|
    vpc = sg.vpc
    vpc = vpc.id if vpc

    if ec2s
      next unless ec2s.any? {|i| (i == 'classic' and vpc.nil?) or i == vpc }
    end

    result[vpc] ||= {}
    result[vpc][sg.id] = export_security_group(sg)
  end

  return result
end