vmc 0.4.0.beta.13 → 0.4.0.beta.14
Sign up to get free protection for your applications and to get access to all the features.
- data/vmc-ng/lib/vmc/cli/app.rb +95 -22
- data/vmc-ng/lib/vmc/cli/start.rb +230 -89
- data/vmc-ng/lib/vmc/cli.rb +46 -50
- data/vmc-ng/lib/vmc/detect.rb +7 -12
- data/vmc-ng/lib/vmc/version.rb +1 -1
- metadata +7 -7
data/vmc-ng/lib/vmc/cli/app.rb
CHANGED
@@ -40,10 +40,18 @@ module VMC
|
|
40
40
|
input :framework, :desc => "Filter by framework regexp"
|
41
41
|
input :url, :desc => "Filter by url regexp"
|
42
42
|
def apps(input)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
if v2?
|
44
|
+
space = client.current_space
|
45
|
+
apps =
|
46
|
+
with_progress("Getting applications in #{c(space.name, :name)}") do
|
47
|
+
space.apps
|
48
|
+
end
|
49
|
+
else
|
50
|
+
apps =
|
51
|
+
with_progress("Getting applications") do
|
52
|
+
client.apps
|
53
|
+
end
|
54
|
+
end
|
47
55
|
|
48
56
|
if apps.empty? and !quiet?
|
49
57
|
puts ""
|
@@ -107,34 +115,51 @@ module VMC
|
|
107
115
|
|
108
116
|
name = input[:name] if input[:name]
|
109
117
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
118
|
+
exists =
|
119
|
+
if v2?
|
120
|
+
client.current_space.apps.find { |a| a.name == name }
|
121
|
+
elsif client.app(name).exists?
|
122
|
+
client.app(name)
|
123
|
+
end
|
115
124
|
|
116
|
-
if
|
117
|
-
upload_app(
|
118
|
-
invoke :restart, :name =>
|
125
|
+
if exists
|
126
|
+
upload_app(exists, path)
|
127
|
+
invoke :restart, :name => exists.name if input[:restart]
|
119
128
|
return
|
120
129
|
end
|
121
130
|
|
131
|
+
detector = Detector.new(client, path)
|
132
|
+
frameworks = detector.all_frameworks
|
133
|
+
detected, default = detector.frameworks
|
134
|
+
|
135
|
+
app = client.app
|
136
|
+
app.name = name
|
137
|
+
app.space = client.current_space if v2?
|
122
138
|
app.total_instances = input[:instances]
|
123
139
|
|
140
|
+
framework_names = frameworks.collect(&:name).sort
|
124
141
|
if detected.empty?
|
125
|
-
|
142
|
+
framework_name = input[:framework, framework_names, nil]
|
126
143
|
else
|
127
|
-
|
128
|
-
|
144
|
+
detected_names = detected.collect(&:name).sort
|
145
|
+
framework_name =
|
146
|
+
input[:framework, detected_names + ["other"], default]
|
147
|
+
|
148
|
+
if framework_name == "other"
|
129
149
|
input.forget(:framework)
|
130
|
-
|
150
|
+
framework_name = input[:framework, framework_names, nil]
|
131
151
|
end
|
132
152
|
end
|
133
153
|
|
134
|
-
|
135
|
-
|
154
|
+
framework = frameworks.find { |f| f.name == framework_name }
|
155
|
+
|
156
|
+
runtimes = v2? ? client.runtimes : framework.runtimes
|
157
|
+
runtime_name = input[:runtime, runtimes.collect(&:name).sort]
|
158
|
+
runtime = runtimes.find { |r| r.name == runtime_name }
|
136
159
|
|
137
|
-
|
160
|
+
fail "Invalid framework '#{input[:framework]}'" unless framework
|
161
|
+
|
162
|
+
fail "Invalid runtime '#{input[:runtime]}'" unless runtime
|
138
163
|
|
139
164
|
app.framework = framework
|
140
165
|
app.runtime = runtime
|
@@ -155,7 +180,7 @@ module VMC
|
|
155
180
|
app.memory = megabytes(input[:memory, framework, runtime])
|
156
181
|
|
157
182
|
bindings = []
|
158
|
-
if input[:create_services] && !force?
|
183
|
+
if !v2? && input[:create_services] && !force?
|
159
184
|
services = client.system_services
|
160
185
|
|
161
186
|
while true
|
@@ -188,7 +213,7 @@ module VMC
|
|
188
213
|
end
|
189
214
|
end
|
190
215
|
|
191
|
-
if input[:bind_services] && !force?
|
216
|
+
if !v2? && input[:bind_services] && !force?
|
192
217
|
services = client.services.collect(&:name)
|
193
218
|
|
194
219
|
while true
|
@@ -776,7 +801,7 @@ module VMC
|
|
776
801
|
|
777
802
|
puts "#{c(a.name, :name)}: #{status}"
|
778
803
|
|
779
|
-
puts " platform: #{b(a.framework)} on #{b(a.runtime)}"
|
804
|
+
puts " platform: #{b(a.framework.name)} on #{b(a.runtime.name)}"
|
780
805
|
|
781
806
|
print " usage: #{b(human_size(a.memory * 1024 * 1024, 0))}"
|
782
807
|
print " #{c(IS_UTF8 ? "\xc3\x97" : "x", :dim)} #{b(a.total_instances)}"
|
@@ -793,6 +818,10 @@ module VMC
|
|
793
818
|
end
|
794
819
|
|
795
820
|
def upload_app(app, path)
|
821
|
+
if v2?
|
822
|
+
fail "V2 API currently does not support uploading or starting apps."
|
823
|
+
end
|
824
|
+
|
796
825
|
with_progress("Uploading #{c(app.name, :name)}") do
|
797
826
|
app.upload(path)
|
798
827
|
end
|
@@ -922,5 +951,49 @@ module VMC
|
|
922
951
|
end
|
923
952
|
end
|
924
953
|
end
|
954
|
+
|
955
|
+
def usage(used, limit)
|
956
|
+
"#{b(human_size(used))} of #{b(human_size(limit, 0))}"
|
957
|
+
end
|
958
|
+
|
959
|
+
def percentage(num, low = 50, mid = 70)
|
960
|
+
color =
|
961
|
+
if num <= low
|
962
|
+
:good
|
963
|
+
elsif num <= mid
|
964
|
+
:warning
|
965
|
+
else
|
966
|
+
:bad
|
967
|
+
end
|
968
|
+
|
969
|
+
c(format("%.1f\%", num), color)
|
970
|
+
end
|
971
|
+
|
972
|
+
def megabytes(str)
|
973
|
+
if str =~ /T$/i
|
974
|
+
str.to_i * 1024 * 1024
|
975
|
+
elsif str =~ /G$/i
|
976
|
+
str.to_i * 1024
|
977
|
+
elsif str =~ /M$/i
|
978
|
+
str.to_i
|
979
|
+
elsif str =~ /K$/i
|
980
|
+
str.to_i / 1024
|
981
|
+
else # assume megabytes
|
982
|
+
str.to_i
|
983
|
+
end
|
984
|
+
end
|
985
|
+
|
986
|
+
def human_size(num, precision = 1)
|
987
|
+
sizes = ["G", "M", "K"]
|
988
|
+
sizes.each.with_index do |suf, i|
|
989
|
+
pow = sizes.size - i
|
990
|
+
unit = 1024 ** pow
|
991
|
+
if num >= unit
|
992
|
+
return format("%.#{precision}f%s", num / unit, suf)
|
993
|
+
end
|
994
|
+
end
|
995
|
+
|
996
|
+
format("%.#{precision}fB", num)
|
997
|
+
end
|
925
998
|
end
|
926
999
|
end
|
data/vmc-ng/lib/vmc/cli/start.rb
CHANGED
@@ -10,100 +10,89 @@ module VMC
|
|
10
10
|
:desc => "List supported services"
|
11
11
|
input :frameworks, :type => :boolean,
|
12
12
|
:desc => "List supported frameworks"
|
13
|
+
input(:all, :type => :boolean, :alias => "-a",
|
14
|
+
:desc => "Show all information")
|
13
15
|
def info(input)
|
14
|
-
|
15
|
-
with_progress("Getting target information") do
|
16
|
-
client.info
|
17
|
-
end
|
18
|
-
|
19
|
-
authorized = !!info["frameworks"]
|
20
|
-
|
21
|
-
if input[:runtimes]
|
22
|
-
raise NotAuthorized unless authorized
|
16
|
+
all = input[:all]
|
23
17
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
runtimes
|
18
|
+
if all || input[:runtimes]
|
19
|
+
runtimes =
|
20
|
+
with_progress("Getting runtimes") do
|
21
|
+
client.runtimes
|
28
22
|
end
|
29
|
-
|
30
|
-
|
31
|
-
runtimes = runtimes.values.sort_by { |x| x["name"] }
|
23
|
+
end
|
32
24
|
|
33
|
-
|
34
|
-
|
35
|
-
|
25
|
+
if all || input[:services]
|
26
|
+
services =
|
27
|
+
with_progress("Getting services") do
|
28
|
+
client.services
|
36
29
|
end
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
runtimes.each do |r|
|
41
|
-
puts ""
|
42
|
-
puts "#{c(r["name"], :name)}:"
|
43
|
-
puts " version: #{b(r["version"])}"
|
44
|
-
puts " description: #{b(r["description"])}"
|
45
|
-
end
|
30
|
+
end
|
46
31
|
|
47
|
-
|
32
|
+
if all || input[:frameworks]
|
33
|
+
frameworks =
|
34
|
+
with_progress("Getting frameworks") do
|
35
|
+
client.frameworks
|
36
|
+
end
|
48
37
|
end
|
49
38
|
|
50
|
-
|
51
|
-
raise NotAuthorized unless authorized
|
39
|
+
info = client.info
|
52
40
|
|
53
|
-
|
41
|
+
showing_any = runtimes || services || frameworks
|
54
42
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
43
|
+
unless !all && showing_any
|
44
|
+
puts "" if showing_any
|
45
|
+
puts info[:description]
|
46
|
+
puts ""
|
47
|
+
puts "target: #{b(client.target)}"
|
48
|
+
puts " version: #{info[:version]}"
|
49
|
+
puts " support: #{info[:support]}"
|
59
50
|
|
60
|
-
|
51
|
+
if user = client.current_user
|
52
|
+
puts ""
|
53
|
+
puts "user: #{b(user.email || user.id)}"
|
61
54
|
end
|
55
|
+
end
|
62
56
|
|
63
|
-
|
57
|
+
if runtimes
|
58
|
+
unless quiet?
|
64
59
|
puts ""
|
65
|
-
puts "
|
66
|
-
puts " versions: #{meta[:versions].join ", "}"
|
67
|
-
puts " description: #{meta[:description]}"
|
68
|
-
puts " type: #{meta[:type]}"
|
60
|
+
puts "runtimes:"
|
69
61
|
end
|
70
62
|
|
71
|
-
|
63
|
+
puts " #{c("none", :dim)}" if runtimes.empty? && !quiet?
|
64
|
+
|
65
|
+
runtimes.each.with_index do |r, i|
|
66
|
+
display_runtime(r)
|
67
|
+
puts "" unless quiet? || i + 1 == runtimes.size
|
68
|
+
end
|
72
69
|
end
|
73
70
|
|
74
|
-
if
|
75
|
-
|
71
|
+
if services
|
72
|
+
unless quiet?
|
73
|
+
puts ""
|
74
|
+
puts "services:"
|
75
|
+
end
|
76
76
|
|
77
|
-
puts ""
|
77
|
+
puts " #{c("none", :dim)}" if services.empty? && !quiet?
|
78
78
|
|
79
|
-
|
80
|
-
|
79
|
+
services.each.with_index do |s, i|
|
80
|
+
display_service(s)
|
81
|
+
puts "" unless quiet? || i + 1 == services.size
|
81
82
|
end
|
82
|
-
|
83
|
-
return
|
84
83
|
end
|
85
84
|
|
86
|
-
|
85
|
+
if frameworks
|
86
|
+
unless quiet?
|
87
|
+
puts ""
|
88
|
+
puts "frameworks:"
|
89
|
+
end
|
87
90
|
|
88
|
-
|
89
|
-
puts ""
|
90
|
-
puts "target: #{b(client.target)}"
|
91
|
-
puts " version: #{info["version"]}"
|
92
|
-
puts " support: #{info["support"]}"
|
91
|
+
puts " #{c("none", :dim)}" if frameworks.empty? && !quiet?
|
93
92
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
puts " usage:"
|
98
|
-
|
99
|
-
limits = info["limits"]
|
100
|
-
info["usage"].each do |k, v|
|
101
|
-
m = limits[k]
|
102
|
-
if k == "memory"
|
103
|
-
puts " #{k}: #{usage(v * 1024 * 1024, m * 1024 * 1024)}"
|
104
|
-
else
|
105
|
-
puts " #{k}: #{b(v)} of #{b(m)} limit"
|
106
|
-
end
|
93
|
+
frameworks.each.with_index do |f, i|
|
94
|
+
display_framework(f)
|
95
|
+
puts "" unless quiet? || i + 1 == frameworks.size
|
107
96
|
end
|
108
97
|
end
|
109
98
|
end
|
@@ -113,72 +102,132 @@ module VMC
|
|
113
102
|
group :start
|
114
103
|
input :url, :argument => :optional,
|
115
104
|
:desc => "Target URL to switch to"
|
105
|
+
input(:organization, :aliases => ["--org", "-o"],
|
106
|
+
:desc => "Organization") { |choices|
|
107
|
+
ask("Organization", :choices => choices)
|
108
|
+
}
|
109
|
+
input(:space, :alias => "-s", :desc => "Space") { |choices|
|
110
|
+
ask("Space", :choices => choices)
|
111
|
+
}
|
116
112
|
def target(input)
|
117
|
-
if !input.given?(:url)
|
113
|
+
if !input.given?(:url) && !input.given?(:organization) &&
|
114
|
+
!input.given?(:space)
|
118
115
|
display_target
|
116
|
+
puts "Organization: #{c(client.current_organization.name, :name)}"
|
117
|
+
puts "Space: #{c(client.current_space.name, :name)}"
|
119
118
|
return
|
120
119
|
end
|
121
120
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
CFoundry::Client.new(target).info
|
121
|
+
if input.given?(:url)
|
122
|
+
target = sane_target_url(input[:url])
|
123
|
+
display = c(target.sub(/https?:\/\//, ""), :name)
|
124
|
+
with_progress("Setting target to #{display}") do
|
125
|
+
set_target(target)
|
128
126
|
end
|
129
127
|
|
130
|
-
|
128
|
+
return if force?
|
129
|
+
end
|
130
|
+
|
131
|
+
return unless v2?
|
132
|
+
|
133
|
+
unless client.logged_in?
|
134
|
+
invoke :login
|
135
|
+
@client = nil
|
131
136
|
end
|
137
|
+
|
138
|
+
info = target_info
|
139
|
+
|
140
|
+
select_org_and_space(input, info)
|
141
|
+
|
142
|
+
save_target_info(info)
|
132
143
|
end
|
133
144
|
|
134
145
|
|
135
146
|
desc "List known targets."
|
136
147
|
group :start, :hidden => true
|
137
148
|
def targets(input)
|
138
|
-
|
149
|
+
targets.each do |target, _|
|
139
150
|
puts target
|
151
|
+
# TODO: print org/space
|
140
152
|
end
|
141
153
|
end
|
142
154
|
|
143
155
|
|
156
|
+
def ask_prompt(type, label)
|
157
|
+
if type == "password"
|
158
|
+
options = { :echo => "*", :forget => true }
|
159
|
+
else
|
160
|
+
options = {}
|
161
|
+
end
|
162
|
+
|
163
|
+
ask(label, options)
|
164
|
+
end
|
165
|
+
|
166
|
+
def ask_prompts(credentials, prompts)
|
167
|
+
prompts.each do |name, meta|
|
168
|
+
type, label = meta
|
169
|
+
credentials[name] ||= ask_prompt(type, label)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
144
173
|
desc "Authenticate with the target"
|
145
174
|
group :start
|
146
|
-
input
|
147
|
-
|
148
|
-
}
|
175
|
+
input :username, :alias => "--email", :argument => :optional,
|
176
|
+
:desc => "Account email"
|
149
177
|
input :password, :desc => "Account password"
|
150
|
-
|
178
|
+
input(:organization, :aliases => ["--org", "-o"],
|
179
|
+
:desc => "Organization") { |choices|
|
180
|
+
ask("Organization", :choices => choices)
|
181
|
+
}
|
182
|
+
input(:space, :alias => "-s", :desc => "Space") { |choices|
|
183
|
+
ask("Space", :choices => choices)
|
184
|
+
}
|
151
185
|
def login(input)
|
152
186
|
unless quiet?
|
153
187
|
display_target
|
154
188
|
puts ""
|
155
189
|
end
|
156
190
|
|
157
|
-
|
158
|
-
|
191
|
+
credentials =
|
192
|
+
{ :username => input[:username],
|
193
|
+
:password => input[:password]
|
194
|
+
}
|
195
|
+
|
196
|
+
prompts = client.login_prompts
|
197
|
+
|
198
|
+
# ask username first
|
199
|
+
if prompts.key? :username
|
200
|
+
type, label = prompts.delete :username
|
201
|
+
credentials[:username] ||= ask_prompt(type, label)
|
202
|
+
end
|
203
|
+
|
204
|
+
info = target_info
|
159
205
|
|
160
206
|
authenticated = false
|
161
207
|
failed = false
|
162
208
|
until authenticated
|
163
209
|
unless force?
|
164
|
-
|
165
|
-
password = ask("Password", :echo => "*", :forget => true)
|
166
|
-
end
|
210
|
+
ask_prompts(credentials, prompts)
|
167
211
|
end
|
168
212
|
|
169
213
|
with_progress("Authenticating") do |s|
|
170
214
|
begin
|
171
|
-
|
215
|
+
info[:token] = client.login(credentials)
|
172
216
|
authenticated = true
|
173
217
|
rescue CFoundry::Denied
|
174
218
|
return if force?
|
175
219
|
|
176
220
|
s.fail do
|
177
221
|
failed = true
|
222
|
+
credentials.delete(:password)
|
178
223
|
end
|
179
224
|
end
|
180
225
|
end
|
181
226
|
end
|
227
|
+
|
228
|
+
select_org_and_space(input, info) if v2?
|
229
|
+
|
230
|
+
save_target_info(info)
|
182
231
|
ensure
|
183
232
|
exit_status 1 if not authenticated
|
184
233
|
end
|
@@ -188,7 +237,7 @@ module VMC
|
|
188
237
|
group :start
|
189
238
|
def logout(input)
|
190
239
|
with_progress("Logging out") do
|
191
|
-
|
240
|
+
remove_target_info
|
192
241
|
end
|
193
242
|
end
|
194
243
|
|
@@ -248,5 +297,97 @@ module VMC
|
|
248
297
|
puts "Target: #{c(client.target, :name)}"
|
249
298
|
end
|
250
299
|
end
|
300
|
+
|
301
|
+
def display_runtime(r)
|
302
|
+
if quiet?
|
303
|
+
puts r.name
|
304
|
+
else
|
305
|
+
puts " #{c(r.name, :name)}:"
|
306
|
+
|
307
|
+
puts " description: #{b(r.description)}" if r.description
|
308
|
+
|
309
|
+
# TODO: probably won't have this in final version
|
310
|
+
apps = r.apps.collect { |a| c(a.name, :name) }
|
311
|
+
app_list = apps.empty? ? c("none", :dim) : apps.join(", ")
|
312
|
+
puts " apps: #{app_list}"
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
def display_service(s)
|
317
|
+
if quiet?
|
318
|
+
puts s.label
|
319
|
+
else
|
320
|
+
puts " #{c(s.label, :name)}:"
|
321
|
+
puts " description: #{s.description}"
|
322
|
+
puts " version: #{s.version}"
|
323
|
+
puts " provider: #{s.provider}"
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
def display_framework(f)
|
328
|
+
if quiet?
|
329
|
+
puts f.name
|
330
|
+
else
|
331
|
+
puts " #{c(f.name, :name)}:"
|
332
|
+
puts " description: #{b(f.description)}" if f.description
|
333
|
+
|
334
|
+
# TODO: probably won't show this in final version; just for show
|
335
|
+
apps = f.apps.collect { |a| c(a.name, :name) }
|
336
|
+
puts " apps: #{apps.empty? ? c("none", :dim) : apps.join(", ")}"
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
def org_valid?(id, user = client.current_user)
|
341
|
+
return false unless id
|
342
|
+
client.organization(id).users.include? user
|
343
|
+
rescue CFoundry::APIError
|
344
|
+
false
|
345
|
+
end
|
346
|
+
|
347
|
+
def space_valid?(id, user = client.current_user)
|
348
|
+
return false unless id
|
349
|
+
client.space(id).developers.include? user
|
350
|
+
rescue CFoundry::APIError
|
351
|
+
false
|
352
|
+
end
|
353
|
+
|
354
|
+
def select_org_and_space(input, info)
|
355
|
+
if input.given?(:organization) || !org_valid?(info[:organization])
|
356
|
+
orgs = client.current_user.organizations
|
357
|
+
fail "No organizations!" if orgs.empty?
|
358
|
+
|
359
|
+
if orgs.size == 1 && !input.given?(:organization)
|
360
|
+
org = orgs.first
|
361
|
+
else
|
362
|
+
org_name = input[:organization, orgs.collect(&:name).sort]
|
363
|
+
org = orgs.find { |o| o.name == org_name }
|
364
|
+
fail "Unknown organization '#{org_name}'" unless org
|
365
|
+
end
|
366
|
+
|
367
|
+
info[:organization] = org.id
|
368
|
+
else
|
369
|
+
org = client.current_organization
|
370
|
+
end
|
371
|
+
|
372
|
+
# switching org probably means switching space
|
373
|
+
if input.given?(:organization) || input.given?(:space) || \
|
374
|
+
!space_valid?(info[:space])
|
375
|
+
spaces = client.current_user.spaces.select do |s|
|
376
|
+
s.organization.id == org.id
|
377
|
+
end
|
378
|
+
|
379
|
+
fail "No spaces!" if spaces.empty?
|
380
|
+
|
381
|
+
if spaces.size == 1 && !input.given?(:space)
|
382
|
+
space = spaces.first
|
383
|
+
else
|
384
|
+
space_name = input[:space, spaces.collect(&:name).sort]
|
385
|
+
space = spaces.find { |s| s.name == space_name }
|
386
|
+
fail "Unknown space '#{space_name}'" unless space
|
387
|
+
end
|
388
|
+
|
389
|
+
info[:space] = space.id
|
390
|
+
end
|
391
|
+
end
|
251
392
|
end
|
252
393
|
end
|
data/vmc-ng/lib/vmc/cli.rb
CHANGED
@@ -40,7 +40,7 @@ module VMC
|
|
40
40
|
option(:script)
|
41
41
|
}
|
42
42
|
|
43
|
-
option(:script, :
|
43
|
+
option(:script, :type => :boolean,
|
44
44
|
:desc => "Shortcut for --quiet and --force") {
|
45
45
|
!$stdout.tty?
|
46
46
|
}
|
@@ -183,7 +183,7 @@ module VMC
|
|
183
183
|
@client = nil
|
184
184
|
end
|
185
185
|
|
186
|
-
def
|
186
|
+
def targets_info
|
187
187
|
new_toks = File.expand_path(VMC::TOKENS_FILE)
|
188
188
|
old_toks = File.expand_path(VMC::OLD_TOKENS_FILE)
|
189
189
|
|
@@ -196,11 +196,17 @@ module VMC
|
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
199
|
-
def
|
200
|
-
|
199
|
+
def target_info
|
200
|
+
info = targets_info[client_target]
|
201
|
+
|
202
|
+
if info.is_a? String
|
203
|
+
{ :token => info }
|
204
|
+
else
|
205
|
+
info || {}
|
206
|
+
end
|
201
207
|
end
|
202
208
|
|
203
|
-
def
|
209
|
+
def save_targets(ts)
|
204
210
|
ensure_config_dir
|
205
211
|
|
206
212
|
File.open(File.expand_path(VMC::TOKENS_FILE), "w") do |io|
|
@@ -208,69 +214,59 @@ module VMC
|
|
208
214
|
end
|
209
215
|
end
|
210
216
|
|
211
|
-
def
|
212
|
-
ts =
|
213
|
-
ts[client_target] =
|
214
|
-
|
217
|
+
def save_target_info(info)
|
218
|
+
ts = targets_info
|
219
|
+
ts[client_target] = info
|
220
|
+
save_targets(ts)
|
215
221
|
end
|
216
222
|
|
217
|
-
def
|
218
|
-
ts =
|
223
|
+
def remove_target_info
|
224
|
+
ts = target_info
|
219
225
|
ts.delete client_target
|
220
|
-
|
226
|
+
save_targets(ts)
|
227
|
+
end
|
228
|
+
|
229
|
+
def v2?
|
230
|
+
client.is_a?(CFoundry::V2::Client)
|
221
231
|
end
|
222
232
|
|
223
233
|
def client
|
224
234
|
return @client if @client
|
225
235
|
|
226
|
-
|
236
|
+
info = target_info
|
237
|
+
|
238
|
+
@client =
|
239
|
+
case info[:version]
|
240
|
+
when 2
|
241
|
+
CFoundry::V2::Client.new(client_target, info[:token])
|
242
|
+
when 1
|
243
|
+
CFoundry::V1::Client.new(client_target, info[:token])
|
244
|
+
else
|
245
|
+
CFoundry::Client.new(client_target, info[:token])
|
246
|
+
end
|
247
|
+
|
227
248
|
@client.proxy = option(:proxy)
|
228
249
|
@client.trace = option(:trace)
|
229
|
-
@client
|
230
|
-
end
|
231
|
-
|
232
|
-
def usage(used, limit)
|
233
|
-
"#{b(human_size(used))} of #{b(human_size(limit, 0))}"
|
234
|
-
end
|
235
250
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
elsif num <= mid
|
241
|
-
:warning
|
251
|
+
info[:version] ||=
|
252
|
+
case @client
|
253
|
+
when CFoundry::V2::Client
|
254
|
+
2
|
242
255
|
else
|
243
|
-
|
256
|
+
1
|
244
257
|
end
|
245
258
|
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
def megabytes(str)
|
250
|
-
if str =~ /T$/i
|
251
|
-
str.to_i * 1024 * 1024
|
252
|
-
elsif str =~ /G$/i
|
253
|
-
str.to_i * 1024
|
254
|
-
elsif str =~ /M$/i
|
255
|
-
str.to_i
|
256
|
-
elsif str =~ /K$/i
|
257
|
-
str.to_i / 1024
|
258
|
-
else # assume megabytes
|
259
|
-
str.to_i
|
259
|
+
if org = info[:organization]
|
260
|
+
@client.current_organization = @client.organization(org)
|
260
261
|
end
|
261
|
-
end
|
262
262
|
|
263
|
-
|
264
|
-
|
265
|
-
sizes.each.with_index do |suf, i|
|
266
|
-
pow = sizes.size - i
|
267
|
-
unit = 1024 ** pow
|
268
|
-
if num >= unit
|
269
|
-
return format("%.#{precision}f%s", num / unit, suf)
|
270
|
-
end
|
263
|
+
if space = info[:space]
|
264
|
+
@client.current_space = @client.space(space)
|
271
265
|
end
|
272
266
|
|
273
|
-
|
267
|
+
save_target_info(info)
|
268
|
+
|
269
|
+
@client
|
274
270
|
end
|
275
271
|
end
|
276
272
|
end
|
data/vmc-ng/lib/vmc/detect.rb
CHANGED
@@ -6,8 +6,7 @@ module VMC
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def all_frameworks
|
9
|
-
|
10
|
-
info["frameworks"] || {}
|
9
|
+
@client.frameworks
|
11
10
|
end
|
12
11
|
|
13
12
|
def find_top(entries)
|
@@ -30,16 +29,14 @@ module VMC
|
|
30
29
|
end
|
31
30
|
|
32
31
|
def frameworks
|
33
|
-
|
34
|
-
|
35
|
-
matches = {}
|
36
|
-
all_frameworks.each do |name, meta|
|
32
|
+
matches = []
|
33
|
+
all_frameworks.each do |framework|
|
37
34
|
matched = false
|
38
35
|
|
39
36
|
# e.g. standalone has no detection
|
40
|
-
next if
|
37
|
+
next if framework.detection.nil?
|
41
38
|
|
42
|
-
|
39
|
+
framework.detection.first.each do |file, match|
|
43
40
|
files =
|
44
41
|
if File.file? @path
|
45
42
|
if File.fnmatch(file, @path)
|
@@ -76,13 +73,11 @@ module VMC
|
|
76
73
|
end
|
77
74
|
end
|
78
75
|
|
79
|
-
if matched
|
80
|
-
matches[name] = meta
|
81
|
-
end
|
76
|
+
matches << framework if matched
|
82
77
|
end
|
83
78
|
|
84
79
|
if matches.size == 1
|
85
|
-
default = matches.
|
80
|
+
default = matches.first
|
86
81
|
end
|
87
82
|
|
88
83
|
[matches, default]
|
data/vmc-ng/lib/vmc/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vmc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 62196479
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
9
|
- 0
|
10
10
|
- beta
|
11
|
-
-
|
12
|
-
version: 0.4.0.beta.
|
11
|
+
- 14
|
12
|
+
version: 0.4.0.beta.14
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- VMware
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2012-07-
|
20
|
+
date: 2012-07-13 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: json_pure
|
@@ -252,9 +252,9 @@ dependencies:
|
|
252
252
|
hash: 19
|
253
253
|
segments:
|
254
254
|
- 0
|
255
|
-
-
|
256
|
-
-
|
257
|
-
version: 0.
|
255
|
+
- 3
|
256
|
+
- 0
|
257
|
+
version: 0.3.0
|
258
258
|
type: :runtime
|
259
259
|
version_requirements: *id014
|
260
260
|
- !ruby/object:Gem::Dependency
|