Class: Kiel::Implementation

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

Instance Method Summary collapse

Constructor Details

#initialize(defaults) ⇒ Implementation

Returns a new instance of Implementation.



24
25
26
# File 'lib/kiel.rb', line 24

def initialize defaults
    @defaults = defaults.dup
end

Instance Method Details

#add_versions(steps) ⇒ Object



103
104
105
106
107
108
# File 'lib/kiel.rb', line 103

def add_versions steps
    steps.collect() do | step | 
        name = step[ :scm_name ] == '*' ? '*' : expand_path( step[ :scm_name ] )
        step.merge( version: scm.version( name ) ) 
    end
end

#create_task(step, steps) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/kiel.rb', line 69

def create_task step, steps
    task = Rake::Task::define_task( step[ :task ] => steps.collect{ | s | s[ :task ] } ) do | task, arguments |
        tags = build_tags step, steps

        if cloud.exists? tags
            puts "image \'#{step[ :name ]}\' already up to date and exists:"
            tags.each{ | key, value | puts "\'#{key}\' => \'#{value}\'" }                    
        else
            puts "starting instance for: \'#{step[ :name ]}\'"
            instance = cloud.start_instance initial_image_id( step, steps )
            puts "instance for: \'#{step[ :name ]}\' started."

            begin
                dns_name    = cloud.dns_name instance
                expand_step = step.dup.merge( setup_name: expand_path( step[ :setup_name ] ) )

                puts "excuting installation for: \'#{step[ :name ]}\'"
                setup.execute expand_step, dns_name  
                puts "installation for: \'#{step[ :name ]}\' done."

                puts "storing image for: \'#{step[ :name ]}\'"
                cloud.store_image instance, tags
                puts "image for: \'#{step[ :name ]}\' stored"
            rescue
                cloud.stop_instance instance
                raise
            end                     
        end                     
    end

    task.add_description( step[ :description ] ) if step.key? :description
    task
end

#expand_path(file_name) ⇒ Object



41
42
43
44
45
46
47
48
49
# File 'lib/kiel.rb', line 41

def expand_path file_name
    @defaults[ :root_dir ] ||= Dir.pwd
    
    if file_name.kind_of? Array 
        file_name.collect { |f| File.expand_path f, @defaults[ :root_dir ] }
    else                
        File.expand_path file_name, @defaults[ :root_dir ]
    end
end