Class: Bosh::Cli::Command::Stemcell
- Inherits:
-
Base
show all
- Defined in:
- lib/cli/commands/stemcell.rb
Constant Summary
collapse
- STEMCELL_EXISTS_ERROR_CODE =
50002
Constants inherited
from Base
Base::DEFAULT_DIRECTOR_PORT
Instance Attribute Summary
Attributes inherited from Base
#args, #exit_code, #options, #out, #runner, #work_dir
Instance Method Summary
collapse
Methods inherited from Base
#add_option, #blob_manager, #blobstore, #cache_dir, #config, #confirmed?, #credentials, #deployment, #director, #initialize, #interactive?, #logged_in?, #non_interactive?, #progress_renderer, #redirect, #release, #remove_option, #show_current_state, #target, #target_name, #verbose?
#desc, #method_added, #option, #register_command, #usage
#cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_in_deployment?, #job_must_exist_in_deployment, #job_unique_in_deployment?, #jobs_and_indexes, #prepare_deployment_manifest, #prompt_for_errand_name, #prompt_for_job_and_index
Instance Method Details
#delete(name, version) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/cli/commands/stemcell.rb', line 137
def delete(name, version)
auth_required
show_current_state
force = !!options[: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
128
129
130
131
132
|
# File 'lib/cli/commands/stemcell.rb', line 128
def download_public(stemcell_filename)
public_stemcells = PublicStemcells.new
public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcells)
public_stemcells_presenter.download(stemcell_filename)
end
|
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
112
113
114
|
# File 'lib/cli/commands/stemcell.rb', line 87
def list
auth_required
show_current_state
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', 'OS', '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
120
121
122
123
124
|
# File 'lib/cli/commands/stemcell.rb', line 120
def list_public
public_stemcells = PublicStemcells.new
public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcells)
public_stemcells_presenter.list(options)
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
83
|
# File 'lib/cli/commands/stemcell.rb', line 32
def upload(stemcell_location)
auth_required
show_current_state
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 options[: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)
success_message = 'Stemcell uploaded and created.'
if status == :error && options[:skip_if_exists] && last_event(task_id)['error']['code'] == STEMCELL_EXISTS_ERROR_CODE
status = :done
success_message = skip_existing_stemcell_message(stemcell_type, stemcell_location)
end
task_report(status, task_id, success_message)
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
|