Class: ETDLProcessor

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

Overview

Use various subsystems to process an etdl

Instance Method Summary collapse

Instance Method Details

#launch_instance(etdl) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/etdl_processor.rb', line 17

def launch_instance(etdl)
  puts "Connecting to deltacloud instance at #{TDLTools::CloudInst::DC_URL}...".green
  inst = TDLTools::CloudInst.new etdl.cloud_attributes

  puts "Booting up cloud instance".green
  puts "  This will take a few minutes to become fully accessible".green
  inst.launch

  if inst.address.nil?
    puts "could not find address to access instance with".red
    exit 1
  end

  puts "using address #{inst.address}\nssh:#{inst.ssh}\nscp:#{inst.scp}".green

  # TODO compare instance to etdl os

  inst
end

#process(etdl, instance) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/etdl_processor.rb', line 37

def process(etdl, instance)
  # TODO setup repos

  # yum install packages
  packages = etdl.instance_attributes[:packages].join(" ")
    puts "installing #{packages}".green
    puts instance.exec(TDLTools::PackageSystem.install_pkg_cmd(packages)).blue

  # copy files over
  files = etdl.instance_attributes[:files]
    files.each { |f|
      tf = Tempfile.new('tdl-launch')
      tf.write f[:contents]
      tf.close

      instance.cp tf.path, f[:name]
    }

  cmds = etdl.instance_attributes[:commands]
    cmds.each { |c|
      puts "running command #{c[:cmd]}"
      puts instance.exec("#{c[:cmd]}").blue
    }
end

#terminate_instance(instance) ⇒ Object



76
77
78
# File 'lib/etdl_processor.rb', line 76

def terminate_instance(instance)
  # TODO
end

#verify(etdl, instance) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/etdl_processor.rb', line 62

def verify(etdl, instance)
  etdl.verify_cmds.each { |v|
      puts "running verification #{v}"
      output = instance.exec("#{v}")
      if $?.to_i == 0
        puts output.blue
        puts "  ...success!".blue
      else
        puts output.red
        puts "  ... #{v} failed".red
      end
  }
end