Class: NiseBOSHVagrant::Runner
- Inherits:
-
Object
- Object
- NiseBOSHVagrant::Runner
- Defined in:
- lib/nise-bosh-vagrant/runner.rb
Instance Attribute Summary collapse
-
#copy_name ⇒ Object
readonly
Returns the value of attribute copy_name.
-
#install_script_path ⇒ Object
readonly
Returns the value of attribute install_script_path.
-
#manifest_copy_path ⇒ Object
readonly
Returns the value of attribute manifest_copy_path.
-
#manifest_file ⇒ Object
readonly
Returns the value of attribute manifest_file.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#nise_path ⇒ Object
readonly
Returns the value of attribute nise_path.
-
#release_path ⇒ Object
readonly
Returns the value of attribute release_path.
-
#scripts_path ⇒ Object
readonly
Returns the value of attribute scripts_path.
-
#vagrantfile_path ⇒ Object
readonly
Returns the value of attribute vagrantfile_path.
Instance Method Summary collapse
- #copy_hook_scripts(output_dir = @release_path, preinstall_file = @preinstall_file, postinstall_file = @postinstall_file) ⇒ Object
- #copy_manifest(output_dir = @release_path, manifest_file = @manifest_file) ⇒ Object
- #exec(cmd) ⇒ Object
- #generate_install_script(output_dir = @release_path, manifest_file = @manifest_copy_path) ⇒ Object
- #generate_vagrantfile(output_path = @vagrantfile_path) ⇒ Object
-
#initialize(opts) ⇒ Runner
constructor
A new instance of Runner.
- #install_release(release_path = @release_path) ⇒ Object
- #prepare_vm(release_path = @release_path) ⇒ Object
- #run_postinstall_release(release_path = @release_path) ⇒ Object
- #run_preinstall_release(release_path = @release_path) ⇒ Object
- #start_release(release_path = @release_path) ⇒ Object
- #start_vm(release_path = @release_path) ⇒ Object
Constructor Details
#initialize(opts) ⇒ Runner
Returns a new instance of Runner.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 12 def initialize(opts) opts[:nise].nil? ? @nise_path = nil : @nise_path = File.(opts[:nise]) @release_path = opts[:release] @vagrantfile_path = File.join(@release_path, "Vagrantfile") @scripts_path = File.join(File.dirname(File.(__FILE__)), "../../scripts") @manifest_file = opts[:manifest] @preinstall_file = opts[:preinstall] @postinstall_file = opts[:postinstall] @memory = opts[:memory] @ip_address = opts[:address] copy_file_prefix = '.nise-bosh' @copy_name = { :manifest => "#{copy_file_prefix}-manifest.yml", :preinstall => "#{copy_file_prefix}-preinstall", :postinstall => "#{copy_file_prefix}-postinstall", :install_script => "#{copy_file_prefix}-install.sh", } end |
Instance Attribute Details
#copy_name ⇒ Object (readonly)
Returns the value of attribute copy_name.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def copy_name @copy_name end |
#install_script_path ⇒ Object (readonly)
Returns the value of attribute install_script_path.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def install_script_path @install_script_path end |
#manifest_copy_path ⇒ Object (readonly)
Returns the value of attribute manifest_copy_path.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def manifest_copy_path @manifest_copy_path end |
#manifest_file ⇒ Object (readonly)
Returns the value of attribute manifest_file.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def manifest_file @manifest_file end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def memory @memory end |
#nise_path ⇒ Object (readonly)
Returns the value of attribute nise_path.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def nise_path @nise_path end |
#release_path ⇒ Object (readonly)
Returns the value of attribute release_path.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def release_path @release_path end |
#scripts_path ⇒ Object (readonly)
Returns the value of attribute scripts_path.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def scripts_path @scripts_path end |
#vagrantfile_path ⇒ Object (readonly)
Returns the value of attribute vagrantfile_path.
9 10 11 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 9 def vagrantfile_path @vagrantfile_path end |
Instance Method Details
#copy_hook_scripts(output_dir = @release_path, preinstall_file = @preinstall_file, postinstall_file = @postinstall_file) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 45 def copy_hook_scripts(output_dir=@release_path, preinstall_file=@preinstall_file, postinstall_file=@postinstall_file) @preinstall_copy_path = File.join(output_dir, @copy_name[:preinstall]) if preinstall_file FileUtils.cp(preinstall_file, @preinstall_copy_path) else FileUtils.rm_rf(@preinstall_copy_path) end @postinstall_copy_path = File.join(output_dir, @copy_name[:postinstall]) if postinstall_file FileUtils.cp(postinstall_file, @postinstall_copy_path) else FileUtils.rm_rf(@postinstall_copy_path) end end |
#copy_manifest(output_dir = @release_path, manifest_file = @manifest_file) ⇒ Object
40 41 42 43 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 40 def copy_manifest(output_dir=@release_path, manifest_file=@manifest_file) @manifest_copy_path = File.join(output_dir, @copy_name[:manifest]) FileUtils.cp(manifest_file, @manifest_copy_path) end |
#exec(cmd) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 91 def exec(cmd) begin PTY.spawn (cmd) do |stdout, stdin, pid| begin stdout.each { |line| print line } rescue Errno::EIO end end rescue PTY::ChildExited end end |
#generate_install_script(output_dir = @release_path, manifest_file = @manifest_copy_path) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 60 def generate_install_script(output_dir=@release_path, manifest_file=@manifest_copy_path) manifest = YAML.load_file manifest_file jobs = [] manifest['jobs'].each do |job| jobs << job['name'] end puts "Job list: #{jobs}" install_script_template = File.open(File.join(File.dirname(File.(__FILE__)), '../../resources/install_release.sh.erb'), "rb") { |f| f.read } install_script_erb = ERB.new install_script_template install_script = "#!/bin/bash\n\n" install_script += "(\n" install_script += " cd /home/vagrant/nise_bosh\n" jobs.each do |job| manifest_path = "/home/vagrant/release/#{@copy_name[:manifest]}" job_name = job install_entry = install_script_erb.result(binding) install_script += "#{install_entry}\n" end install_script += ")" @install_script_path = File.join(output_dir, @copy_name[:install_script]) File.open(@install_script_path, "wb") { |f| f.write(install_script) } FileUtils.chmod 0755, @install_script_path end |
#generate_vagrantfile(output_path = @vagrantfile_path) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 33 def generate_vagrantfile(output_path=@vagrantfile_path) vagrantfile_template = File.open(File.join(File.dirname(File.(__FILE__)), '../../resources/Vagrantfile.erb'), "rb") { |f| f.read } template = ERB.new vagrantfile_template vagrantfile = template.result(binding) File.open(output_path, "wb") { |f| f.write(vagrantfile) } end |
#install_release(release_path = @release_path) ⇒ Object
114 115 116 117 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 114 def install_release(release_path=@release_path) install_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/install_release.sh\"" self.exec(install_cmd) end |
#prepare_vm(release_path = @release_path) ⇒ Object
109 110 111 112 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 109 def prepare_vm(release_path=@release_path) prepare_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/scripts/prepare.sh\"" self.exec(prepare_cmd) end |
#run_postinstall_release(release_path = @release_path) ⇒ Object
124 125 126 127 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 124 def run_postinstall_release(release_path=@release_path) hook_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/postinstall_release\"" self.exec(hook_cmd) end |
#run_preinstall_release(release_path = @release_path) ⇒ Object
119 120 121 122 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 119 def run_preinstall_release(release_path=@release_path) hook_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/preinstall_release\"" self.exec(hook_cmd) end |
#start_release(release_path = @release_path) ⇒ Object
129 130 131 132 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 129 def start_release(release_path=@release_path) start_cmd = "cd #{release_path} ; vagrant ssh -c \"/home/vagrant/start.sh\"" self.exec(start_cmd) end |
#start_vm(release_path = @release_path) ⇒ Object
103 104 105 106 107 |
# File 'lib/nise-bosh-vagrant/runner.rb', line 103 def start_vm(release_path=@release_path) up_cmd = "cd #{release_path} ; vagrant up" self.exec(up_cmd) end |