module Bosh::Workspace::StemcellHelper
Public Instance Methods
download_stemcell_from_bosh_io(stemcell)
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 42 def download_stemcell_from_bosh_io(stemcell) url = "https://bosh.io/d/stemcells/#{stemcell.name}?v=#{stemcell.version}" response = HTTPClient.new.head(url) if response.status == 302 location = response.header['location'][0] response2 = HTTPClient.new.head(location) if response2.status == 200 size = response2.header['Content-Length'][0] else say("HTTP #{response2.status} : #{location}".make_red) say(" - redirected from: : #{url}".make_red) return end else say("HTTP #{response.status} : #{url} (expecting 302 - redirect)".make_red) return end download_with_progress = Bosh::Cli::DownloadWithProgress.new(location, size.to_i) download_with_progress.perform end
project_deployment_stemcells()
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 36 def project_deployment_stemcells @stemcells ||= begin project_deployment.stemcells.map { |s| Stemcell.new(s, stemcells_dir) } end end
stemcell_download(stemcell)
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 8 def stemcell_download(stemcell) Dir.chdir(stemcells_dir) do say "Downloading stemcell '#{stemcell.name}' version '#{stemcell.version}'" nl download_stemcell_from_bosh_io(stemcell) end end
stemcell_upload(stemcell_file)
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 16 def stemcell_upload(stemcell_file) say "Uploading stemcell '#{File.basename(stemcell_file)}'" nl stemcell_cmd.upload(stemcell_file) end
stemcell_uploaded?(name, version)
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 22 def stemcell_uploaded?(name, version) existing = director.list_stemcells.select do |sc| sc['name'] == name && sc['version'] == version.to_s end !existing.empty? end
stemcells_dir()
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 30 def stemcells_dir @stemcells_dir ||= begin FileUtils.mkdir_p(File.join(work_dir, ".stemcells")).first end end
Private Instance Methods
stemcell_cmd()
click to toggle source
# File lib/bosh/workspace/helpers/stemcell_helper.rb, line 70 def stemcell_cmd @stemcell_cmd ||= Bosh::Cli::Command::Stemcell.new end