Class: Kelbim::Client

Inherits:
Object
  • Object
show all
Includes:
Logger::ClientHelper, Utils::Helper
Defined in:
lib/kelbim/client.rb

Instance Method Summary collapse

Methods included from Utils::Helper

#matched_elb?

Methods included from Logger::ClientHelper

#log

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



6
7
8
9
10
11
# File 'lib/kelbim/client.rb', line 6

def initialize(options = {})
  @options = OpenStruct.new(options)
  @options.elb = AWS::ELB.new
  @options.ec2 = AWS::EC2.new
  @options.iam = AWS::IAM.new
end

Instance Method Details

#apply(file) ⇒ Object



13
14
15
# File 'lib/kelbim/client.rb', line 13

def apply(file)
  AWS.memoize { walk(file) }
end

#export(opts = {}) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/kelbim/client.rb', line 68

def export(opts = {})
  exported = nil
  instance_names = nil

  AWS.memoize do
    exported = Exporter.export(@options.elb, opts)
    instance_names = @options.ec2.instance_names
  end

  if block_given?
    converter = proc do |src|
      DSL.convert(src, instance_names)
    end

    yield(exported, converter)
  else
    DSL.convert(exported, instance_names)
  end
end

#load_balancersObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kelbim/client.rb', line 24

def load_balancers
  exported = nil

  AWS.memoize do
    exported = Exporter.export(@options.elb)
  end

  retval = {}

  exported.map do |vpc, lbs|
    vpc = vpc || 'classic'
    retval[vpc] = {}

    lbs.map do |name, attrs|
      retval[vpc][name] = attrs[:dns_name]
    end
  end

  return retval
end

#policiesObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/kelbim/client.rb', line 45

def policies
  exported = nil

  AWS.memoize do
    exported = Exporter.export(@options.elb, :fetch_policies => true)
  end

  retval = {}

  exported.map do |vpc, lbs|
    vpc = vpc || 'classic'

    lbs.map do |name, attrs|
      if attrs[:policies]
        retval[vpc] ||= {}
        retval[vpc][name] = attrs[:policies]
      end
    end
  end

  return retval
end

#test(file) ⇒ Object



17
18
19
20
21
22
# File 'lib/kelbim/client.rb', line 17

def test(file)
  AWS.memoize do
    dsl = load_file(file)
    Tester.test(dsl)
  end
end