pi 0.1.33 → 0.1.34
Sign up to get free protection for your applications and to get access to all the features.
- data/README +10 -13
- data/lib/cli.rb +1 -1
- data/lib/cli/choose_helper.rb +50 -54
- data/lib/cli/commands/apps.rb +139 -139
- data/lib/cli/commands/dns.rb +50 -50
- data/lib/cli/commands/misc.rb +12 -11
- data/lib/cli/commands/projects.rb +67 -67
- data/lib/cli/commands/services.rb +56 -56
- data/lib/cli/commands/user.rb +29 -33
- data/lib/cli/interact_helper.rb +9 -9
- data/lib/cli/runner.rb +129 -129
- data/lib/cli/usage.rb +11 -11
- data/lib/cli/version.rb +1 -1
- data/lib/pi/client.rb +80 -89
- data/lib/pi/const.rb +1 -1
- metadata +147 -130
data/README
CHANGED
@@ -59,7 +59,7 @@ Try 'pi help [command]' or 'pi help options' for more information.
|
|
59
59
|
Currently available pi commands are:
|
60
60
|
|
61
61
|
User
|
62
|
-
login [
|
62
|
+
login [env] [--user,--password] Login
|
63
63
|
logout Logs current user out of the system
|
64
64
|
info List system information
|
65
65
|
user Display user information
|
@@ -144,16 +144,19 @@ Currently available pi commands are:
|
|
144
144
|
4. Example
|
145
145
|
|
146
146
|
wangjing@wangjing-pc:~$ pi login
|
147
|
-
|
147
|
+
1: www
|
148
|
+
2: staging
|
149
|
+
3: qa
|
150
|
+
Select CloudPi Environment [www]: 1
|
148
151
|
User: wangjing
|
149
152
|
Password: *******
|
150
|
-
Successfully logged into [http://
|
153
|
+
Successfully logged into [http://api.samsungcloud.org]
|
151
154
|
|
152
|
-
wangjing@wangjing-pc:~$ pi login
|
153
|
-
Successfully logged into [http://
|
155
|
+
wangjing@wangjing-pc:~$ pi login www --user wangjing --password cloudpi
|
156
|
+
Successfully logged into [http://api.samsungcloud.org]
|
154
157
|
|
155
158
|
wangjing@wangjing-pc:~$ pi version
|
156
|
-
pi 0.1.
|
159
|
+
pi 0.1.34
|
157
160
|
|
158
161
|
wangjing@wangjing-pc:~$ pi info
|
159
162
|
|
@@ -170,7 +173,7 @@ Try 'pi help [command]' or 'pi help options' for more information.
|
|
170
173
|
Currently available pi commands are:
|
171
174
|
|
172
175
|
User
|
173
|
-
login [
|
176
|
+
login [env] [--user,--password] Login
|
174
177
|
logout Logs current user out of the system
|
175
178
|
info List system information
|
176
179
|
user Display user information
|
@@ -763,12 +766,6 @@ Successfully logged out of [http://api.staging.samsungcloud.org]
|
|
763
766
|
|
764
767
|
5. Common Exception
|
765
768
|
|
766
|
-
ubuntu@admin:~$ pi login
|
767
|
-
Attempting login to 'http://api.staging.samsungcloud.org'? [Yn]: n
|
768
|
-
Please input URL: http://test.org
|
769
|
-
Host is not available or is not valid: 'http://test.org'
|
770
|
-
Problem with login, Cannot access target (getaddrinfo: Name or service not known), try again.
|
771
|
-
|
772
769
|
ubuntu@admin:~$ pi github
|
773
770
|
Please input your name: ruanzhimin
|
774
771
|
Please input your email: ruanzhimin@gmail.com
|
data/lib/cli.rb
CHANGED
@@ -11,7 +11,7 @@ module PI
|
|
11
11
|
autoload :Runner, "#{ROOT}/cli/runner"
|
12
12
|
autoload :ChooseHelper, "#{ROOT}/cli/choose_helper"
|
13
13
|
autoload :InteractHelper, "#{ROOT}/cli/interact_helper"
|
14
|
-
|
14
|
+
|
15
15
|
module Command
|
16
16
|
autoload :Base, "#{ROOT}/cli/commands/base"
|
17
17
|
autoload :Projects, "#{ROOT}/cli/commands/projects"
|
data/lib/cli/choose_helper.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "set"
|
2
2
|
module PI::Cli
|
3
3
|
module ChooseHelper
|
4
|
-
|
4
|
+
|
5
5
|
YES_SET = Set.new(["y", "Y", "yes", "YES"])
|
6
6
|
NO_SET = Set.new(["n", "N", "no", "NO"])
|
7
7
|
DEFAULTS = {
|
@@ -13,7 +13,7 @@ module PI::Cli
|
|
13
13
|
"isDebug" => false,
|
14
14
|
"needMonitor" => false
|
15
15
|
}
|
16
|
-
|
16
|
+
|
17
17
|
def total_opts
|
18
18
|
all_opts = Hash.new
|
19
19
|
all_opts = {
|
@@ -40,7 +40,7 @@ module PI::Cli
|
|
40
40
|
:graceful => @options[:graceful]
|
41
41
|
}
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def choose_project
|
45
45
|
projects = client.projects
|
46
46
|
err "No Projects" if projects.nil? || projects.empty?
|
@@ -54,9 +54,9 @@ module PI::Cli
|
|
54
54
|
display "#{useproject}"
|
55
55
|
projects.each do |p|
|
56
56
|
return p if p[:name] == useproject
|
57
|
-
end
|
57
|
+
end
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
def choose_target
|
61
61
|
targets = client.targets
|
62
62
|
err "No Targets" if targets.nil? || targets.empty?
|
@@ -70,13 +70,13 @@ module PI::Cli
|
|
70
70
|
display "#{usetarget}"
|
71
71
|
targets.each do |p|
|
72
72
|
return p if p[:name] == usetarget
|
73
|
-
end
|
73
|
+
end
|
74
74
|
end
|
75
|
-
|
75
|
+
|
76
76
|
def select_apps
|
77
77
|
choices = ["all","project","target"]
|
78
|
-
select_type = ask"Select application by", :choices => choices, :indexed => true
|
79
|
-
display "Select application by #{select_type}"
|
78
|
+
select_type = ask"Select application by", :choices => choices, :indexed => true
|
79
|
+
display "Select application by #{select_type}"
|
80
80
|
case select_type
|
81
81
|
when "all"
|
82
82
|
app = client.apps
|
@@ -93,7 +93,7 @@ module PI::Cli
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
|
97
97
|
def choose_app
|
98
98
|
apps = select_apps
|
99
99
|
err "No application!" if apps.nil? || apps.empty?
|
@@ -107,7 +107,7 @@ module PI::Cli
|
|
107
107
|
apps.each do |a|
|
108
108
|
if a[:name] == appname
|
109
109
|
flag = true
|
110
|
-
return a
|
110
|
+
return a
|
111
111
|
end
|
112
112
|
end
|
113
113
|
if flag == false
|
@@ -115,11 +115,11 @@ module PI::Cli
|
|
115
115
|
next
|
116
116
|
end
|
117
117
|
}
|
118
|
-
|
118
|
+
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def choose_app_help(appid_or_appname)
|
122
|
-
target = @options[:target]
|
122
|
+
target = @options[:target]
|
123
123
|
target_not_all = true
|
124
124
|
appid = nil
|
125
125
|
if appid_or_appname =~ /^[1-9]\d*$/
|
@@ -127,14 +127,14 @@ module PI::Cli
|
|
127
127
|
app = client.app_get_byid(appid)
|
128
128
|
err"The application is not found!" if app.nil?
|
129
129
|
return target_not_all, app, appid
|
130
|
-
elsif appid_or_appname == nil
|
130
|
+
elsif appid_or_appname == nil
|
131
131
|
if target.nil?
|
132
132
|
app = choose_app
|
133
133
|
return target_not_all, app, appid
|
134
|
-
else
|
135
|
-
err "Not enough arguments"
|
134
|
+
else
|
135
|
+
err "Not enough arguments"
|
136
136
|
end
|
137
|
-
else
|
137
|
+
else
|
138
138
|
appname = appid_or_appname
|
139
139
|
err "Not enough arguments" if target == nil
|
140
140
|
if target != "all"
|
@@ -147,28 +147,28 @@ module PI::Cli
|
|
147
147
|
else
|
148
148
|
apps = client.app_search_target_is_all(appname)
|
149
149
|
err "The application '#{appname}' is not found!" if apps.size == 0
|
150
|
-
target_not_all = false
|
151
|
-
return target_not_all, apps, appid
|
150
|
+
target_not_all = false
|
151
|
+
return target_not_all, apps, appid
|
152
152
|
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
156
|
def choose_app_help_target_not_all(appid_or_appname)
|
157
|
-
target = @options[:target]
|
158
|
-
appid = nil
|
157
|
+
target = @options[:target]
|
158
|
+
appid = nil
|
159
159
|
if appid_or_appname =~ /^[1-9]\d*$/
|
160
160
|
appid = appid_or_appname
|
161
161
|
app = client.app_get_byid(appid)
|
162
162
|
err"The application is not found!" if app.nil?
|
163
163
|
return app, appid
|
164
|
-
elsif appid_or_appname == nil
|
164
|
+
elsif appid_or_appname == nil
|
165
165
|
if target.nil?
|
166
166
|
app = choose_app
|
167
167
|
return app, appid
|
168
|
-
else
|
169
|
-
err "Not enough arguments"
|
168
|
+
else
|
169
|
+
err "Not enough arguments"
|
170
170
|
end
|
171
|
-
else
|
171
|
+
else
|
172
172
|
appname = appid_or_appname
|
173
173
|
err "Not enough arguments" if target == nil
|
174
174
|
# targets = client.targets
|
@@ -176,10 +176,10 @@ module PI::Cli
|
|
176
176
|
# err "Invalid target" unless targets.include?(target)
|
177
177
|
app = client.app_search(target, appname)
|
178
178
|
err "The application '#{appname}' is not found!" if app.nil?
|
179
|
-
return app, appid
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
179
|
+
return app, appid
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
183
|
def choose_serviceid
|
184
184
|
services = client.services
|
185
185
|
err "No services" if services.nil? || services.empty?
|
@@ -194,7 +194,7 @@ module PI::Cli
|
|
194
194
|
end
|
195
195
|
return serviceid
|
196
196
|
end
|
197
|
-
|
197
|
+
|
198
198
|
def choose_dnsid
|
199
199
|
dns = client.dns
|
200
200
|
err "No DNS" if dns.nil? || dns.empty?
|
@@ -209,21 +209,21 @@ module PI::Cli
|
|
209
209
|
end
|
210
210
|
return dnsid
|
211
211
|
end
|
212
|
-
|
212
|
+
|
213
213
|
def get_graceful(app)
|
214
214
|
graceful = @options[:graceful]
|
215
215
|
graceful = ask "Need graceful?", :default => DEFAULTS["graceful"] unless graceful
|
216
216
|
end
|
217
|
-
|
217
|
+
|
218
218
|
# def check_status(uuid)
|
219
|
-
# for i in 1..13 do
|
219
|
+
# for i in 1..13 do
|
220
220
|
# result = client.app_message(uuid)
|
221
|
-
# break result unless result[:text].empty?
|
222
|
-
# sleep(10)
|
223
|
-
# end
|
224
|
-
# return result
|
221
|
+
# break result unless result[:text].empty?
|
222
|
+
# sleep(10)
|
223
|
+
# end
|
224
|
+
# return result
|
225
225
|
# end
|
226
|
-
|
226
|
+
|
227
227
|
def check_status(uuid)
|
228
228
|
result = client.app_message(uuid)
|
229
229
|
if not result[:text].empty?
|
@@ -233,21 +233,21 @@ module PI::Cli
|
|
233
233
|
check_status(uuid)
|
234
234
|
end
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
def check_version_name_valid?(version)
|
238
238
|
version.size > 30 ? false : true
|
239
239
|
end
|
240
|
-
|
240
|
+
|
241
241
|
# only [a-zA-Z0-9] for project name and app name (size <=18)
|
242
242
|
def check_name_valid?(name)
|
243
243
|
(name =~ /^[a-zA-Z0-9]{1,18}$/) ? true : false
|
244
244
|
end
|
245
245
|
|
246
|
-
#Env name can't start with 'vcap_', 'VCAP_', 'vmc_' & 'VMC_', and can include 'a-zA-Z`~!@#$%^&*()_+-{}' only. The max length of name is 18
|
246
|
+
#Env name can't start with 'vcap_', 'VCAP_', 'vmc_' & 'VMC_', and can include 'a-zA-Z`~!@#$%^&*()_+-{}' only. The max length of name is 18
|
247
247
|
def check_envname_valid?(name)
|
248
248
|
#(name =~ /\b(?!vcap_|vmc_|VCAP_|VMC_)\D+\b/ && name.size <= 18) ? true : false
|
249
|
-
|
250
|
-
display "
|
249
|
+
unless name =~ /^[a-zA-Z_][[:alnum:]_]*$/
|
250
|
+
display "Env name must be started with \"a-zA-Z_\", and can include \"a-zA-Z_0-9\"".red
|
251
251
|
return false
|
252
252
|
end
|
253
253
|
if name =~ /^vcap_/i
|
@@ -258,22 +258,18 @@ module PI::Cli
|
|
258
258
|
display "Env name cannot be started with \"vmc_\" or \"VMC_\"".red
|
259
259
|
return false
|
260
260
|
end
|
261
|
-
# if not name =~ /^[a-zA-Z\`\~\!\@\#\$\%\^\&\*\(\)\_\+\-\{\}]{0,18}$/
|
262
|
-
# display "the input is illegal!".red
|
263
|
-
# return false
|
264
|
-
# end
|
265
261
|
if name.size > 18
|
266
262
|
display "Invalid name length. The max length of name is 18"
|
267
263
|
return false
|
268
264
|
end
|
269
265
|
return true
|
270
266
|
end
|
271
|
-
|
272
|
-
#not include number, ', ", \, and size <= 18
|
267
|
+
|
268
|
+
#not include number, ', ", \, =,and size <= 18
|
273
269
|
def check_envvalue_valid?(value)
|
274
270
|
#(value =~ /^[^\'\"\\]+$/ && value.size <= 18) ? true : false
|
275
271
|
(value =~ /^[^\'\"\\=]{1,18}$/) ? true : false
|
276
272
|
end
|
277
|
-
|
273
|
+
|
278
274
|
end
|
279
275
|
end
|
data/lib/cli/commands/apps.rb
CHANGED
@@ -14,7 +14,7 @@ module PI::Cli::Command
|
|
14
14
|
"needMonitor" => false,
|
15
15
|
"probe" => false
|
16
16
|
}
|
17
|
-
|
17
|
+
|
18
18
|
def apps
|
19
19
|
all_opts = total_opts
|
20
20
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(projectid|target)/i}
|
@@ -23,8 +23,8 @@ module PI::Cli::Command
|
|
23
23
|
end
|
24
24
|
client.check_login_status
|
25
25
|
projectid = @options[:projectid]
|
26
|
-
target = @options[:target]
|
27
|
-
projectid = 0 if projectid == "all" || projectid == nil
|
26
|
+
target = @options[:target]
|
27
|
+
projectid = 0 if projectid == "all" || projectid == nil
|
28
28
|
target = nil if target == "all"
|
29
29
|
app_sum = client.app_sum(projectid, target)
|
30
30
|
total_app = Integer(app_sum[1])
|
@@ -32,34 +32,34 @@ module PI::Cli::Command
|
|
32
32
|
pageNum = -1
|
33
33
|
numPerPage = -1
|
34
34
|
if total_app >= 50
|
35
|
-
puts "Total applications: #{total_app}."
|
36
|
-
numPerPage = nil
|
35
|
+
puts "Total applications: #{total_app}."
|
36
|
+
numPerPage = nil
|
37
37
|
loop{
|
38
38
|
numPerPage = ask "Number per page"
|
39
39
|
if not numPerPage =~ /^[1-9]\d*$/
|
40
|
-
display "Invalid Number! Please input number from 1 to #{total_app}".red
|
40
|
+
display "Invalid Number! Please input number from 1 to #{total_app}".red
|
41
41
|
numPerPage =nil
|
42
42
|
next
|
43
43
|
else
|
44
44
|
break
|
45
45
|
end
|
46
|
-
}
|
46
|
+
}
|
47
47
|
numPerPage = numPerPage.to_i
|
48
48
|
maxpage = (total_app.to_f/numPerPage).ceil
|
49
49
|
loop{
|
50
50
|
pageNum = ask "Page number"
|
51
51
|
if not pageNum =~ /^[1-9]\d*$/
|
52
|
-
display "Invalid Number! Please input number from 1 to #{maxpage}".red
|
52
|
+
display "Invalid Number! Please input number from 1 to #{maxpage}".red
|
53
53
|
pageNum =nil
|
54
54
|
next
|
55
55
|
else
|
56
56
|
break
|
57
57
|
end
|
58
|
-
}
|
59
|
-
pageNum = pageNum.to_i
|
60
|
-
end
|
58
|
+
}
|
59
|
+
pageNum = pageNum.to_i
|
60
|
+
end
|
61
61
|
apps = client.apps(projectid, target, pageNum, numPerPage)
|
62
|
-
return display "No Applications" if apps.nil? || apps.empty?
|
62
|
+
return display "No Applications" if apps.nil? || apps.empty?
|
63
63
|
return display JSON.pretty_generate(apps) if @options[:json]
|
64
64
|
apps.sort! {|a, b| a[:name] <=> b[:name] }
|
65
65
|
apps_table = table do |t|
|
@@ -78,42 +78,42 @@ module PI::Cli::Command
|
|
78
78
|
end
|
79
79
|
client.check_login_status
|
80
80
|
binarylist, deployType, instances = nil, nil, nil
|
81
|
-
|
82
|
-
if appname
|
81
|
+
|
82
|
+
if appname
|
83
83
|
if not check_name_valid?(appname)
|
84
|
-
err "Invalid application name '#{appname}'."
|
84
|
+
err "Invalid application name '#{appname}'."
|
85
85
|
end
|
86
86
|
end
|
87
|
-
|
87
|
+
|
88
88
|
# choose the target
|
89
|
-
targets = client.targets
|
89
|
+
targets = client.targets
|
90
90
|
err "No Targets!" if targets.nil? || targets.empty?
|
91
91
|
target = ask "Select Target", :choices => targets.collect { |t| t[:name] }, :indexed => true
|
92
92
|
display "Selected Target: ",false
|
93
93
|
display "#{target}"
|
94
94
|
target_memory = client.target_memory(target)
|
95
|
-
|
96
|
-
loop{
|
95
|
+
|
96
|
+
loop{
|
97
97
|
appname = ask "Application Name" unless appname
|
98
98
|
if not check_name_valid?(appname)
|
99
|
-
display "Invalid application name '#{appname}'.".red
|
99
|
+
display "Invalid application name '#{appname}'.".red
|
100
100
|
appname =nil
|
101
101
|
next
|
102
|
-
else if app_exists?(target, appname)
|
103
|
-
display "Application '#{appname}' already exists.".red
|
104
|
-
appname =nil
|
105
|
-
next
|
106
|
-
else
|
102
|
+
else if app_exists?(target, appname)
|
103
|
+
display "Application '#{appname}' already exists.".red
|
104
|
+
appname =nil
|
105
|
+
next
|
106
|
+
else
|
107
107
|
break
|
108
108
|
end
|
109
109
|
end
|
110
|
-
}
|
111
|
-
|
110
|
+
}
|
111
|
+
|
112
112
|
# choose the project
|
113
113
|
useproject = choose_project
|
114
114
|
projectname = useproject[:name]
|
115
115
|
projectid = useproject[:id]
|
116
|
-
|
116
|
+
|
117
117
|
# choose the tag
|
118
118
|
if useproject[:runtime] =~ /^(ruby)/i
|
119
119
|
deployType = "git"
|
@@ -134,42 +134,42 @@ module PI::Cli::Command
|
|
134
134
|
tag = ""
|
135
135
|
else
|
136
136
|
err "Invalid Input"
|
137
|
-
end
|
137
|
+
end
|
138
138
|
else
|
139
139
|
deployType = "binary"
|
140
140
|
binarylist = client.project_binary(projectid)
|
141
141
|
err "No version!" if binarylist.nil? || binarylist.empty?
|
142
142
|
tag = ask "Select Version", :choices => binarylist.collect { |b| b[:versionName] }, :indexed => true
|
143
143
|
display "Selected Version: ",false
|
144
|
-
display "#{tag}"
|
145
|
-
end
|
144
|
+
display "#{tag}"
|
145
|
+
end
|
146
146
|
# URL combination
|
147
147
|
user = client.user_info
|
148
148
|
url = "#{appname}.#{user[:userName]}.#{target}.samsungpaas.com"
|
149
|
-
display "URL: #{url}"
|
149
|
+
display "URL: #{url}"
|
150
150
|
# choose the mem
|
151
151
|
mem = ask "Memory reservation", :default => DEFAULTS["mem"], :choices => ["64M", "128M", "256M", "512M", "1G", "2G"]
|
152
152
|
# Set to MB number
|
153
153
|
mem_quota = mem_choice_to_quota(mem)
|
154
|
-
|
154
|
+
|
155
155
|
target_memory = Integer(target_memory[1])
|
156
156
|
max_instance = (target_memory.to_f/mem.to_i).floor
|
157
157
|
display ("Available memory: #{target_memory} M, maximum instances: #{max_instance}")
|
158
158
|
loop{
|
159
159
|
instances = ask "How many instances(from 1 to #{max_instance})?", :default => DEFAULTS["instances"]
|
160
160
|
if not instances.to_s =~ /^[1-9]\d*$/
|
161
|
-
display "Invalid Number!".red
|
162
|
-
instances =nil
|
163
|
-
next
|
161
|
+
display "Invalid Number!".red
|
162
|
+
instances =nil
|
163
|
+
next
|
164
164
|
else if instances < 1 || instances > max_instance
|
165
|
-
display "Invalid Number! Please input number from 1 to #{max_instance}".red
|
166
|
-
instances =nil
|
167
|
-
next
|
165
|
+
display "Invalid Number! Please input number from 1 to #{max_instance}".red
|
166
|
+
instances =nil
|
167
|
+
next
|
168
168
|
else
|
169
169
|
break
|
170
170
|
end
|
171
171
|
end
|
172
|
-
}
|
172
|
+
}
|
173
173
|
isDebug = false
|
174
174
|
isDebug = ask "Need debug?", :default => DEFAULTS["isDebug"] if deployType == "binary"
|
175
175
|
isDebug = (isDebug == false ? "no" : "yes")
|
@@ -178,9 +178,9 @@ module PI::Cli::Command
|
|
178
178
|
probe = false
|
179
179
|
probe = ask "Need JMX monitoring?", :default => DEFAULTS["probe"] if deployType == "binary"
|
180
180
|
probe = (probe == false ? "no" : "yes")
|
181
|
-
# needMonitor = ask "Need monitor?", :default => DEFAULTS["needMonitor"]
|
181
|
+
# needMonitor = ask "Need monitor?", :default => DEFAULTS["needMonitor"]
|
182
182
|
# needMonitor = (needMonitor == false ? "no" : "yes")
|
183
|
-
|
183
|
+
|
184
184
|
manifest = {
|
185
185
|
:targetName => target,
|
186
186
|
:name => "#{appname}",
|
@@ -197,23 +197,23 @@ module PI::Cli::Command
|
|
197
197
|
:needMonitor => "no",
|
198
198
|
:probe => probe
|
199
199
|
}
|
200
|
-
|
200
|
+
|
201
201
|
display "Creating application \"#{appname}\": ",false
|
202
|
-
|
203
|
-
t = Thread.new do
|
202
|
+
|
203
|
+
t = Thread.new do
|
204
204
|
loop do
|
205
|
-
display '.', false
|
205
|
+
display '.', false
|
206
206
|
sleep (1)
|
207
207
|
break unless t.alive?
|
208
208
|
end
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
tmp = client.create_app(manifest)
|
212
212
|
uuid = tmp[1]
|
213
213
|
result = check_status(uuid)
|
214
214
|
Thread.kill(t)
|
215
215
|
end
|
216
|
-
|
216
|
+
|
217
217
|
def delete_app(appid_or_appname=nil)
|
218
218
|
all_opts = total_opts
|
219
219
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
|
@@ -221,64 +221,64 @@ module PI::Cli::Command
|
|
221
221
|
err "Invalid options" if value != nil
|
222
222
|
end
|
223
223
|
client.check_login_status
|
224
|
-
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
224
|
+
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
225
225
|
appid = (appid == nil ? app[:id] : appid)
|
226
|
-
|
226
|
+
|
227
227
|
display "Deleting application: ",false
|
228
|
-
|
229
|
-
t = Thread.new do
|
228
|
+
|
229
|
+
t = Thread.new do
|
230
230
|
loop do
|
231
|
-
display '.', false
|
231
|
+
display '.', false
|
232
232
|
sleep (1)
|
233
233
|
break unless t.alive?
|
234
234
|
end
|
235
235
|
end
|
236
|
-
|
236
|
+
|
237
237
|
client.delete_app(appid)
|
238
238
|
Thread.kill(t)
|
239
239
|
display "OK".green
|
240
240
|
end
|
241
|
-
|
241
|
+
|
242
242
|
def start_app(appid_or_appname=nil)
|
243
243
|
all_opts = total_opts
|
244
244
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
|
245
245
|
all_opts_except_valid_opts.each_value do |value|
|
246
246
|
err "Invalid options" if value != nil
|
247
247
|
end
|
248
|
-
client.check_login_status
|
249
|
-
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
248
|
+
client.check_login_status
|
249
|
+
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
250
250
|
if target_not_all
|
251
251
|
appid = (appid == nil ? app[:id] : appid)
|
252
|
-
return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already started.".yellow if app[:status] == "STARTED"
|
253
|
-
do_start_app(app, appid)
|
252
|
+
return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already started.".yellow if app[:status] == "STARTED"
|
253
|
+
do_start_app(app, appid)
|
254
254
|
else
|
255
255
|
app.each do |a|
|
256
|
-
next display "The application '#{a[:name]}'(target:#{a[:targetName]}) has already started.".yellow if a[:status] == "STARTED"
|
256
|
+
next display "The application '#{a[:name]}'(target:#{a[:targetName]}) has already started.".yellow if a[:status] == "STARTED"
|
257
257
|
do_start_app(a, a[:id])
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
def stop_app(appid_or_appname=nil)
|
263
263
|
all_opts = total_opts
|
264
264
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|graceful)/i}
|
265
265
|
all_opts_except_valid_opts.each_value do |value|
|
266
266
|
err "Invalid options" if value != nil
|
267
267
|
end
|
268
|
-
client.check_login_status
|
269
|
-
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
268
|
+
client.check_login_status
|
269
|
+
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
270
270
|
if target_not_all
|
271
|
-
appid = (appid == nil ? app[:id] : appid)
|
272
|
-
# return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already stopped.".yellow if app[:status] == "STOPPED"
|
273
|
-
do_stop_app(app, appid)
|
271
|
+
appid = (appid == nil ? app[:id] : appid)
|
272
|
+
# return display "The application '#{app[:name]}'(target:#{app[:targetName]}) has already stopped.".yellow if app[:status] == "STOPPED"
|
273
|
+
do_stop_app(app, appid)
|
274
274
|
else
|
275
275
|
app.each do |a|
|
276
|
-
next display "The application '#{a[:name]}'(target:#{a[:targetName]}) has already stopped.".yellow if a[:status] == "STOPPED"
|
276
|
+
next display "The application '#{a[:name]}'(target:#{a[:targetName]}) has already stopped.".yellow if a[:status] == "STOPPED"
|
277
277
|
do_stop_app(a, a[:id])
|
278
278
|
end
|
279
279
|
end
|
280
280
|
end
|
281
|
-
|
281
|
+
|
282
282
|
def restart_app(appid_or_appname=nil)
|
283
283
|
all_opts = total_opts
|
284
284
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|graceful)/i}
|
@@ -286,17 +286,17 @@ module PI::Cli::Command
|
|
286
286
|
err "Invalid options" if value != nil
|
287
287
|
end
|
288
288
|
client.check_login_status
|
289
|
-
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
290
|
-
if target_not_all
|
291
|
-
appid = (appid == nil ? app[:id] : appid)
|
292
|
-
do_restart_app(app, appid)
|
289
|
+
target_not_all, app, appid = choose_app_help(appid_or_appname)
|
290
|
+
if target_not_all
|
291
|
+
appid = (appid == nil ? app[:id] : appid)
|
292
|
+
do_restart_app(app, appid)
|
293
293
|
else
|
294
294
|
app.each do |a|
|
295
295
|
do_restart_app(a, a[:id])
|
296
296
|
end
|
297
297
|
end
|
298
298
|
end
|
299
|
-
|
299
|
+
|
300
300
|
def scale_app(appid_or_appname=nil)
|
301
301
|
all_opts = total_opts
|
302
302
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|instance)/i}
|
@@ -304,46 +304,46 @@ module PI::Cli::Command
|
|
304
304
|
err "Invalid options" if value != nil
|
305
305
|
end
|
306
306
|
client.check_login_status
|
307
|
-
instance = @options[:instance]
|
308
|
-
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
309
|
-
appid = (appid == nil ? app[:id] : appid)
|
307
|
+
instance = @options[:instance]
|
308
|
+
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
309
|
+
appid = (appid == nil ? app[:id] : appid)
|
310
310
|
target_memory = client.target_memory(app[:targetName])
|
311
311
|
target_memory = Integer(target_memory[1])
|
312
312
|
max_instance = (target_memory.to_f/app[:memory].to_i).floor
|
313
|
-
display ("Available memory: #{target_memory} M, maximum instances: #{max_instance}")
|
314
|
-
loop{
|
315
|
-
instance = ask "Current instance: #{app[:instances]},
|
313
|
+
display ("Available memory: #{target_memory} M, maximum instances: #{max_instance}")
|
314
|
+
loop{
|
315
|
+
instance = ask "Current instance: #{app[:instances]}, instance number" unless instance
|
316
316
|
if not instance.to_s =~ /^[1-9]\d*$/
|
317
|
-
display "Invalid Number!".red
|
318
|
-
instance =nil
|
317
|
+
display "Invalid Number!".red
|
318
|
+
instance =nil
|
319
319
|
next
|
320
320
|
else if instance.to_i < 1 || instance.to_i > max_instance
|
321
|
-
display "Invalid Number! Please input number from 1 to #{max_instance}".red
|
322
|
-
instance =nil
|
321
|
+
display "Invalid Number! Please input number from 1 to #{max_instance}".red
|
322
|
+
instance =nil
|
323
323
|
next
|
324
324
|
else
|
325
325
|
break
|
326
326
|
end
|
327
327
|
end
|
328
|
-
}
|
328
|
+
}
|
329
329
|
err "Don't need scale application" if instance.to_s == app[:instances].to_s
|
330
|
-
# graceful = get_graceful(app)
|
330
|
+
# graceful = get_graceful(app)
|
331
331
|
display "Scaling application: ",false
|
332
|
-
|
333
|
-
t = Thread.new do
|
332
|
+
|
333
|
+
t = Thread.new do
|
334
334
|
loop do
|
335
|
-
display '.', false
|
335
|
+
display '.', false
|
336
336
|
sleep (1)
|
337
337
|
break unless t.alive?
|
338
338
|
end
|
339
339
|
end
|
340
|
-
|
340
|
+
|
341
341
|
tmp = client.scale_app(appid, instance)
|
342
342
|
uuid = tmp[1]
|
343
343
|
result = check_status(uuid)
|
344
|
-
Thread.kill(t)
|
344
|
+
Thread.kill(t)
|
345
345
|
end
|
346
|
-
|
346
|
+
|
347
347
|
def update_app(appid_or_appname=nil)
|
348
348
|
all_opts = total_opts
|
349
349
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|ver|graceful)/i}
|
@@ -352,9 +352,9 @@ module PI::Cli::Command
|
|
352
352
|
end
|
353
353
|
client.check_login_status
|
354
354
|
tag = @options[:ver]
|
355
|
-
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
356
|
-
appid = (appid == nil ? app[:id] : appid)
|
357
|
-
if app[:deployType] == "git"
|
355
|
+
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
356
|
+
appid = (appid == nil ? app[:id] : appid)
|
357
|
+
if app[:deployType] == "git"
|
358
358
|
tags = client.project_tags(app[:projectId])
|
359
359
|
err "No tags!" if tags.nil? || tags.empty?
|
360
360
|
if tag
|
@@ -363,7 +363,7 @@ module PI::Cli::Command
|
|
363
363
|
tag = ask "Select Tag", :choices => tags, :indexed => true
|
364
364
|
end
|
365
365
|
err "Don't need update application!" if tag == app[:tag]
|
366
|
-
else
|
366
|
+
else
|
367
367
|
tags = client.project_binary(app[:projectId])
|
368
368
|
err "No version!" if tags.nil? || tags.empty?
|
369
369
|
if tag
|
@@ -372,26 +372,26 @@ module PI::Cli::Command
|
|
372
372
|
else
|
373
373
|
tag = ask "Select Version", :choices => tags.collect { |b| b[:versionName] }, :indexed => true
|
374
374
|
end
|
375
|
-
err "Don't need update application!" if tag == app[:tag]
|
375
|
+
err "Don't need update application!" if tag == app[:tag]
|
376
376
|
end
|
377
377
|
graceful = get_graceful(app)
|
378
378
|
# lazy = get_lazy(app)
|
379
379
|
display "Updating application: ",false
|
380
|
-
|
381
|
-
t = Thread.new do
|
380
|
+
|
381
|
+
t = Thread.new do
|
382
382
|
loop do
|
383
|
-
display '.', false
|
383
|
+
display '.', false
|
384
384
|
sleep (1)
|
385
385
|
break unless t.alive?
|
386
386
|
end
|
387
387
|
end
|
388
|
-
|
389
|
-
tmp = client.update_app(appid,tag,graceful)
|
388
|
+
|
389
|
+
tmp = client.update_app(appid,tag,graceful)
|
390
390
|
uuid = tmp[1]
|
391
391
|
result = check_status(uuid)
|
392
|
-
Thread.kill(t)
|
392
|
+
Thread.kill(t)
|
393
393
|
end
|
394
|
-
|
394
|
+
|
395
395
|
def status(appid_or_appname=nil)
|
396
396
|
all_opts = total_opts
|
397
397
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
|
@@ -399,7 +399,7 @@ module PI::Cli::Command
|
|
399
399
|
err "Invalid options" if value != nil
|
400
400
|
end
|
401
401
|
client.check_login_status
|
402
|
-
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
402
|
+
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
403
403
|
appid = (appid == nil ? app[:id] : appid)
|
404
404
|
status = client.status(appid)
|
405
405
|
return display JSON.pretty_generate(status) if @options[:json]
|
@@ -412,7 +412,7 @@ module PI::Cli::Command
|
|
412
412
|
end
|
413
413
|
display status_table
|
414
414
|
end
|
415
|
-
|
415
|
+
|
416
416
|
def app_env(appid_or_appname=nil)
|
417
417
|
all_opts = total_opts
|
418
418
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
|
@@ -420,9 +420,9 @@ module PI::Cli::Command
|
|
420
420
|
err "Invalid options" if value != nil
|
421
421
|
end
|
422
422
|
client.check_login_status
|
423
|
-
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
423
|
+
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
424
424
|
appid = (appid == nil ? app[:id] : appid)
|
425
|
-
env = client.app_env(appid)
|
425
|
+
env = client.app_env(appid)
|
426
426
|
return display JSON.pretty_generate(env) if @options[:json]
|
427
427
|
return display "No Environments!" if env.nil? || env.empty?
|
428
428
|
env.sort! {|a, b| a[:name] <=> b[:name] }
|
@@ -434,7 +434,7 @@ module PI::Cli::Command
|
|
434
434
|
end
|
435
435
|
display env_table
|
436
436
|
end
|
437
|
-
|
437
|
+
|
438
438
|
def create_env(appid_or_appname=nil)
|
439
439
|
all_opts = total_opts
|
440
440
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|name|value)/i}
|
@@ -444,33 +444,33 @@ module PI::Cli::Command
|
|
444
444
|
client.check_login_status
|
445
445
|
name = @options[:name]
|
446
446
|
value = @options[:value]
|
447
|
-
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
447
|
+
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
448
448
|
appid = (appid == nil ? app[:id] : appid)
|
449
|
-
|
450
|
-
loop{
|
449
|
+
|
450
|
+
loop{
|
451
451
|
name = ask "Environment Name" unless name
|
452
452
|
if not check_envname_valid?(name)
|
453
|
-
name =nil
|
453
|
+
name =nil
|
454
454
|
next
|
455
455
|
else if env_exists?(appid,name)
|
456
|
-
display "Environment '#{name}' already exists.".red
|
457
|
-
name =nil
|
458
|
-
next
|
456
|
+
display "Environment '#{name}' already exists.".red
|
457
|
+
name =nil
|
458
|
+
next
|
459
459
|
else
|
460
460
|
break
|
461
461
|
end
|
462
462
|
end
|
463
|
-
}
|
463
|
+
}
|
464
464
|
loop{
|
465
465
|
value = ask "Environment Value" unless value
|
466
466
|
if not check_envvalue_valid?(value)
|
467
|
-
display "Invalid environment value '#{value}'.".red
|
467
|
+
display "Invalid environment value '#{value}'.".red
|
468
468
|
value =nil
|
469
469
|
next
|
470
470
|
else
|
471
471
|
break
|
472
472
|
end
|
473
|
-
}
|
473
|
+
}
|
474
474
|
manifest = {
|
475
475
|
:name => name,
|
476
476
|
:value => value
|
@@ -478,7 +478,7 @@ module PI::Cli::Command
|
|
478
478
|
client.create_env(appid, manifest)
|
479
479
|
display "OK".green
|
480
480
|
end
|
481
|
-
|
481
|
+
|
482
482
|
def delete_env(appid_or_appname=nil)
|
483
483
|
all_opts = total_opts
|
484
484
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|name)/i}
|
@@ -501,22 +501,22 @@ module PI::Cli::Command
|
|
501
501
|
end
|
502
502
|
display "\n"
|
503
503
|
end
|
504
|
-
|
504
|
+
|
505
505
|
delete_envs = Array.new
|
506
506
|
envs.each do |e|
|
507
507
|
name.each do |n|
|
508
508
|
delete_envs.push("#{n}=#{e[:value]}") if n == e[:name]
|
509
|
-
end
|
510
|
-
end
|
509
|
+
end
|
510
|
+
end
|
511
511
|
err " The environment is not exist!" if delete_envs.nil? || delete_envs.empty?
|
512
512
|
|
513
513
|
delete_envs.each do |env|
|
514
|
-
display "Deleting environment '#{env}': ",false
|
514
|
+
display "Deleting environment '#{env}': ",false
|
515
515
|
client.delete_env(appid, env)
|
516
516
|
display "OK".green
|
517
|
-
end
|
517
|
+
end
|
518
518
|
end
|
519
|
-
|
519
|
+
|
520
520
|
def app_log(appid_or_appname=nil)
|
521
521
|
all_opts = total_opts
|
522
522
|
all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target|instanceid|file)/i}
|
@@ -527,7 +527,7 @@ module PI::Cli::Command
|
|
527
527
|
instanceindex = @options[:instanceid]
|
528
528
|
file = @options[:file]
|
529
529
|
app, appid = choose_app_help_target_not_all(appid_or_appname)
|
530
|
-
appid = (appid == nil ? app[:id] : appid)
|
530
|
+
appid = (appid == nil ? app[:id] : appid)
|
531
531
|
max_index = app[:instances]-1
|
532
532
|
instanceindex = ask "Select instance index(from 0 to #{max_index})", :default => 0 unless instanceindex
|
533
533
|
unless file
|
@@ -545,7 +545,7 @@ module PI::Cli::Command
|
|
545
545
|
display "\n"
|
546
546
|
display logs[1]
|
547
547
|
end
|
548
|
-
|
548
|
+
|
549
549
|
# def app_debug(appid_or_appname=nil)
|
550
550
|
# all_opts = total_opts
|
551
551
|
# all_opts_except_valid_opts = all_opts.delete_if{ |key,value| key.to_s =~ /(target)/i}
|
@@ -573,19 +573,19 @@ module PI::Cli::Command
|
|
573
573
|
# end
|
574
574
|
# display debug_table
|
575
575
|
# end
|
576
|
-
|
577
|
-
private
|
578
|
-
|
576
|
+
|
577
|
+
private
|
578
|
+
|
579
579
|
def app_exists?(target, appname)
|
580
580
|
app = client.app_search(target,appname)
|
581
|
-
app.nil? ? false : true
|
581
|
+
app.nil? ? false : true
|
582
582
|
end
|
583
|
-
|
583
|
+
|
584
584
|
def env_exists?(appid, envname)
|
585
585
|
env = client.env_verify(appid, envname)
|
586
|
-
"true" == env[1] ? false : true
|
586
|
+
"true" == env[1] ? false : true
|
587
587
|
end
|
588
|
-
|
588
|
+
|
589
589
|
def do_start_app(app, appid)
|
590
590
|
display "Starting application '#{app[:name]}'(target:#{app[:targetName]}): ",false
|
591
591
|
t = Thread.new do
|
@@ -600,15 +600,15 @@ module PI::Cli::Command
|
|
600
600
|
result = check_status(uuid)
|
601
601
|
Thread.kill(t)
|
602
602
|
end
|
603
|
-
|
603
|
+
|
604
604
|
def do_stop_app(app, appid)
|
605
605
|
graceful = get_graceful(app)
|
606
606
|
display "Stoping application '#{app[:name]}'(target:#{app[:targetName]}): ",false
|
607
607
|
client.stop_app(appid, graceful)
|
608
608
|
display "OK".green
|
609
609
|
end
|
610
|
-
|
611
|
-
def do_restart_app(app, appid)
|
610
|
+
|
611
|
+
def do_restart_app(app, appid)
|
612
612
|
graceful = get_graceful(app)
|
613
613
|
# lazy = get_lazy(app)
|
614
614
|
display "Restart application '#{app[:name]}'(target:#{app[:targetName]}): ",false
|
@@ -624,11 +624,11 @@ module PI::Cli::Command
|
|
624
624
|
result = check_status(uuid)
|
625
625
|
Thread.kill(t)
|
626
626
|
end
|
627
|
-
|
627
|
+
|
628
628
|
def mem_choice_to_quota(mem_choice)
|
629
629
|
(mem_choice =~ /(\d+)M/i) ? mem_quota = $1.to_i : mem_quota = mem_choice.to_i * 1024
|
630
630
|
mem_quota
|
631
631
|
end
|
632
|
-
|
632
|
+
|
633
633
|
end
|
634
634
|
end
|