app42 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ module App42::Command
11
11
  check_key_file?
12
12
  end
13
13
 
14
- def is_authorize?(api_key, secret_key)
14
+ def is_authorize?(api_key, secret_key) #:ndoc
15
15
  if api_key.nil? || secret_key.nil?
16
16
  message "#{Message::ADD_KEY}", true, 'red'
17
17
  puts App42::Base::Help.addkeys
@@ -33,6 +33,17 @@ module App42
33
33
  app_name = get_app_name
34
34
  available = app_url_availability app_name
35
35
  return available if available
36
+ end
37
+
38
+ # collect setup name from user
39
+ # if setup name will not available
40
+ # User can try 3 more times with different setup name
41
+ def get_setup_name_and_check_setup_url_availability
42
+ @aa_retry ||= 1
43
+ exit! if (@aa_retry += 1 ) >= 5
44
+ setup_name = get_setup_name
45
+ available = setup_url_availability setup_name
46
+ return available if available
36
47
  end
37
48
 
38
49
  # get supported virtual machine type by app42paas
@@ -68,6 +79,14 @@ module App42
68
79
  valid_app_name ? (return valid_app_name) : get_app_name
69
80
  end
70
81
 
82
+ # Ask setup name from user and
83
+ # will wait for user response (user will enter setup name)
84
+ def get_setup_name(prompt = Paint['Enter Setup Name', :cyan])
85
+ setup_name = ask(prompt) {|q| q.each = true}
86
+ valid_setup_name = validate_setup_name "Setup name", setup_name.strip
87
+ valid_setup_name ? (return valid_setup_name) : get_setup_name
88
+ end
89
+
71
90
  # get supported runtime by app42paas
72
91
  def get_runtime
73
92
  runtime_hash = {}
@@ -142,16 +161,10 @@ module App42
142
161
  end
143
162
 
144
163
  # get supported vm configuration by app42paas
145
- def get_vmconfig resource, vm_type, iaas
146
- vmconfig_hash = {}
147
- vmconfig = App42::Command::Config.new.get_vmconfig(resource, vm_type, iaas)
148
-
149
- vmconfig['vmconfig'].select {|each_vmcf| vmconfig_hash["#{each_vmcf['id']}"] = each_vmcf['memory'] + ' ' + each_vmcf['memoryUnit']}
150
- vm_cf = input "Memory Limit", vmconfig_hash.values, true
151
-
152
- vm_cf_id = nil
153
- vmconfig_hash.each_pair{|vmcf| vm_cf_id = vmcf[0] if vmcf[1] == vm_cf}
154
- return vm_cf_id
164
+ def get_vmconfig
165
+ kontena = input "Specify Kontena Power", [], true
166
+ valid = validate_vm_config kontena
167
+ valid ? (return valid) : get_vmconfig
155
168
  end
156
169
 
157
170
  # collect type of application source supported by app42paas
@@ -198,6 +211,25 @@ module App42
198
211
 
199
212
  end
200
213
 
214
+ # check setup name availabilities
215
+ def setup_url_availability setup_name
216
+ query_params = params
217
+ query_params.store('setupName', setup_name)
218
+
219
+ response = with_progress(Paint["Checking Setup Name Availability", :yellow]) do |s|
220
+ build_get_request query_params, 'setup', 'availability'
221
+ end
222
+
223
+ if response["success"]
224
+ print_new_line
225
+ return setup_name
226
+ else
227
+ message "#{response['description']}", true, 'red'
228
+ get_setup_name_and_check_setup_url_availability
229
+ end
230
+
231
+ end
232
+
201
233
  # check service availabilities
202
234
  def service_name_availability service_name
203
235
  query_params = params
@@ -217,17 +249,17 @@ module App42
217
249
  end
218
250
 
219
251
  # infrastructure setup call
220
- def create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os, vmconfig
252
+ def create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os, kontena
221
253
  begin
222
254
  body = {'app42' => {"request"=> {
223
- "appName" => app_name,
224
- "iaas" => iaas,
225
- "vmType" => vm_type,
226
- "runtime" => runtime,
227
- "framework" => framework,
228
- "webServer" => webserver,
229
- "os" => os,
230
- "vmConfig" => vmconfig
255
+ "appName" => app_name,
256
+ "iaas" => iaas,
257
+ "vmType" => vm_type,
258
+ "runtime" => runtime,
259
+ "framework" => framework,
260
+ "webServer" => webserver,
261
+ "os" => os,
262
+ "kontenaPower" => kontena
231
263
  }}}.to_json
232
264
 
233
265
  query_params = params
@@ -259,6 +291,47 @@ module App42
259
291
  end
260
292
  end
261
293
 
294
+ # setup cloud API
295
+ def create_cloud_setup setup_name, iaas, vm_type, setup_type, flavour
296
+ begin
297
+ body = {'app42' => {"request"=> {
298
+ "setupName" => setup_name,
299
+ "iaas" => iaas,
300
+ "vmType" => vm_type,
301
+ "setupType" => setup_type,
302
+ "flavour" => flavour
303
+ }}}.to_json
304
+
305
+ query_params = params
306
+ query_params.store('body', body)
307
+
308
+ response = with_progress(Paint["Setting up the infrastructure", :yellow]) do |s|
309
+ build_post_request body, query_params, 'setup', nil
310
+ end
311
+
312
+ if response["success"] == true && response["transactionId"]
313
+ transaction_success = check_transaction_status_of_setup response["transactionId"], previous_completed = 0, 'created'
314
+ end
315
+
316
+ if transaction_success
317
+ transaction_params = params
318
+ transaction_params.store('setupName', setup_name)
319
+ host_response = build_get_request transaction_params, "setup", "#{setup_name}"
320
+ end
321
+
322
+ if host_response['success']
323
+ puts Paint["Your setup has been completed successfully, For details, Login you your AppHQ console.", :green]
324
+ return true
325
+ else
326
+ puts Paint["#{response['description']}", :red]
327
+ end
328
+ rescue Interrupt
329
+ puts Paint[" Command cancelled.", :red]
330
+ exit!
331
+ end
332
+ end
333
+
334
+
262
335
  # Binary upload call
263
336
  def upload_binary app_name, app_source, source_url
264
337
  @code_flag ||= 1
@@ -268,21 +341,21 @@ module App42
268
341
  query_params.store('appName', app_name)
269
342
  message "#{Message::WAIT_FOR_WHILE}", true, 'green'
270
343
  response = with_progress(Paint["Deploying Application", :yellow]) do |s|
271
- @connection.multipart(signature(query_params), resource_url("app", "binary"), query_params, query_params, source_url)
344
+ @connection.multipart(signature(query_params), resource_url("app/deploy", "binary"), query_params, query_params, source_url)
272
345
  end
273
346
  else
274
347
  body = {'app42' => {"request"=> {
275
348
  "appName" => app_name,
276
- "sourcetype" => app_source,
349
+ "sourceType" => app_source,
277
350
  "sourceUrl" => source_url,
278
351
  }}}.to_json
279
-
352
+
280
353
  query_params = params
281
354
  query_params.store('body', body)
282
355
 
283
356
 
284
357
  response = with_progress(Paint["Deploying Application", :yellow]) do |s|
285
- build_put_request body, query_params, 'app', 'source'
358
+ build_put_request body, query_params, 'app/deploy', 'source'
286
359
  end
287
360
  end
288
361
 
@@ -306,6 +379,41 @@ module App42
306
379
  return response
307
380
  end
308
381
 
382
+ # Binary update call
383
+ def update_binary app_name
384
+ @code_flag ||= 1
385
+ begin
386
+ body = {'app42' => {"request"=> {
387
+ "appName" => app_name
388
+ }}}.to_json
389
+
390
+ query_params = params
391
+ query_params.store('body', body)
392
+
393
+
394
+ response = with_progress(Paint["Updating Application", :yellow]) do |s|
395
+ build_put_request body, query_params, 'app/update', 'source'
396
+ end
397
+ if response["success"] == true && response["transactionId"]
398
+ check_transaction_status response["transactionId"], previous_completed = 0, 'Uploaded'
399
+ end
400
+
401
+ if response['success']
402
+ exit!
403
+ else
404
+ puts Paint["#{response['description']}", :red]
405
+ exit 1 if ( @code_flag += 1 ) > 3
406
+ get_binary_url app_name
407
+ end
408
+ rescue Interrupt
409
+ puts Paint[" Command cancelled.", :red]
410
+ exit!
411
+ rescue Exception => e
412
+ puts e
413
+ end
414
+ return response
415
+ end
416
+
309
417
  # It's common methods of app information like app state, info etc.
310
418
  # methods expect +what+ as operation and +app_name+ as Application name
311
419
  def app_information what, app_name
@@ -421,14 +529,14 @@ module App42
421
529
  # ==== return
422
530
  # will display service details in tabular form and
423
531
  # will exist console
424
- def create_service service, service_name ,database, vm_type, iaas, vmconfig, os
532
+ def create_service service, service_name ,database, vm_type, iaas, kontena, os
425
533
  body = {'app42' => {"request"=> {
426
- "service" => service,
427
- "serviceName" => service_name,
428
- "vmType" => vm_type,
429
- "database" => database,
430
- "iaas" => iaas,
431
- "vmconfig" => vmconfig,
534
+ "service" => service,
535
+ "serviceName" => service_name,
536
+ "vmType" => vm_type,
537
+ "database" => database,
538
+ "iaas" => iaas,
539
+ "kontenaPower" => kontena,
432
540
  "os" => os
433
541
  }}}.to_json
434
542
 
@@ -498,6 +606,34 @@ module App42
498
606
  end
499
607
  end
500
608
 
609
+ # delete setup cloud API, as a
610
+ #
611
+ # ==== Parameters
612
+ # setup_name = setup_name provided by user
613
+ #
614
+ # ==== return
615
+ # true:: if cloud setup deleted
616
+ # OR
617
+ # ERROR message in case failed
618
+ def delete_clouldapi setup_name
619
+ begin
620
+ response = with_progress(Paint["Deleting Clould API", :yellow]) do |s|
621
+ query_params = params
622
+ query_params.store('setupName', setup_name)
623
+ build_delete_request query_params, "setup", "#{setup_name}"
624
+ end
625
+
626
+ transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"]
627
+
628
+ response['success'] ? (return true) : (message "#{response['description']}", true, 'red')
629
+ rescue Interrupt
630
+ puts Paint[" Command cancelled.", :red]
631
+ exit!
632
+ rescue Exception => e
633
+ puts e
634
+ end
635
+ end
636
+
501
637
  # reset service password and fetch service latest details
502
638
  #
503
639
  # ==== Parameters
@@ -542,6 +678,48 @@ module App42
542
678
  end
543
679
  end
544
680
 
681
+
682
+ # All application operation will take placed like app start, stop etc.
683
+ # expect +what+ as operation and +app_name+ as application name.
684
+ def service_operation what, service_name
685
+ begin
686
+ if what.to_s == 'stop'
687
+ response = with_progress(Paint[ "Stopping Service #{service_name}", :yellow]) do |s|
688
+ body = {'app42' => {"request"=> {
689
+ "serviceName" => service_name
690
+ }}}.to_json
691
+
692
+ query_params = params
693
+ query_params.store('body', body)
694
+ build_put_request body, query_params, "service", "#{what}" if what.to_s == 'stop'
695
+ end
696
+ else
697
+ response = with_progress(Paint["#{what.capitalize}ing Service #{service_name}", :yellow]) do |s|
698
+ body = {'app42' => {"request"=> {
699
+ "serviceName" => service_name
700
+ }}}.to_json
701
+
702
+ query_params = params
703
+ query_params.store('body', body)
704
+ build_put_request body, query_params, "service", "#{what}" if what.to_s == 'restart' || what.to_s == 'start'
705
+ end
706
+ end
707
+
708
+ if response["success"] == true && response["transactionId"]
709
+ if what.to_s == 'stop'
710
+ check_transaction_status response["transactionId"], previous_completed = 0, "#{what}ped"
711
+ else
712
+ check_transaction_status response["transactionId"], previous_completed = 0, "#{what}ed"
713
+ end
714
+ end
715
+
716
+ response['success'] ? (return true) : (message "#{response['description']}", true, 'red')
717
+ rescue Interrupt
718
+ puts Paint[" Command cancelled.", :red]
719
+ exit!
720
+ end
721
+ end
722
+
545
723
  # Bind service to requested source IP and fetch service latest details
546
724
  #
547
725
  # ==== Parameters
@@ -127,7 +127,7 @@ module App42
127
127
  set_cmd(:app, :setup_infra)
128
128
 
129
129
  when 'update'
130
- set_cmd(:app, :deploy)
130
+ set_cmd(:app, :update)
131
131
 
132
132
  when 'keys'
133
133
  set_cmd(:user, :keys)
@@ -201,6 +201,15 @@ module App42
201
201
  when 'deleteservice'
202
202
  set_cmd(:service, :delete)
203
203
 
204
+ when 'startservice'
205
+ set_cmd(:service, :start)
206
+
207
+ when 'restartservice'
208
+ set_cmd(:service, :restart)
209
+
210
+ when 'stopservice'
211
+ set_cmd(:service, :stop)
212
+
204
213
  when 'resetservicepassword'
205
214
  set_cmd(:service, :reset_pass)
206
215
 
@@ -211,7 +220,19 @@ module App42
211
220
  set_cmd(:service, :service_unbind)
212
221
 
213
222
  when 'bindinfo'
214
- set_cmd(:service, :service_bindInfo)
223
+ set_cmd(:service, :service_bindInfo)
224
+
225
+ when 'setupcloudapi'
226
+ set_cmd(:setup, :setup_cloud_api)
227
+
228
+ when 'deletecloudapi'
229
+ set_cmd(:setup, :delete_cloud_api)
230
+
231
+ when 'setupinfo'
232
+ set_cmd(:setup, :info)
233
+
234
+ when 'setups'
235
+ set_cmd(:setup, :setups)
215
236
 
216
237
  else
217
238
  puts Paint["app42: Unknown command [#{action}]", :red]
@@ -33,6 +33,20 @@ module App42::Command
33
33
  build_get_request params, 'info', 'runtimes'
34
34
  end
35
35
 
36
+ #
37
+ # return list of setup type
38
+ #
39
+ def get_setup_type_fm_server
40
+ build_get_request params, 'info', 'setuptype'
41
+ end
42
+
43
+ #
44
+ # return list of flavour
45
+ #
46
+ def get_flavour_type_fm_server
47
+ build_get_request params, 'info', 'flavour'
48
+ end
49
+
36
50
  #
37
51
  # return list of templates
38
52
  #
@@ -6,7 +6,7 @@ module App42
6
6
  class Info < Base
7
7
 
8
8
  #
9
- # return user activites
9
+ # return user activities
10
10
  #
11
11
  def get_activities
12
12
  build_get_request params, 'info', 'activities'
@@ -83,9 +83,9 @@ module App42::Command
83
83
 
84
84
  os = get_os_for_service iaas, vm_type, service
85
85
 
86
- vmconfig = get_vmconfig 'info/service', vm_type, iaas
86
+ kontena = get_vmconfig
87
87
 
88
- create_service service, service_name , database, vm_type, iaas, vmconfig, os
88
+ create_service service, service_name , database, vm_type, iaas, kontena, os
89
89
 
90
90
  end
91
91
 
@@ -96,6 +96,27 @@ module App42::Command
96
96
  exit! if response
97
97
  end
98
98
 
99
+ # collect service name from user and proceed service start request
100
+ def start
101
+ @options[:service] = ask_service_name if @options[:service].nil?
102
+ response = service_operation __method__, @options[:service] if is_service_exist? @options[:service]
103
+ exit! if response
104
+ end
105
+
106
+ # collect service name from user and proceed service restart request
107
+ def restart
108
+ @options[:service] = ask_service_name if @options[:service].nil?
109
+ response = service_operation __method__, @options[:service] if is_service_exist? @options[:service]
110
+ exit! if response
111
+ end
112
+
113
+ # collect service name from user and proceed service stop request
114
+ def stop
115
+ @options[:service] = ask_service_name if @options[:service].nil?
116
+ response = service_operation __method__, @options[:service] if is_service_exist? @options[:service]
117
+ exit! if response
118
+ end
119
+
99
120
  # collect service name from user and proceed service resetPassword request
100
121
  def reset_pass
101
122
  @options[:service] = ask_service_name if @options[:service].nil?