Class: Bosh::Cli::Command::PrepareBoshForCloudFoundry

Inherits:
Base
  • Object
show all
Includes:
Validation
Defined in:
lib/bosh/cli/commands/01_prepare_bosh_for_cf.rb

Overview

Upload a specific bosh release (or the latest one) and upload the latest base stemcell, if target bosh does not already have a stemcell uploaded.

Instance Method Summary collapse

Instance Method Details

#prepare_cfObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/bosh/cli/commands/01_prepare_bosh_for_cf.rb', line 11

def prepare_cf
  auth_required
  bosh_status

  release_version = options[:release_version] || latest_release_version

  # Support:
  # * --release-version v132
  # * --release-version 132
  if release_version.to_s =~ /(\d+)/
    release_version = $1
  end
  release_yml = Dir[File.join(bosh_release_dir, "releases", "*-#{release_version}.yml")].first

  release_name = YAML.load_file(release_yml)["name"]

  release_exists = nil
  step("Checking bosh already has release #{release_name} #{release_version}",
        "Currently bosh does not have #{release_name} #{release_version}, uploading...", :non_fatal) do
    release_exists = director.list_releases.find do |existing_release|
      next false unless existing_release["name"] == release_name
      versions = existing_release["release_versions"]
      versions.find do |version|
        version["version"].to_s == release_version.to_s
      end
    end
  end
  unless errors.empty?
    say errors.shift.make_yellow
    release_cmd(non_interactive: true).upload(release_yml)
  end

  stemcell_exists = nil
  step("Checking bosh already has base stemcell",
        "Currently bosh does not have base stemcell, uploading...", :non_fatal) do
    stemcell_exists = director.list_stemcells.find do |existing_stemcell|
      existing_stemcell["name"] == stemcell_name
    end
  end
  unless errors.empty?
    say errors.shift.make_yellow
    stemcell_url = "http://bosh-jenkins-artifacts.s3.amazonaws.com/bosh-stemcell/#{bosh_cpi}/bosh-stemcell-latest-#{bosh_cpi}-#{bosh_cpi_hypervisor}-ubuntu.tgz"
    stemcell_cmd(non_interactive: true).upload(stemcell_url)
  end
end