class Ec2::ProfileDsl
Attributes
api[R]
Public Class Methods
new(file, api:)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 15 def initialize(file, api:) @file = file @profiles = {} @api = api @templates = {} @availability_zones = ["a", "b"] @required = Set.new end
Public Instance Methods
availability_zones(*zones)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 69 def availability_zones(*zones) @availability_zones = zones end
base_profile(name)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 61 def base_profile(name) @base_profile = name end
base_subnet(name)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 65 def base_subnet(name) @base_subnet = name end
import(path)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 88 def import(path) abs_path = File.realpath path return if @required.include? abs_path instance_eval((File.read abs_path), abs_path) @required << abs_path end
mprofile(name, template: nil, &block)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 39 def mprofile(name, template: nil, &block) data = @templates.fetch template if template @availability_zones.each do |az| profile = Profile.new(data: data, api: api) profile.extends(@base_profile) if @base_profile profile.subnet("#{@base_subnet}-#{az}") profile.create &block profile_name = "#{name}-#{az}" profile.data.freeze @profiles[profile_name] = profile.data end end
profile(name, template: nil, &block)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 52 def profile(name, template: nil, &block) data = @templates.fetch template if template profile = Profile.new(data: data, api: api) profile.extends(@base_profile) if @base_profile profile.create &block profile.data.freeze @profiles[name] = profile.data end
render()
click to toggle source
# File lib/ec2/profile_dsl.rb, line 73 def render if not File.readable? @file logger.info "#{@file} not readable" return end instance_eval(File.read(@file), @file) YAML.dump @profiles rescue NoMethodError => e error "invalid option used in profiles config: #{e.name}" end
template(name, &block)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 31 def template(name, &block) profile = Profile.new(api: api) profile.extends(@base_profile) if @base_profile profile.create(transform: false, &block) @templates[name] = profile.data @templates[name].freeze end
use(*templates)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 24 def use(*templates) templates.each do |t| t = t.to_s mprofile(t, template: t){} end end
vpc_id(vpc_id)
click to toggle source
# File lib/ec2/profile_dsl.rb, line 84 def vpc_id(vpc_id) @vpc_id = vpc_id end