Class: Piculet::Client

Inherits:
Object
  • Object
show all
Includes:
Logger::ClientHelper
Defined in:
lib/piculet/client.rb

Instance Method Summary collapse

Methods included from Logger::ClientHelper

#log

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
# File 'lib/piculet/client.rb', line 5

def initialize(options = {})
  @options = OpenStruct.new(options)
  @options_hash = options
  @options.ec2 = AWS::EC2.new
end

Instance Method Details

#apply(file) ⇒ Object



11
12
13
14
# File 'lib/piculet/client.rb', line 11

def apply(file)
  @options.ec2.owner_id
  AWS.memoize { walk(file) }
end

#export(options = {}) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/piculet/client.rb', line 40

def export(options = {})
  exported = AWS.memoize do
    Exporter.export(@options.ec2, @options_hash.merge(options))
  end

  converter = proc do |src|
    if options[:without_convert]
      exported
    else
      DSL.convert(src, @options.ec2.owner_id)
    end
  end

  if block_given?
    yield(exported, converter)
  else
    converter.call(exported)
  end
end

#should_skip(sg_name, sg) ⇒ Object



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

def should_skip(sg_name, sg)
  # Name
  if @options.sg_names
    if not @options.sg_names.include?(sg_name)
      return true
    end
  end

  if @options.exclude_sgs
    if @options.exclude_sgs.any? {|regex| sg_name =~ regex}
      return true
    end
  end

  # Tag
  if @options.exclude_tags
    if sg and (@options.exclude_tags & sg.tags.keys).any?
      return true
    end
  end

  false
end