Class: Bosh::Cli::Command::Stemcell
- Includes:
- VersionCalc
- Defined in:
- lib/cli/commands/stemcell.rb
Constant Summary collapse
- PUBLIC_STEMCELL_INDEX =
The filename of the public stemcell index.
"public_stemcells_index.yml"
- PUBLIC_STEMCELL_INDEX_URL =
The URL of the public stemcell index.
"https://blob.cfblob.com/rest/objects/4e4e78bca2" + "1e121204e4e86ee151bc04f6a19ce46b22?uid=bb6a0c89ef4048a8a0f814e2538" + "5d1c5/user1&expires=1893484800&signature=NJuAr9c8eOid7dKFmOEN7bmzAlI="
- DEFAULT_PUB_STEMCELL_TAG =
"stable"
- ALL_STEMCELLS_TAG =
"all"
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#args, #options, #out, #runner, #work_dir
Instance Method Summary collapse
- #delete(name, version) ⇒ Object
- #download_public(stemcell_name) ⇒ Object
- #list ⇒ Object
- #list_public ⇒ Object
- #upload(tarball_path) ⇒ Object
- #verify(tarball_path) ⇒ Object
Methods included from VersionCalc
#major_version, #minor_version, #version_cmp, #version_greater, #version_less, #version_same
Methods inherited from Base
#add_option, #blob_manager, #blobstore, #cache, #config, #confirmed?, #deployment, #director, #exit_code, #initialize, #interactive?, #logged_in?, #non_interactive?, #password, #redirect, #release, #remove_option, #target, #target_name, #task_report, #username, #verbose?
Methods included from Bosh::Cli::CommandDiscovery
#desc, #method_added, #option, #register_command, #usage
Constructor Details
This class inherits a constructor from Bosh::Cli::Command::Base
Instance Method Details
#delete(name, version) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/cli/commands/stemcell.rb', line 180 def delete(name, version) auth_required say("Checking if stemcell exists...") unless exists?(name, version) err("Stemcell `#{name}/#{version}' does not exist") end say("You are going to delete stemcell `#{name}/#{version}'".red) unless confirmed? say("Canceled deleting stemcell".green) return end status, task_id = director.delete_stemcell(name, version) task_report(status, task_id, "Deleted stemcell `#{name}/#{version}'") end |
#download_public(stemcell_name) ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/cli/commands/stemcell.rb', line 140 def download_public(stemcell_name) yaml = get_public_stemcell_list yaml.delete(PUBLIC_STEMCELL_INDEX) if yaml.has_key?(PUBLIC_STEMCELL_INDEX) unless yaml.has_key?(stemcell_name) available_stemcells = yaml.map { |k| k }.join(", ") err("'#{stemcell_name}' not found in '#{available_stemcells}'.") end if File.exists?(stemcell_name) && !confirmed?("Overwrite existing file `#{stemcell_name}'?") err("File `#{stemcell_name}' already exists") end url = yaml[stemcell_name]["url"] size = yaml[stemcell_name]["size"] sha1 = yaml[stemcell_name]["sha"] = ProgressBar.new(stemcell_name, size) .file_transfer_mode File.open("#{stemcell_name}", "w") do |file| @http_client.get(url) do |chunk| file.write(chunk) .inc(chunk.size) end end .finish file_sha1 = Digest::SHA1.file(stemcell_name).hexdigest if file_sha1 != sha1 err("The downloaded file sha1 `#{file_sha1}' does not match the " + "expected sha1 `#{sha1}'") else say("Download complete".green) end end |
#list ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/cli/commands/stemcell.rb', line 80 def list auth_required stemcells = director.list_stemcells.sort do |sc1, sc2| sc1["name"] == sc2["name"] ? version_cmp(sc1["version"], sc2["version"]) : sc1["name"] <=> sc2["name"] end err("No stemcells") if stemcells.empty? stemcells_table = table do |t| t.headings = "Name", "Version", "CID" stemcells.each do |sc| t << [sc["name"], sc["version"], sc["cid"]] end end nl say(stemcells_table) nl say("Stemcells total: %d" % stemcells.size) end |
#list_public ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/cli/commands/stemcell.rb', line 109 def list_public full = !![:full] = [:tags] || [DEFAULT_PUB_STEMCELL_TAG] = [ALL_STEMCELLS_TAG] if [:all] yaml = get_public_stemcell_list stemcells_table = table do |t| t.headings = full ? ["Name", "Url", "Tags"] : ["Name", "Tags"] yaml.keys.sort.each do |key| if key != PUBLIC_STEMCELL_INDEX url = yaml[key]["url"] = yaml[key]["tags"] next if skip_this_tag?(, ) = ? .join(", ") : "" t << (full ? [key, url, ] : [key, ]) end end end say(stemcells_table) say("To download use `bosh download public stemcell <stemcell_name>'. " + "For full url use --full.") end |
#upload(tarball_path) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/cli/commands/stemcell.rb', line 43 def upload(tarball_path) auth_required stemcell = Bosh::Cli::Stemcell.new(tarball_path, cache) nl say("Verifying stemcell...") stemcell.validate nl unless stemcell.valid? err("Stemcell is invalid, please fix, verify and upload again") end say("Checking if stemcell already exists...") name = stemcell.manifest["name"] version = stemcell.manifest["version"] if exists?(name, version) err("Stemcell `#{name}/#{version}' already exists, " + "increment the version if it has changed") else say("No") end nl say("Uploading stemcell...") nl status, task_id = director.upload_stemcell(stemcell.stemcell_file) task_report(status, task_id, "Stemcell uploaded and created") end |
#verify(tarball_path) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cli/commands/stemcell.rb', line 21 def verify(tarball_path) stemcell = Bosh::Cli::Stemcell.new(tarball_path, cache) nl say("Verifying stemcell...") stemcell.validate nl if stemcell.valid? say("`#{tarball_path}' is a valid stemcell".green) else say("Validation errors:".red) stemcell.errors.each do |error| say("- %s" % [error]) end err("`#{tarball_path}' is not a valid stemcell") end end |