Class: Bosh::Cli::Command::Stemcell
- Includes:
- VersionCalc
- Defined in:
- lib/cli/commands/stemcell.rb
Constant Summary collapse
- STEMCELL_EXISTS_ERROR_CODE =
50002
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#args, #exit_code, #options, #out, #runner, #work_dir
Instance Method Summary collapse
- #delete(name, version) ⇒ Object
- #download_public(stemcell_filename) ⇒ Object
- #list ⇒ Object
- #list_public ⇒ Object
- #upload(stemcell_location) ⇒ 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, #config, #confirmed?, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #password, #redirect, #release, #remove_option, #target, #target_name, #username, #verbose?
Methods included from Bosh::Cli::CommandDiscovery
#desc, #method_added, #option, #register_command, #usage
Methods included from DeploymentHelper
#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_in_deployment, #job_unique_in_deployment?, #jobs_and_indexes, #latest_release_versions, #prepare_deployment_manifest, #prompt_for_job_and_index, #resolve_release_aliases
Constructor Details
This class inherits a constructor from Bosh::Cli::Command::Base
Instance Method Details
#delete(name, version) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/cli/commands/stemcell.rb', line 133 def delete(name, version) auth_required force = !![:force] 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}'".make_red) unless confirmed? say('Canceled deleting stemcell'.make_green) return end status, task_id = director.delete_stemcell(name, version, :force => force) task_report(status, task_id, "Deleted stemcell `#{name}/#{version}'") end |
#download_public(stemcell_filename) ⇒ Object
124 125 126 127 128 |
# File 'lib/cli/commands/stemcell.rb', line 124 def download_public(stemcell_filename) public_stemcells = PublicStemcells.new public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcells) public_stemcells_presenter.download(stemcell_filename) end |
#list ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cli/commands/stemcell.rb', line 87 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 << get_stemcell_table_record(sc) end end nl say(stemcells_table) nl say('(*) Currently in-use') nl say('Stemcells total: %d' % stemcells.size) end |
#list_public ⇒ Object
116 117 118 119 120 |
# File 'lib/cli/commands/stemcell.rb', line 116 def list_public public_stemcells = PublicStemcells.new public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcells) public_stemcells_presenter.list() end |
#upload(stemcell_location) ⇒ Object
33 34 35 36 37 38 39 40 41 42 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 76 77 78 79 80 81 82 83 |
# File 'lib/cli/commands/stemcell.rb', line 33 def upload(stemcell_location) auth_required stemcell_type = stemcell_location =~ /^#{URI::regexp}$/ ? 'remote' : 'local' if stemcell_type == 'local' stemcell = Bosh::Cli::Stemcell.new(stemcell_location) 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) if [:skip_if_exists] say("Stemcell `#{name}/#{version}' already exists. Skipping upload.") return else err("Stemcell `#{name}/#{version}' already exists. Increment the version if it has changed.") end else say('No') end stemcell_location = stemcell.stemcell_file nl say('Uploading stemcell...') nl else nl say("Using remote stemcell `#{stemcell_location}'") end status, task_id = apply_upload_stemcell_strategy(stemcell_type, stemcell_location) = 'Stemcell uploaded and created.' if status == :error && [:skip_if_exists] && last_event(task_id)['error']['code'] == STEMCELL_EXISTS_ERROR_CODE status = :done = (stemcell_type, stemcell_location) end task_report(status, task_id, ) end |
#verify(tarball_path) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/cli/commands/stemcell.rb', line 11 def verify(tarball_path) stemcell = Bosh::Cli::Stemcell.new(tarball_path) nl say('Verifying stemcell...') stemcell.validate nl if stemcell.valid? say("`#{tarball_path}' is a valid stemcell".make_green) else say('Validation errors:'.make_red) stemcell.errors.each do |error| say('- %s' % [error]) end err("`#{tarball_path}' is not a valid stemcell") end end |