pi 0.1.27 → 0.1.28
Sign up to get free protection for your applications and to get access to all the features.
- data/README +253 -213
- data/lib/cli/choose_helper.rb +20 -25
- data/lib/cli/commands/apps.rb +31 -35
- data/lib/cli/commands/dns.rb +37 -13
- data/lib/cli/commands/projects.rb +2 -2
- data/lib/cli/commands/services.rb +8 -8
- data/lib/cli/commands/user.rb +5 -2
- data/lib/cli/runner.rb +17 -12
- data/lib/cli/usage.rb +4 -4
- data/lib/cli/version.rb +1 -1
- data/lib/pi/client.rb +12 -10
- metadata +4 -4
data/lib/cli/choose_helper.rb
CHANGED
@@ -88,7 +88,7 @@ module PI::Cli
|
|
88
88
|
if appid_or_appname =~ /^[1-9]\d*$/
|
89
89
|
appid = appid_or_appname
|
90
90
|
app = client.app_get_byid(appid)
|
91
|
-
err"The application is not found!" if app
|
91
|
+
err"The application is not found!" if app.nil?
|
92
92
|
return target_not_all, app, appid
|
93
93
|
elsif appid_or_appname == nil
|
94
94
|
if target.nil?
|
@@ -101,8 +101,11 @@ module PI::Cli
|
|
101
101
|
appname = appid_or_appname
|
102
102
|
err "Not enough arguments" if target == nil
|
103
103
|
if target != "all"
|
104
|
+
# targets = client.targets
|
105
|
+
# targets = targets.collect { |t| t[:name] }
|
106
|
+
# err "Invalid target" unless targets.include?(target)
|
104
107
|
app = client.app_search(target, appname)
|
105
|
-
err "The application '#{appname}' is not found!" if app
|
108
|
+
err "The application '#{appname}' is not found!" if app.nil?
|
106
109
|
return target_not_all, app, appid
|
107
110
|
else
|
108
111
|
apps = client.app_search_target_is_all(appname)
|
@@ -119,7 +122,7 @@ module PI::Cli
|
|
119
122
|
if appid_or_appname =~ /^[1-9]\d*$/
|
120
123
|
appid = appid_or_appname
|
121
124
|
app = client.app_get_byid(appid)
|
122
|
-
err"The application is not found!" if app
|
125
|
+
err"The application is not found!" if app.nil?
|
123
126
|
return app, appid
|
124
127
|
elsif appid_or_appname == nil
|
125
128
|
if target.nil?
|
@@ -131,8 +134,11 @@ module PI::Cli
|
|
131
134
|
else
|
132
135
|
appname = appid_or_appname
|
133
136
|
err "Not enough arguments" if target == nil
|
137
|
+
# targets = client.targets
|
138
|
+
# targets = targets.collect { |t| t[:name] }
|
139
|
+
# err "Invalid target" unless targets.include?(target)
|
134
140
|
app = client.app_search(target, appname)
|
135
|
-
err "The application '#{appname}' is not found!" if app
|
141
|
+
err "The application '#{appname}' is not found!" if app.nil?
|
136
142
|
return app, appid
|
137
143
|
end
|
138
144
|
end
|
@@ -169,22 +175,7 @@ module PI::Cli
|
|
169
175
|
|
170
176
|
def get_graceful(app)
|
171
177
|
graceful = @options[:graceful]
|
172
|
-
|
173
|
-
graceful = ask "Need graceful?", :default => DEFAULTS["graceful"] unless graceful
|
174
|
-
else
|
175
|
-
graceful = false
|
176
|
-
end
|
177
|
-
graceful = (graceful == true ? "true" : "false")
|
178
|
-
end
|
179
|
-
|
180
|
-
def get_lazy(app)
|
181
|
-
lazy = @options[:lazy]
|
182
|
-
if app[:action_for_change] == "restart"
|
183
|
-
lazy = ask "Need lazy?", :default => DEFAULTS["lazy"] unless lazy
|
184
|
-
else
|
185
|
-
lazy = false
|
186
|
-
end
|
187
|
-
lazy = (lazy == true ? "true" : "false")
|
178
|
+
graceful = ask "Need graceful?", :default => DEFAULTS["graceful"] unless graceful
|
188
179
|
end
|
189
180
|
|
190
181
|
# def check_status(uuid)
|
@@ -215,19 +206,23 @@ module PI::Cli
|
|
215
206
|
def check_envname_valid?(name)
|
216
207
|
#(name =~ /\b(?!vcap_|vmc_|VCAP_|VMC_)\D+\b/ && name.size <= 18) ? true : false
|
217
208
|
if name =~ /[0-9]/
|
218
|
-
display "Digital cannot be included in Env name"
|
209
|
+
display "Digital cannot be included in Env name".red
|
219
210
|
return false
|
220
211
|
end
|
221
212
|
if name =~ /^vcap_/i
|
222
|
-
display "Env name cannot be started with \"vcap_\" or \"VCAP_\""
|
213
|
+
display "Env name cannot be started with \"vcap_\" or \"VCAP_\"".red
|
223
214
|
return false
|
224
215
|
end
|
225
216
|
if name =~ /^vmc_/i
|
226
|
-
display "Env name cannot be started with \"vmc_\" or \"VMC_\""
|
217
|
+
display "Env name cannot be started with \"vmc_\" or \"VMC_\"".red
|
227
218
|
return false
|
228
219
|
end
|
229
|
-
if not name =~ /^[a-zA-Z\`\~\!\@\#\$\%\^\&\*\(\)\_\+\-\{\}]{0,18}$/
|
230
|
-
display "the input is illegal!"
|
220
|
+
# if not name =~ /^[a-zA-Z\`\~\!\@\#\$\%\^\&\*\(\)\_\+\-\{\}]{0,18}$/
|
221
|
+
# display "the input is illegal!".red
|
222
|
+
# return false
|
223
|
+
# end
|
224
|
+
if name.size > 18
|
225
|
+
display "Invalid name length. The max length of name is 18"
|
231
226
|
return false
|
232
227
|
end
|
233
228
|
return true
|
data/lib/cli/commands/apps.rb
CHANGED
@@ -31,7 +31,7 @@ module PI::Cli::Command
|
|
31
31
|
loop{
|
32
32
|
numPerPage = ask "Number per page"
|
33
33
|
if not numPerPage =~ /^[1-9]\d*$/
|
34
|
-
display "Invalid Number! Please input number from 1 to #{total_app}"
|
34
|
+
display "Invalid Number! Please input number from 1 to #{total_app}".red
|
35
35
|
numPerPage =nil
|
36
36
|
next
|
37
37
|
else
|
@@ -43,7 +43,7 @@ module PI::Cli::Command
|
|
43
43
|
loop{
|
44
44
|
pageNum = ask "Page number"
|
45
45
|
if not pageNum =~ /^[1-9]\d*$/
|
46
|
-
display "Invalid Number! Please input number from 1 to #{maxpage}"
|
46
|
+
display "Invalid Number! Please input number from 1 to #{maxpage}".red
|
47
47
|
pageNum =nil
|
48
48
|
next
|
49
49
|
else
|
@@ -86,11 +86,11 @@ module PI::Cli::Command
|
|
86
86
|
loop{
|
87
87
|
appname = ask "Application Name" unless appname
|
88
88
|
if not check_name_valid?(appname)
|
89
|
-
display "Invalid application name '#{appname}'."
|
89
|
+
display "Invalid application name '#{appname}'.".red
|
90
90
|
appname =nil
|
91
91
|
next
|
92
92
|
else if app_exists?(target, appname)
|
93
|
-
display "Application '#{appname}' already exists."
|
93
|
+
display "Application '#{appname}' already exists.".red
|
94
94
|
appname =nil
|
95
95
|
next
|
96
96
|
else
|
@@ -148,11 +148,11 @@ module PI::Cli::Command
|
|
148
148
|
loop{
|
149
149
|
instances = ask "How many instances(from 1 to #{max_instance})?", :default => DEFAULTS["instances"]
|
150
150
|
if not instances.to_s =~ /^[1-9]\d*$/
|
151
|
-
display "Invalid Number!"
|
151
|
+
display "Invalid Number!".red
|
152
152
|
instances =nil
|
153
153
|
next
|
154
154
|
else if instances < 1 || instances > max_instance
|
155
|
-
display "Invalid Number! Please input number from 1 to #{max_instance}"
|
155
|
+
display "Invalid Number! Please input number from 1 to #{max_instance}".red
|
156
156
|
instances =nil
|
157
157
|
next
|
158
158
|
else
|
@@ -163,16 +163,8 @@ module PI::Cli::Command
|
|
163
163
|
isDebug = false
|
164
164
|
isDebug = ask "Need debug?", :default => DEFAULTS["isDebug"] if deployType == "binary"
|
165
165
|
isDebug = (isDebug == false ? "no" : "yes")
|
166
|
-
graceful = false
|
167
|
-
lazy = false
|
168
166
|
choices = ["restart", "notify"]
|
169
167
|
action_for_change = ask"Reaction when service changed", :default => DEFAULTS["action_for_change"], :choices => choices, :indexed => true
|
170
|
-
if action_for_change == "restart"
|
171
|
-
graceful = ask "Need graceful?", :default => DEFAULTS["graceful"]
|
172
|
-
lazy = ask "Need lazy?", :default => DEFAULTS["lazy"]
|
173
|
-
end
|
174
|
-
graceful = (graceful == false ? "false" : "true")
|
175
|
-
lazy = (lazy == false ? "false" : "true")
|
176
168
|
needMonitor = ask "Need monitor?", :default => DEFAULTS["needMonitor"]
|
177
169
|
needMonitor = (needMonitor == false ? "no" : "yes")
|
178
170
|
|
@@ -189,8 +181,6 @@ module PI::Cli::Command
|
|
189
181
|
:tag => tag,
|
190
182
|
:isDebug => isDebug,
|
191
183
|
:action_for_change => action_for_change,
|
192
|
-
:graceful => graceful,
|
193
|
-
:lazy => lazy,
|
194
184
|
:needMonitor => needMonitor
|
195
185
|
}
|
196
186
|
|
@@ -250,7 +240,7 @@ module PI::Cli::Command
|
|
250
240
|
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
251
241
|
if target_not_all
|
252
242
|
appid = (appid == nil ? app[:id] : appid)
|
253
|
-
return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already stopped.".yellow if app[:status] == "STOPPED"
|
243
|
+
# return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already stopped.".yellow if app[:status] == "STOPPED"
|
254
244
|
do_stop_app(app, appid)
|
255
245
|
else
|
256
246
|
app.each do |a|
|
@@ -275,7 +265,7 @@ module PI::Cli::Command
|
|
275
265
|
|
276
266
|
def scale_app(appid_or_appname=nil)
|
277
267
|
client.check_login_status
|
278
|
-
instance = @options[:instance]
|
268
|
+
instance = @options[:instance]
|
279
269
|
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
280
270
|
appid = (appid == nil ? app[:id] : appid)
|
281
271
|
target_memory = client.target_memory(app[:targetName])
|
@@ -285,11 +275,11 @@ module PI::Cli::Command
|
|
285
275
|
loop{
|
286
276
|
instance = ask "Current instance: #{app[:instances]}, Instance number" unless instance
|
287
277
|
if not instance.to_s =~ /^[1-9]\d*$/
|
288
|
-
display "Invalid Number!"
|
278
|
+
display "Invalid Number!".red
|
289
279
|
instance =nil
|
290
280
|
next
|
291
281
|
else if instance.to_i < 1 || instance.to_i > max_instance
|
292
|
-
display "Invalid Number! Please input number from 1 to #{max_instance}"
|
282
|
+
display "Invalid Number! Please input number from 1 to #{max_instance}".red
|
293
283
|
instance =nil
|
294
284
|
next
|
295
285
|
else
|
@@ -297,8 +287,8 @@ module PI::Cli::Command
|
|
297
287
|
end
|
298
288
|
end
|
299
289
|
}
|
300
|
-
err "Don't need scale application" if instance == app[:instances].to_s
|
301
|
-
graceful = get_graceful(app)
|
290
|
+
err "Don't need scale application" if instance.to_s == app[:instances].to_s
|
291
|
+
# graceful = get_graceful(app)
|
302
292
|
display "Scaling application: ",false
|
303
293
|
|
304
294
|
t = Thread.new do
|
@@ -309,7 +299,7 @@ module PI::Cli::Command
|
|
309
299
|
end
|
310
300
|
end
|
311
301
|
|
312
|
-
tmp = client.scale_app(appid, instance
|
302
|
+
tmp = client.scale_app(appid, instance)
|
313
303
|
uuid = tmp[1]
|
314
304
|
result = check_status(uuid)
|
315
305
|
Thread.kill(t)
|
@@ -323,18 +313,25 @@ module PI::Cli::Command
|
|
323
313
|
if app[:deployType] == "git"
|
324
314
|
tags = client.project_tags(app[:projectId])
|
325
315
|
err "No tags!" if tags.nil? || tags.empty?
|
326
|
-
|
316
|
+
if tag
|
317
|
+
err "Invalid tag" unless tags.include?(tag)
|
318
|
+
else
|
319
|
+
tag = ask "Select Tag", :choices => tags, :indexed => true
|
320
|
+
end
|
327
321
|
err "Don't need update application!" if tag == app[:tag]
|
328
|
-
display "Selected tag: ",false
|
329
|
-
display "#{tag}"
|
330
322
|
else
|
331
323
|
tags = client.project_binary(app[:projectId])
|
332
324
|
err "No version!" if tags.nil? || tags.empty?
|
333
|
-
|
325
|
+
if tag
|
326
|
+
tags = tags.collect { |b| b[:versionName] }
|
327
|
+
err "Invalid version" unless tags.include?(tag)
|
328
|
+
else
|
329
|
+
tag = ask "Select Version", :choices => tags.collect { |b| b[:versionName] }, :indexed => true
|
330
|
+
end
|
334
331
|
err "Don't need update application!" if tag == app[:tag]
|
335
332
|
end
|
336
333
|
graceful = get_graceful(app)
|
337
|
-
lazy = get_lazy(app)
|
334
|
+
# lazy = get_lazy(app)
|
338
335
|
display "Updating application: ",false
|
339
336
|
|
340
337
|
t = Thread.new do
|
@@ -345,7 +342,7 @@ module PI::Cli::Command
|
|
345
342
|
end
|
346
343
|
end
|
347
344
|
|
348
|
-
tmp = client.update_app(appid,tag,graceful
|
345
|
+
tmp = client.update_app(appid,tag,graceful)
|
349
346
|
uuid = tmp[1]
|
350
347
|
result = check_status(uuid)
|
351
348
|
Thread.kill(t)
|
@@ -394,11 +391,10 @@ module PI::Cli::Command
|
|
394
391
|
loop{
|
395
392
|
name = ask "Environment Name" unless name
|
396
393
|
if not check_envname_valid?(name)
|
397
|
-
#display "Invalid environment name '#{name}'."
|
398
394
|
name =nil
|
399
395
|
next
|
400
396
|
else if env_exists?(appid,name)
|
401
|
-
display "Environment '#{name}' already exists."
|
397
|
+
display "Environment '#{name}' already exists.".red
|
402
398
|
name =nil
|
403
399
|
next
|
404
400
|
else
|
@@ -409,7 +405,7 @@ module PI::Cli::Command
|
|
409
405
|
loop{
|
410
406
|
value = ask "Environment Value" unless value
|
411
407
|
if not check_envvalue_valid?(value)
|
412
|
-
display "Invalid environment value '#{value}'."
|
408
|
+
display "Invalid environment value '#{value}'.".red
|
413
409
|
value =nil
|
414
410
|
next
|
415
411
|
else
|
@@ -501,7 +497,7 @@ module PI::Cli::Command
|
|
501
497
|
|
502
498
|
def app_exists?(target, appname)
|
503
499
|
app = client.app_search(target,appname)
|
504
|
-
app
|
500
|
+
app.nil? ? false : true
|
505
501
|
end
|
506
502
|
|
507
503
|
def env_exists?(appid, envname)
|
@@ -533,7 +529,7 @@ module PI::Cli::Command
|
|
533
529
|
|
534
530
|
def do_restart_app(app, appid)
|
535
531
|
graceful = get_graceful(app)
|
536
|
-
lazy = get_lazy(app)
|
532
|
+
# lazy = get_lazy(app)
|
537
533
|
display "Restart application '#{app[:name]}'(target:#{app[:targetName]}): ",false
|
538
534
|
t = Thread.new do
|
539
535
|
loop do
|
@@ -542,7 +538,7 @@ module PI::Cli::Command
|
|
542
538
|
break unless t.alive?
|
543
539
|
end
|
544
540
|
end
|
545
|
-
tmp = client.restart_app(appid, graceful
|
541
|
+
tmp = client.restart_app(appid, graceful)
|
546
542
|
uuid = tmp[1]
|
547
543
|
result = check_status(uuid)
|
548
544
|
Thread.kill(t)
|
data/lib/cli/commands/dns.rb
CHANGED
@@ -27,13 +27,18 @@ module PI::Cli::Command
|
|
27
27
|
def map_dns(appid_or_appname=nil)
|
28
28
|
client.check_login_status
|
29
29
|
dnsname = @options[:dns]
|
30
|
+
if dnsname
|
31
|
+
dns_list = client.dns
|
32
|
+
dnsnames = dns_list.collect { |d| d[:name] }
|
33
|
+
err "Invalid dns name" unless dnsnames.include?(dnsname)
|
34
|
+
end
|
30
35
|
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
31
36
|
appid = (appid == nil ? app[:id] : appid)
|
32
37
|
dns = client.usable_dns(appid)
|
33
38
|
err "No usable dns!" if dns.nil? || dns.empty?
|
34
|
-
if dnsname
|
35
|
-
|
36
|
-
err "Invalid dns name" unless
|
39
|
+
if dnsname
|
40
|
+
usable_dnsnames = dns.collect { |d| d[:name] }
|
41
|
+
err "Invalid dns name" unless usable_dnsnames.include?(dnsname)
|
37
42
|
tmp = dnsname.split(",")
|
38
43
|
manifest = Array.new
|
39
44
|
tmp.each do |t|
|
@@ -183,7 +188,15 @@ module PI::Cli::Command
|
|
183
188
|
client.check_login_status
|
184
189
|
target = @options[:target]
|
185
190
|
continent = @options[:continent]
|
191
|
+
if continent
|
192
|
+
continents = client.dns_continents
|
193
|
+
err "Invalid continent" unless continents.has_key?(continent.to_sym)
|
194
|
+
end
|
186
195
|
country = @options[:country]
|
196
|
+
if country && continent
|
197
|
+
countries = client.dns_country(continent)
|
198
|
+
err "Invalid country" unless countries.has_key?(country.to_sym)
|
199
|
+
end
|
187
200
|
unless dnsid
|
188
201
|
dnsid = choose_dnsid
|
189
202
|
end
|
@@ -193,24 +206,35 @@ module PI::Cli::Command
|
|
193
206
|
end
|
194
207
|
unless continent
|
195
208
|
continents = client.dns_continents
|
209
|
+
err "No continents" if continents.nil? || continents.empty?
|
196
210
|
tmp = continents.values
|
197
211
|
tmp.sort! {|a, b| a <=> b }
|
198
212
|
continent = ask"Select continent", :choices => tmp.collect { |t| t }, :indexed => true
|
199
213
|
display "Select continent: #{continent}"
|
200
214
|
continent = continents.invert["#{continent}"]
|
201
215
|
end
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
216
|
+
if continent.to_s == "DEFAULT"
|
217
|
+
manifest = {
|
218
|
+
# :continentName => continent,
|
219
|
+
:continentCode => continent,
|
220
|
+
:countryCode => "DEFAULT"
|
221
|
+
}
|
222
|
+
else
|
223
|
+
unless country
|
224
|
+
countries = client.dns_country(continent)
|
225
|
+
err "No countries" if countries.nil? || countries.empty?
|
226
|
+
tmp = countries.values
|
227
|
+
tmp.sort! {|a, b| a <=> b }
|
228
|
+
country = ask"Select country", :choices => tmp.collect { |t| t }, :indexed => true
|
229
|
+
display "Select country: #{country}"
|
230
|
+
country = countries.invert["#{country}"]
|
231
|
+
end
|
232
|
+
manifest = {
|
233
|
+
# :continentName => continent,
|
234
|
+
:continentCode => continent,
|
212
235
|
:countryCode => country
|
213
236
|
}
|
237
|
+
end
|
214
238
|
client.register_dns(dnsid, target, manifest)
|
215
239
|
display "OK".green
|
216
240
|
end
|
@@ -95,7 +95,7 @@ module PI::Cli::Command
|
|
95
95
|
|
96
96
|
github_info = client.github_info
|
97
97
|
|
98
|
-
if github_info
|
98
|
+
if github_info.nil?
|
99
99
|
manifest = {
|
100
100
|
:name => "#{project}",
|
101
101
|
:runtime => "#{runtime}",
|
@@ -327,7 +327,7 @@ module PI::Cli::Command
|
|
327
327
|
|
328
328
|
def project_exists?(projectname)
|
329
329
|
project = client.project_search(projectname)
|
330
|
-
project
|
330
|
+
project.nil? ? false : true
|
331
331
|
end
|
332
332
|
|
333
333
|
|
@@ -39,8 +39,8 @@ module PI::Cli::Command
|
|
39
39
|
else
|
40
40
|
manifest = asks "Select services, indexed list?", :choices => services.collect { |s| s[:name] }, :indexed => true
|
41
41
|
end
|
42
|
-
graceful = get_graceful(app)
|
43
|
-
lazy = get_lazy(app)
|
42
|
+
# graceful = get_graceful(app)
|
43
|
+
# lazy = get_lazy(app)
|
44
44
|
display "Binding service: ",false
|
45
45
|
|
46
46
|
t = Thread.new do
|
@@ -51,7 +51,7 @@ module PI::Cli::Command
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
tmp = client.bind_service(appid,
|
54
|
+
tmp = client.bind_service(appid, manifest)
|
55
55
|
uuid = tmp[1]
|
56
56
|
result = check_status(uuid)
|
57
57
|
Thread.kill(t)
|
@@ -69,10 +69,10 @@ module PI::Cli::Command
|
|
69
69
|
else
|
70
70
|
services = asks "Select Service", :choices => services.collect { |s| s[:name] }, :indexed => true
|
71
71
|
end
|
72
|
-
graceful = get_graceful(app)
|
73
|
-
lazy = get_lazy(app)
|
72
|
+
# graceful = get_graceful(app)
|
73
|
+
# lazy = get_lazy(app)
|
74
74
|
services.each do |service|
|
75
|
-
do_unbind_service(app, service
|
75
|
+
do_unbind_service(app, service)
|
76
76
|
end
|
77
77
|
end
|
78
78
|
|
@@ -213,7 +213,7 @@ module PI::Cli::Command
|
|
213
213
|
|
214
214
|
private
|
215
215
|
|
216
|
-
def do_unbind_service(app, service
|
216
|
+
def do_unbind_service(app, service)
|
217
217
|
display "Unbinding service '#{service}': ",false
|
218
218
|
t = Thread.new do
|
219
219
|
loop do
|
@@ -222,7 +222,7 @@ module PI::Cli::Command
|
|
222
222
|
break unless t.alive?
|
223
223
|
end
|
224
224
|
end
|
225
|
-
tmp = client.unbind_service(app[:id], service
|
225
|
+
tmp = client.unbind_service(app[:id], service)
|
226
226
|
uuid = tmp[1]
|
227
227
|
result = check_status(uuid)
|
228
228
|
Thread.kill(t)
|