Class: Kelbim::Client

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

Instance Method Summary collapse

Methods included from Logger::ClientHelper

#log

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/kelbim/client.rb', line 15

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



22
23
24
# File 'lib/kelbim/client.rb', line 22

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

#export(opts = {}) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/kelbim/client.rb', line 77

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/kelbim/client.rb', line 33

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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/kelbim/client.rb', line 54

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



26
27
28
29
30
31
# File 'lib/kelbim/client.rb', line 26

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