Class: Bosh::Cli::Command::Stemcell
- Defined in:
- lib/cli/commands/stemcell.rb
Constant Summary collapse
- STEMCELL_EXISTS_ERROR_CODE =
50002
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
Instance Method Details
#delete(name, version) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/cli/commands/stemcell.rb', line 134 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
125 126 127 128 129 |
# File 'lib/cli/commands/stemcell.rb', line 125 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
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/cli/commands/stemcell.rb', line 86 def list auth_required stemcells = director.list_stemcells.sort do |sc1, sc2| if sc1['name'] == sc2['name'] Bosh::Common::Version::StemcellVersion.parse_and_compare(sc1['version'], sc2['version']) else sc1['name'] <=> sc2['name'] end 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
117 118 119 120 121 |
# File 'lib/cli/commands/stemcell.rb', line 117 def list_public public_stemcells = PublicStemcells.new public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcells) public_stemcells_presenter.list() end |
#upload(stemcell_location) ⇒ Object
32 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 |
# File 'lib/cli/commands/stemcell.rb', line 32 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
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cli/commands/stemcell.rb', line 10 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 |