app42 0.5.5 → 0.5.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +90 -58
- data/lib/app42/base/constants.rb +0 -1
- data/lib/app42/base/help.rb +271 -54
- data/lib/app42/base/message.rb +2 -0
- data/lib/app42/base/shell.rb +9 -1
- data/lib/app42/base/util.rb +97 -6
- data/lib/app42/client/app42_rest_client.rb +0 -8
- data/lib/app42/command/app.rb +47 -34
- data/lib/app42/command/authorize.rb +1 -1
- data/lib/app42/command/base.rb +208 -30
- data/lib/app42/command/client.rb +23 -2
- data/lib/app42/command/config.rb +14 -0
- data/lib/app42/command/info.rb +1 -1
- data/lib/app42/command/service.rb +23 -2
- data/lib/app42/command/setup.rb +89 -0
- data/lib/app42/version.rb +1 -1
- data/spec/app42/base/constants_spec.rb +1 -1
- data/spec/app42/command/app_spec.rb +4 -4
- data/spec/app42/command/info_spec.rb +5 -5
- data/spec/app42/command/service_spec.rb +4 -4
- metadata +2 -2
- data/TODO.txt +0 -36
data/lib/app42/base/message.rb
CHANGED
@@ -17,6 +17,7 @@ module Message
|
|
17
17
|
LATEST_S_WAIT = "\nOperation is in progress, Please wait..."
|
18
18
|
LATEST_S_INTERRUPT = "\nYour request is being processed. Please check the request status after sometime."
|
19
19
|
NOT_A_VALID_NUM = "Instance(s) count should be a valid number and greater than zero."
|
20
|
+
NOT_A_VALID_KONTENA = "Kontena(s) count should be a valid number and greater than zero."
|
20
21
|
REQUEST_PROGRESS = "\nYour request is in progress. Please check the request status after sometime."
|
21
22
|
LOG_MESSAGE = "Please visit below URL(s) to access app logs"
|
22
23
|
|
@@ -26,6 +27,7 @@ module Message
|
|
26
27
|
BIND_NOTE = "Please Provide Source IP\n(For public access, use '0.0.0.0')"
|
27
28
|
UNBIND_NOTE = "Please Provide Source IP"
|
28
29
|
ACCESS_TIME_NOTE = "Please provide the time duration(in hours) you want to bind IP(0 for unlimited access)"
|
30
|
+
GIT_URL_NOT_VALID = "App git url is not valid."
|
29
31
|
|
30
32
|
# REST CLIENT EXCEPTION
|
31
33
|
SERVER_ERROR = "Something went wrong. We will look into the issue. For further information, Please drop a mail to 'support@shephertz.com'."
|
data/lib/app42/base/shell.rb
CHANGED
@@ -7,6 +7,7 @@ module App42
|
|
7
7
|
'version',
|
8
8
|
'list',
|
9
9
|
'deploy',
|
10
|
+
'update',
|
10
11
|
'setupinfra',
|
11
12
|
'keys',
|
12
13
|
'clearkeys',
|
@@ -30,10 +31,17 @@ module App42
|
|
30
31
|
'supportedservices',
|
31
32
|
'activities',
|
32
33
|
'serviceinfo',
|
34
|
+
'startservice',
|
35
|
+
'restartservice',
|
36
|
+
'stopservice',
|
33
37
|
'resetservicepassword',
|
34
38
|
'bindip',
|
35
39
|
'unbindip',
|
36
|
-
'bindinfo'
|
40
|
+
'bindinfo',
|
41
|
+
'setupcloudapi',
|
42
|
+
'deletecloudapi',
|
43
|
+
'setupinfo',
|
44
|
+
'setups'
|
37
45
|
]
|
38
46
|
|
39
47
|
end
|
data/lib/app42/base/util.rb
CHANGED
@@ -48,7 +48,7 @@ module App42
|
|
48
48
|
end
|
49
49
|
|
50
50
|
|
51
|
-
def request_failed?(status)
|
51
|
+
def request_failed?(status) #:nodoc:
|
52
52
|
# TODO, if more than one error code
|
53
53
|
# APP42_HTTP_ERROR_CODES.detect{|error_code| status >= error_code}
|
54
54
|
APP42_HTTP_ERROR_CODES.include? status
|
@@ -60,8 +60,6 @@ module App42
|
|
60
60
|
desc = body["details"].gsub("\"","'")
|
61
61
|
# TODO, may need later
|
62
62
|
# app42_client_info
|
63
|
-
# FIXME, should be proper message
|
64
|
-
# message "#{body["message"]}: #{body["details"]}", true, 'red'
|
65
63
|
message "#{body["details"]}", true, 'red'
|
66
64
|
exit!
|
67
65
|
else
|
@@ -96,7 +94,7 @@ module App42
|
|
96
94
|
what.nil? ? (resource_url = "/#{resource}") : (resource_url = "/#{resource}/#{what}")
|
97
95
|
end
|
98
96
|
|
99
|
-
#
|
97
|
+
# Generate signature using requested params and Secret key
|
100
98
|
#
|
101
99
|
# @params +requested params+
|
102
100
|
#
|
@@ -166,6 +164,49 @@ module App42
|
|
166
164
|
end
|
167
165
|
end
|
168
166
|
|
167
|
+
# checks transaction status of setup cloud API
|
168
|
+
#
|
169
|
+
#REVIEW, need to verify FAILED use case
|
170
|
+
def check_transaction_status_of_setup transaction_id, previous_completed, what
|
171
|
+
begin
|
172
|
+
flag = false
|
173
|
+
message "#{Message::LATEST_S_WAIT}", false, 'green'
|
174
|
+
while flag == false do
|
175
|
+
response = status_call transaction_id
|
176
|
+
re_try ||= 1
|
177
|
+
|
178
|
+
if response["success"] == true && response["transactionStatus"] == "COMPLETED"
|
179
|
+
print_new_line
|
180
|
+
message "#{response["message"]}", true, 'green'
|
181
|
+
return true
|
182
|
+
elsif response["success"] == true && response["transactionStatus"] == "INPROGRESS"
|
183
|
+
if previous_completed != response["completed"]
|
184
|
+
print_new_line
|
185
|
+
puts Paint["#{response["completed"]} out of #{response["requested"]} #{what}", :green]
|
186
|
+
previous_completed = response["completed"]
|
187
|
+
end
|
188
|
+
show_wait_spinner{
|
189
|
+
sleep rand(4)+2
|
190
|
+
}
|
191
|
+
unless what.to_s == 'Uploaded'
|
192
|
+
if(re_try += 1 ) >= 250
|
193
|
+
message "#{Message::REQUEST_PROGRESS}", true, 'red'
|
194
|
+
exit!
|
195
|
+
end
|
196
|
+
end
|
197
|
+
else response["success"] == true && response["transactionStatus"] == "FAILED"
|
198
|
+
print_new_line
|
199
|
+
message "#{response["message"]}", true, 'red'
|
200
|
+
exit!
|
201
|
+
end
|
202
|
+
sleep 5
|
203
|
+
end
|
204
|
+
rescue Interrupt
|
205
|
+
message "#{Message::LATEST_S_INTERRUPT}", true, 'red'
|
206
|
+
exit!
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
169
210
|
# rest call for transaction status check
|
170
211
|
def status_call transaction_id
|
171
212
|
begin
|
@@ -244,7 +285,7 @@ module App42
|
|
244
285
|
end
|
245
286
|
|
246
287
|
# Check whether +app OR service+ name is valid OR not
|
247
|
-
# +app OR service+ name
|
288
|
+
# +app OR service+ name length should not be more than 30 character
|
248
289
|
# And should not contain any special character
|
249
290
|
def validate_app_and_service_name name, str
|
250
291
|
if str.match(App42::REGEX) || str.length > 30
|
@@ -255,8 +296,20 @@ module App42
|
|
255
296
|
end
|
256
297
|
end
|
257
298
|
|
299
|
+
# Check whether +setup+ name is valid OR not
|
300
|
+
# +setup+ name length should not be more than 30 character
|
301
|
+
# And should not contain any special character
|
302
|
+
def validate_setup_name name, str
|
303
|
+
if str.match(App42::REGEX) || str.length > 30
|
304
|
+
message "#{name} should not contain any special character or white space and length should be less than 30.", true, 'red'
|
305
|
+
return false
|
306
|
+
else
|
307
|
+
return str
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
258
311
|
# Check whether +database name+ is valid OR not
|
259
|
-
# +database name+
|
312
|
+
# +database name+ length should not be more than 64 character
|
260
313
|
# And should not contain any special character
|
261
314
|
def validate_database_name name, str
|
262
315
|
if str.match(App42::DBNAME_REGEX) || str.length > 64 || (numeric_including_zero? str)
|
@@ -270,6 +323,18 @@ module App42
|
|
270
323
|
end
|
271
324
|
end
|
272
325
|
|
326
|
+
# Check whether +vm config+ is valid OR not
|
327
|
+
# +vm config+ should be a valid number
|
328
|
+
# And should not contain any special character
|
329
|
+
def validate_vm_config kontena
|
330
|
+
unless numeric?(kontena)
|
331
|
+
message "#{Message::NOT_A_VALID_KONTENA}", true, 'red'
|
332
|
+
false
|
333
|
+
else
|
334
|
+
return kontena
|
335
|
+
end
|
336
|
+
end
|
337
|
+
|
273
338
|
# rest call to server to check whether +application+ exist OR not.
|
274
339
|
# return true if +application+ exist else display ERROR message and exit
|
275
340
|
def is_app_exist? app_name
|
@@ -301,6 +366,32 @@ module App42
|
|
301
366
|
exit!
|
302
367
|
end
|
303
368
|
end
|
369
|
+
|
370
|
+
# rest call to server to check whether +setup name+ exist OR not.
|
371
|
+
# return true if +setup name+ exist else display ERROR message and exit
|
372
|
+
def is_setup_name_exist? setup_name
|
373
|
+
query_params = params
|
374
|
+
query_params.store('setupName', setup_name)
|
375
|
+
|
376
|
+
response = build_get_request query_params, 'setup', 'availability'
|
377
|
+
unless response["success"]
|
378
|
+
return true
|
379
|
+
else
|
380
|
+
message "Setup name with the name #{setup_name} does not exist.", true, 'red'
|
381
|
+
exit!
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
# Check whether +git URL+ is valid OR not
|
386
|
+
# given +git URL+ must end with +.git+ extension
|
387
|
+
def validate_git_url git_url
|
388
|
+
unless git_url.include?('.git')
|
389
|
+
message "#{Message::GIT_URL_NOT_VALID}", true, 'red'
|
390
|
+
return false
|
391
|
+
else
|
392
|
+
return git_url
|
393
|
+
end
|
394
|
+
end
|
304
395
|
|
305
396
|
end
|
306
397
|
end
|
@@ -14,13 +14,11 @@ module App42
|
|
14
14
|
@exception_msg = nil
|
15
15
|
end
|
16
16
|
|
17
|
-
#
|
18
17
|
# @param signature
|
19
18
|
# @param url
|
20
19
|
# @param params
|
21
20
|
# @return
|
22
21
|
# @rescue Exception
|
23
|
-
#
|
24
22
|
def get(signature, url, params)
|
25
23
|
params.store("signature", signature)
|
26
24
|
resource, json_obj = "", nil
|
@@ -98,14 +96,12 @@ module App42
|
|
98
96
|
exit!
|
99
97
|
end
|
100
98
|
|
101
|
-
#
|
102
99
|
# @param signature
|
103
100
|
# @param url
|
104
101
|
# @param params
|
105
102
|
# @param bodyPayload
|
106
103
|
# @return
|
107
104
|
# @rescue Exception
|
108
|
-
#
|
109
105
|
def post(signature, url, params, body)
|
110
106
|
params.store("signature", signature)
|
111
107
|
resource = ""
|
@@ -181,14 +177,12 @@ module App42
|
|
181
177
|
exit!
|
182
178
|
end
|
183
179
|
|
184
|
-
#
|
185
180
|
# @param signature
|
186
181
|
# @param url
|
187
182
|
# @param params
|
188
183
|
# @param bodyPayload
|
189
184
|
# @return
|
190
185
|
# @rescue Exception
|
191
|
-
#
|
192
186
|
def put(signature, url, params, body)
|
193
187
|
params.store("signature", signature)
|
194
188
|
resource = ""
|
@@ -264,13 +258,11 @@ module App42
|
|
264
258
|
exit!
|
265
259
|
end
|
266
260
|
|
267
|
-
#
|
268
261
|
# @param signature
|
269
262
|
# @param url
|
270
263
|
# @param params
|
271
264
|
# @return
|
272
265
|
# @rescue Exception
|
273
|
-
#
|
274
266
|
def delete(signature, url, params)
|
275
267
|
params.store("signature", signature)
|
276
268
|
resource = ""
|
data/lib/app42/command/app.rb
CHANGED
@@ -7,7 +7,7 @@ module App42
|
|
7
7
|
module Command
|
8
8
|
class App < Base
|
9
9
|
|
10
|
-
#
|
10
|
+
# collect all required attributes for new VM spawn
|
11
11
|
def setup_infra
|
12
12
|
app_name = get_app_name_and_check_app_url_availability
|
13
13
|
vm_type = get_vm_types
|
@@ -15,37 +15,60 @@ module App42
|
|
15
15
|
app_name, source_url = get_app_source app_name, iaas, vm_type
|
16
16
|
end
|
17
17
|
|
18
|
-
#
|
18
|
+
# collect all required attributes for app deploy
|
19
19
|
def deploy
|
20
20
|
@options[:name] = get_app_name if @options[:name].nil?
|
21
21
|
response = interactive_get 'info', 'app/uploadtypes' if is_app_exist? @options[:name]
|
22
22
|
app_source_type = response['sourceTypes']
|
23
23
|
|
24
24
|
if response['sourceTypes'].count > 1
|
25
|
-
|
26
|
-
|
25
|
+
source_type = ask_app_source response['sourceTypes']
|
26
|
+
if source_type == 'Source'
|
27
|
+
git_url = get_git_url
|
28
|
+
status = upload_binary @options[:name], source_type, git_url if validate_git_url git_url
|
29
|
+
else
|
30
|
+
status = get_binary_url @options[:name]
|
31
|
+
end
|
27
32
|
else
|
28
33
|
status = get_binary_url @options[:name]
|
29
34
|
end
|
30
35
|
exit! if status
|
31
36
|
end
|
32
37
|
|
38
|
+
# collect all required attributes for app update
|
39
|
+
def update
|
40
|
+
@options[:name] = get_app_name if @options[:name].nil?
|
41
|
+
response = interactive_get 'info', 'app/uploadtypes' if is_app_exist? @options[:name]
|
42
|
+
app_source_type = response['sourceTypes']
|
43
|
+
|
44
|
+
if response['sourceTypes'].count > 1
|
45
|
+
source_type = ask_app_source response['sourceTypes']
|
46
|
+
if source_type == 'Source'
|
47
|
+
status = update_binary @options[:name]
|
48
|
+
else
|
49
|
+
status = get_binary_url @options[:name]
|
50
|
+
end
|
51
|
+
else
|
52
|
+
status = get_binary_url @options[:name]
|
53
|
+
end
|
54
|
+
exit! if status
|
55
|
+
end
|
56
|
+
|
33
57
|
# @param app_name
|
34
|
-
#
|
35
|
-
#
|
58
|
+
#
|
59
|
+
# collect app source type
|
36
60
|
#
|
61
|
+
# pass app name, app source and source url to binary upload methods
|
37
62
|
def get_binary_url app_name
|
38
63
|
app_source, source_url = collect_app_source app_name
|
39
64
|
status = upload_binary app_name, app_source, source_url
|
40
65
|
return status
|
41
66
|
end
|
42
67
|
|
43
|
-
#
|
44
68
|
# @param app_name
|
45
69
|
# @param iaas
|
46
70
|
# @param vm_type
|
47
71
|
# @return host name
|
48
|
-
#
|
49
72
|
def collect_vm_details app_name, iaas, vm_type
|
50
73
|
runtime = get_runtime
|
51
74
|
framework = get_framework iaas, vm_type, runtime
|
@@ -53,16 +76,14 @@ module App42
|
|
53
76
|
os = get_os_for_app iaas, vm_type, runtime, framework, webserver
|
54
77
|
# FIXME, may be configure out later
|
55
78
|
# instance = get_instance 'new_vm'
|
56
|
-
|
57
|
-
setup_infra_res = App42::Command::Base.new.create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os,
|
79
|
+
kontena = get_vmconfig
|
80
|
+
setup_infra_res = App42::Command::Base.new.create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os, kontena
|
58
81
|
exit! if setup_infra_res
|
59
82
|
end
|
60
83
|
|
61
|
-
#
|
62
84
|
# @param deployment path
|
63
85
|
# @param app_name
|
64
|
-
# @return
|
65
|
-
#
|
86
|
+
# @return binary name
|
66
87
|
def is_binary_exist? source_url, app_name
|
67
88
|
path = escape_path(source_url)
|
68
89
|
app_file_name = nil
|
@@ -80,37 +101,31 @@ module App42
|
|
80
101
|
return app_file_name
|
81
102
|
end
|
82
103
|
|
83
|
-
#
|
84
104
|
# ask existing app url for deploy
|
85
|
-
#
|
86
105
|
def ask_existing_app_url
|
87
106
|
input "Enter App URL", [], true
|
88
107
|
end
|
89
108
|
|
90
109
|
# @param app_source_url
|
110
|
+
# @return upload type
|
91
111
|
def ask_app_source app_source_type
|
92
|
-
input "Choose
|
112
|
+
input "Choose Upload Type", app_source_type, true
|
93
113
|
end
|
94
114
|
|
95
|
-
#
|
96
115
|
# @param binary/git
|
97
116
|
# @return path
|
98
|
-
#
|
99
117
|
def get_source_path app_source
|
100
118
|
path = ask(Paint["#{app_source.capitalize} Deployment Path", :cyan])
|
101
119
|
return path.strip
|
102
120
|
end
|
103
121
|
|
104
|
-
#
|
105
122
|
# collect git URL from user
|
106
|
-
|
107
|
-
def get_git_url(prompt = Paint["Deployment Path?", :cyan])
|
123
|
+
def get_git_url(prompt = Paint["Enter Git URL?", :cyan])
|
108
124
|
ask(prompt) {|q| q.each = true}
|
109
125
|
end
|
110
126
|
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
127
|
+
# read +app name+ and number of +instance+ from user
|
128
|
+
# then scale app by no of instance
|
114
129
|
def scale
|
115
130
|
@options[:name] = get_app_name if @options[:name].nil?
|
116
131
|
@options[:instance] = get_instance __method__ if is_app_exist? @options[:name] and @options[:instance].nil?
|
@@ -118,9 +133,8 @@ module App42
|
|
118
133
|
exit! if scale_or_descal_res
|
119
134
|
end
|
120
135
|
|
121
|
-
#
|
122
|
-
#
|
123
|
-
#
|
136
|
+
# read +app name+ and number of +instance+ from user
|
137
|
+
# then descale app by no of instance
|
124
138
|
def descale
|
125
139
|
@options[:name] = get_app_name if @options[:name].nil?
|
126
140
|
@options[:instance] = get_instance __method__ if is_app_exist? @options[:name] and @options[:instance].nil?
|
@@ -130,7 +144,7 @@ module App42
|
|
130
144
|
|
131
145
|
# app42 start
|
132
146
|
#
|
133
|
-
#
|
147
|
+
# start the app, return true or error code/message
|
134
148
|
#
|
135
149
|
def start
|
136
150
|
@options[:name] = get_app_name if @options[:name].nil?
|
@@ -140,7 +154,7 @@ module App42
|
|
140
154
|
|
141
155
|
# app42 stop
|
142
156
|
#
|
143
|
-
#
|
157
|
+
# stop the app, return true or error code/message
|
144
158
|
#
|
145
159
|
def stop
|
146
160
|
@options[:name] = get_app_name if @options[:name].nil?
|
@@ -148,9 +162,9 @@ module App42
|
|
148
162
|
exit! if app_operation_req
|
149
163
|
end
|
150
164
|
|
151
|
-
# app42
|
165
|
+
# app42 restart
|
152
166
|
#
|
153
|
-
#
|
167
|
+
# restart the app, return true or error code/message
|
154
168
|
#
|
155
169
|
def restart
|
156
170
|
@options[:name] = get_app_name if @options[:name].nil?
|
@@ -158,8 +172,9 @@ module App42
|
|
158
172
|
exit! if app_operation_req
|
159
173
|
end
|
160
174
|
|
175
|
+
# app42 delete
|
161
176
|
#
|
162
|
-
#
|
177
|
+
# delete the app, return true or error code/message
|
163
178
|
#
|
164
179
|
def delete
|
165
180
|
@options[:name] = get_app_name if @options[:name].nil?
|
@@ -167,9 +182,7 @@ module App42
|
|
167
182
|
exit! if app_operation_req
|
168
183
|
end
|
169
184
|
|
170
|
-
#
|
171
185
|
# List deployed applications
|
172
|
-
#
|
173
186
|
def apps
|
174
187
|
response = build_get_request params, 'app', nil
|
175
188
|
rows, rows_header_final, rows_header = [], [], nil
|