bosh_cli 1.5.0.pre.1336 → 1.5.0.pre.1337
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cli/commands/stemcell.rb +13 -106
- data/lib/cli/public_stemcell_presenter.rb +2 -2
- data/lib/cli/version.rb +1 -1
- metadata +6 -6
@@ -1,16 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
include Bosh::Cli::VersionCalc
|
4
|
-
|
5
|
-
# The filename of the public stemcell index.
|
6
|
-
PUBLIC_STEMCELL_INDEX = 'public_stemcells_index.yml'
|
1
|
+
require 'cli/public_stemcell_presenter'
|
2
|
+
require 'cli/public_stemcell_index'
|
7
3
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
DEFAULT_PUB_STEMCELL_TAG = 'stable'
|
13
|
-
ALL_STEMCELLS_TAG = 'all'
|
4
|
+
module Bosh::Cli
|
5
|
+
class Command::Stemcell < Command::Base
|
6
|
+
include Bosh::Cli::VersionCalc
|
14
7
|
|
15
8
|
usage 'verify stemcell'
|
16
9
|
desc 'Verify stemcell'
|
@@ -33,7 +26,6 @@ module Bosh::Cli::Command
|
|
33
26
|
end
|
34
27
|
end
|
35
28
|
|
36
|
-
# bosh upload stemcell
|
37
29
|
usage 'upload stemcell'
|
38
30
|
desc 'Upload stemcell (stemcell_location can be a local file or a remote URI)'
|
39
31
|
def upload(stemcell_location)
|
@@ -51,7 +43,7 @@ module Bosh::Cli::Command
|
|
51
43
|
unless stemcell.valid?
|
52
44
|
err('Stemcell is invalid, please fix, verify and upload again')
|
53
45
|
end
|
54
|
-
|
46
|
+
|
55
47
|
say('Checking if stemcell already exists...')
|
56
48
|
name = stemcell.manifest['name']
|
57
49
|
version = stemcell.manifest['version']
|
@@ -82,7 +74,6 @@ module Bosh::Cli::Command
|
|
82
74
|
task_report(status, task_id, 'Stemcell uploaded and created')
|
83
75
|
end
|
84
76
|
|
85
|
-
# bosh stemcells
|
86
77
|
usage 'stemcells'
|
87
78
|
desc 'Show the list of available stemcells'
|
88
79
|
def list
|
@@ -108,81 +99,25 @@ module Bosh::Cli::Command
|
|
108
99
|
say('Stemcells total: %d' % stemcells.size)
|
109
100
|
end
|
110
101
|
|
111
|
-
# Prints out the publicly available stemcells.
|
112
102
|
usage 'public stemcells'
|
113
103
|
desc 'Show the list of publicly available stemcells for download.'
|
114
104
|
option '--full', 'show the full download url'
|
115
105
|
option '--tags tag1,tag2...', Array, 'filter by tag'
|
116
106
|
option '--all', 'show all stemcells'
|
117
107
|
def list_public
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
yaml = get_public_stemcell_list
|
123
|
-
stemcells_table = table do |t|
|
124
|
-
t.headings = full ? ['Name', 'Url', 'Tags'] : ['Name', 'Tags']
|
125
|
-
yaml.keys.sort.each do |key|
|
126
|
-
if key != PUBLIC_STEMCELL_INDEX
|
127
|
-
url = yaml[key]['url']
|
128
|
-
yaml_tags = yaml[key]['tags']
|
129
|
-
next if skip_this_tag?(yaml_tags, tags)
|
130
|
-
|
131
|
-
yaml_tags = yaml_tags ? yaml_tags.join(', ') : ''
|
132
|
-
t << (full ? [key, url, yaml_tags] : [key, yaml_tags])
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
say(stemcells_table)
|
138
|
-
|
139
|
-
say("To download use `bosh download public stemcell <stemcell_name>'. " +
|
140
|
-
'For full url use --full.')
|
108
|
+
public_stemcell_index = PublicStemcellIndex.download(self)
|
109
|
+
public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcell_index)
|
110
|
+
public_stemcells_presenter.list(options)
|
141
111
|
end
|
142
112
|
|
143
|
-
# Downloads one of the publicly available stemcells.
|
144
113
|
usage 'download public stemcell'
|
145
114
|
desc 'Downloads a stemcell from the public blobstore'
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
yaml.delete(PUBLIC_STEMCELL_INDEX) if yaml.has_key?(PUBLIC_STEMCELL_INDEX)
|
151
|
-
|
152
|
-
unless yaml.has_key?(stemcell_name)
|
153
|
-
available_stemcells = yaml.map { |k| k }.join(', ')
|
154
|
-
err("'#{stemcell_name}' not found in '#{available_stemcells}'.")
|
155
|
-
end
|
156
|
-
|
157
|
-
if File.exists?(stemcell_name) &&
|
158
|
-
!confirmed?("Overwrite existing file `#{stemcell_name}'?")
|
159
|
-
err("File `#{stemcell_name}' already exists")
|
160
|
-
end
|
161
|
-
|
162
|
-
url = yaml[stemcell_name]['url']
|
163
|
-
size = yaml[stemcell_name]['size']
|
164
|
-
sha1 = yaml[stemcell_name]['sha']
|
165
|
-
progress_bar = ProgressBar.new(stemcell_name, size)
|
166
|
-
progress_bar.file_transfer_mode
|
167
|
-
|
168
|
-
File.open("#{stemcell_name}", 'w') do |file|
|
169
|
-
@http_client.get(url) do |chunk|
|
170
|
-
file.write(chunk)
|
171
|
-
progress_bar.inc(chunk.size)
|
172
|
-
end
|
173
|
-
end
|
174
|
-
progress_bar.finish
|
175
|
-
|
176
|
-
file_sha1 = Digest::SHA1.file(stemcell_name).hexdigest
|
177
|
-
if file_sha1 != sha1
|
178
|
-
err("The downloaded file sha1 `#{file_sha1}' does not match the " +
|
179
|
-
"expected sha1 `#{sha1}'")
|
180
|
-
else
|
181
|
-
say('Download complete'.make_green)
|
182
|
-
end
|
115
|
+
def download_public(stemcell_filename)
|
116
|
+
public_stemcell_index = PublicStemcellIndex.download(self)
|
117
|
+
public_stemcells_presenter = PublicStemcellPresenter.new(self, public_stemcell_index)
|
118
|
+
public_stemcells_presenter.download(stemcell_filename)
|
183
119
|
end
|
184
120
|
|
185
|
-
# bosh delete stemcell
|
186
121
|
usage 'delete stemcell'
|
187
122
|
desc 'Delete stemcell'
|
188
123
|
option '--force', 'ignore errors while deleting the stemcell'
|
@@ -210,21 +145,6 @@ module Bosh::Cli::Command
|
|
210
145
|
|
211
146
|
private
|
212
147
|
|
213
|
-
def skip_this_tag?(yaml_tags, requested_tags)
|
214
|
-
if requested_tags == [ALL_STEMCELLS_TAG]
|
215
|
-
return false
|
216
|
-
end
|
217
|
-
unless yaml_tags
|
218
|
-
return true
|
219
|
-
end
|
220
|
-
requested_tags.each do |tag|
|
221
|
-
unless yaml_tags.include?(tag)
|
222
|
-
return true
|
223
|
-
end
|
224
|
-
end
|
225
|
-
return false
|
226
|
-
end
|
227
|
-
|
228
148
|
def exists?(name, version)
|
229
149
|
existing = director.list_stemcells.select do |sc|
|
230
150
|
sc['name'] == name && sc['version'] == version
|
@@ -232,18 +152,5 @@ module Bosh::Cli::Command
|
|
232
152
|
|
233
153
|
!existing.empty?
|
234
154
|
end
|
235
|
-
|
236
|
-
# Grabs the index file for the publicly available stemcells.
|
237
|
-
# @return [Hash] The index file YAML as a hash.
|
238
|
-
def get_public_stemcell_list
|
239
|
-
@http_client = HTTPClient.new
|
240
|
-
response = @http_client.get(PUBLIC_STEMCELL_INDEX_URL)
|
241
|
-
status_code = response.http_header.status_code
|
242
|
-
if status_code != HTTP::Status::OK
|
243
|
-
err("Received HTTP #{status_code} from #{PUBLIC_STEMCELL_INDEX_URL}.")
|
244
|
-
end
|
245
|
-
Psych.load(response.body)
|
246
|
-
end
|
247
|
-
|
248
155
|
end
|
249
156
|
end
|
@@ -3,9 +3,9 @@ require 'cli/download_with_progress'
|
|
3
3
|
|
4
4
|
module Bosh::Cli
|
5
5
|
class PublicStemcellPresenter
|
6
|
-
def initialize(ui)
|
6
|
+
def initialize(ui, public_stemcell_index)
|
7
7
|
@ui = ui
|
8
|
-
@public_stemcell_index =
|
8
|
+
@public_stemcell_index = public_stemcell_index
|
9
9
|
end
|
10
10
|
|
11
11
|
def list(options)
|
data/lib/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bosh_cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.0.pre.
|
4
|
+
version: 1.5.0.pre.1337
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,7 +18,7 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.5.0.pre.
|
21
|
+
version: 1.5.0.pre.1337
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 1.5.0.pre.
|
29
|
+
version: 1.5.0.pre.1337
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
31
|
name: json_pure
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,7 +114,7 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ~>
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: 1.5.0.pre.
|
117
|
+
version: 1.5.0.pre.1337
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -122,7 +122,7 @@ dependencies:
|
|
122
122
|
requirements:
|
123
123
|
- - ~>
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: 1.5.0.pre.
|
125
|
+
version: 1.5.0.pre.1337
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: net-ssh
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,7 +221,7 @@ dependencies:
|
|
221
221
|
version: '0'
|
222
222
|
description: ! 'BOSH CLI
|
223
223
|
|
224
|
-
|
224
|
+
9923ad'
|
225
225
|
email: support@cloudfoundry.com
|
226
226
|
executables:
|
227
227
|
- bosh
|