Class: Kiel::Implementation

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

Overview

:nodoc: all

Instance Method Summary collapse

Constructor Details

#initialize(defaults) ⇒ Implementation

Returns a new instance of Implementation.



28
29
30
# File 'lib/kiel.rb', line 28

def initialize defaults
    @defaults = defaults.dup
end

Instance Method Details

#add_versions(steps) ⇒ Object



120
121
122
123
124
125
# File 'lib/kiel.rb', line 120

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

this function creates the rake task, by first checking if the image already exists and then starting the base image and running the setup step



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/kiel.rb', line 85

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 ] ) )
                expand_step[ :tags ] = tags 
                
                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

fully expands the given file_name or array of file names



55
56
57
58
59
60
61
62
63
# File 'lib/kiel.rb', line 55

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