Class: Stacco::Orchestrator

Inherits:
Object
  • Object
show all
Defined in:
lib/stacco/orchestrator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Orchestrator

Returns a new instance of Orchestrator.



12
13
14
15
16
17
18
19
20
21
# File 'lib/stacco/orchestrator.rb', line 12

def initialize(config)
  @config = config

  @services = {}
  @services[:s3] = AWS::S3.new(
    access_key_id: @config['aws']['access_key_id'],
    secret_access_key: @config['aws']['secret_access_key'],
    region: @config['aws']['region']
  )
end

Class Method Details

.from_config(config_body) ⇒ Object



7
8
9
10
# File 'lib/stacco/orchestrator.rb', line 7

def self.from_config(config_body)
  config_body = config_body.read if config_body.respond_to?(:read)
  self.new YAML.load(config_body)
end

Instance Method Details

#define_stack(config_body) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stacco/orchestrator.rb', line 31

def define_stack(config_body)
  config_body = config_body.read if config_body.respond_to?(:read)
  config = YAML.load(config_body)

  stack_name = config['name']
  bucket_name = "stacco-#{self.stack_bucket_prefix}-stack-#{stack_name}"

  bucket = @services[:s3].buckets[bucket_name]
  unless bucket.exists?
    @services[:s3].buckets.create(bucket_name)
  end

  bucket.objects['stack.yml'].write(config.to_yaml)

  Stacco::Stack.new(bucket)
end

#stack_bucket_prefixObject



23
24
25
# File 'lib/stacco/orchestrator.rb', line 23

def stack_bucket_prefix
  @config['organization'].gsub(/[^\w]/, '')
end

#stacksObject



27
28
29
# File 'lib/stacco/orchestrator.rb', line 27

def stacks
  @services[:s3].buckets.find_all{ |b| b.name =~ /^stacco-#{self.stack_bucket_prefix}-stack-/ }.map{ |b| Stacco::Stack.new(b) rescue nil }.compact
end