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, #info, #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, #run_nested_command, #show_current_state, #target, #target_name, #verbose?
#desc, #method_added, #option, #register_command, #usage
#build_manifest, #cancel_deployment, #deployment_changed?, #inspect_deployment_changes, #job_exists_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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/cli/commands/stemcell.rb', line 158
def delete(name, version)
auth_required
show_current_state
force = !!options[:force]
err("Stemcell `#{name}/#{version}' does not exist") unless exists?(name, version)
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
149
150
151
152
153
|
# File 'lib/cli/commands/stemcell.rb', line 149
def download_public(stemcell_filename)
public_stemcells = PublicStemcells.new
public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcells)
public_stemcells_presenter.download(stemcell_filename)
end
|
108
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
134
135
|
# File 'lib/cli/commands/stemcell.rb', line 108
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
141
142
143
144
145
|
# File 'lib/cli/commands/stemcell.rb', line 141
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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/cli/commands/stemcell.rb', line 38
def upload(stemcell_location)
auth_required
show_current_state
if options[:skip_if_exists] && options[:fix]
err("Option '--skip-if-exists' and option '--fix' should not be used together")
end
if options[:fix] && (options[:name] || options[:version])
err("Options '--name' and '--version' should not be used together with option '--fix'")
end
stemcell_type = stemcell_location =~ /^#{URI::regexp}$/ ? 'remote' : 'local'
if options[:name] && options[:version]
return if exists?(options[:name], options[:version])
end
if stemcell_type == 'local'
err("Option '--sha1' is not supported for uploading local stemcell") unless options[:sha1].nil?
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
name = stemcell.manifest['name']
version = stemcell.manifest['version']
if !options[:fix] && 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
end
stemcell_location = stemcell.stemcell_file
nl
say('Uploading stemcell...')
nl
else
nl
say("Using remote stemcell `#{stemcell_location}'")
end
selected_options = {}
selected_options[:fix] = options[:fix] if options[:fix]
selected_options[:sha1] = options[:sha1] if options[:sha1]
status, task_id = apply_upload_stemcell_strategy(stemcell_type, stemcell_location, selected_options)
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
|