Class: ZergrushCF::Renderer

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

Instance Method Summary collapse

Constructor Details

#initialize(hive_location, task_name, task_hash) ⇒ Renderer

Returns a new instance of Renderer.



30
31
32
33
34
35
36
37
# File 'lib/zergrush_cf/renderer.rb', line 30

def initialize(hive_location, task_name, task_hash)
    @vm = task_hash["vm"]
    @name = task_name
    @template = task_hash["vm"]["driver"]["driveroptions"][0]["template"]
    @template_file = task_hash["vm"]["driver"]["driveroptions"][0]["template_file"]
    @driver = task_hash["vm"]["driver"]["drivertype"] 
    @hive_location = hive_location
end

Instance Method Details

#renderObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/zergrush_cf/renderer.rb', line 39

def render
    puts ("Rendering driver templates...")

    abort("ERROR: Can't specify both template and template_file") unless @template == nil || @template_file == nil
    abort("ERROR: Must specify template or template_file") unless @template != nil || @template_file != nil

    template_body = (@template != nil) ? @template : JSON.parse( IO.read(File.join(@hive_location, @name, @template_file)) )


    puts ("Writing #{File.join(@hive_location, "driver", @driver, @name, "template.json")}...")
    FileUtils.mkdir_p(File.join(@hive_location, "driver", @driver, @name))
    File.open(File.join("#{@hive_location}", "driver", @vm["driver"]["drivertype"], @name, "template.json"), 'w') { |file| file.write(template_body.to_json) }

    return template_body
end