lib/app42/command/base.rb in app42-0.5.8 vs lib/app42/command/base.rb in app42-0.5.9

- old
+ new

@@ -71,12 +71,12 @@ collect_vm_details app_name, iaas, vm_type end # Ask application name from user and # will wait for user response (user will enter application name) - def get_app_name(prompt = Paint['Enter App Name', :cyan]) - app_name = ask(prompt) {|q| q.each = true} + def get_app_name + app_name = input "Enter App Name", [], true valid_app_name = validate_app_and_service_name "App name", app_name.strip valid_app_name ? (return valid_app_name) : get_app_name end # Ask setup name from user and @@ -412,10 +412,44 @@ puts e end return response end + # upload service backup + # @params service name, file upload path and restore(wanted to restore running db) + def upload_service_backup service_name, path, restore + begin + query_params = params + query_params.store('serviceName', service_name) + query_params.store('restore', restore.to_s) + message "#{Message::WAIT_FOR_WHILE}", true, 'green' + response = with_progress(Paint["Uploading Service Backup", :yellow]) do |s| + @connection.multipart(signature(query_params), resource_url("service/backup", "upload"), query_params, query_params, path) + end + + if response["success"] == true && response["transactionId"] + check_transaction_status response["transactionId"], previous_completed = 0, 'Uploaded' + else response["success"] == true + message "#{response['message']}", true, 'green' + exit! + end + + if response['success'] + exit! + else + puts Paint["#{response['description']}", :red] + exit! + end + rescue Interrupt + puts Paint[" Command cancelled.", :red] + exit! + rescue Exception => e + puts e + end + return response + end + # It's common methods of app information like app state, info etc. # methods expect +what+ as operation and +app_name+ as Application name def app_information what, app_name query_params = params query_params.store('appName', app_name) @@ -454,10 +488,38 @@ puts e exit! end end + # vertical scale or descale application by no of kontena, + # expect +what+ as operation and kontena as no of kontena + def vscale_or_vdescale_app what, kontena, app_name + begin + body = {'app42' => {"request"=> { + 'appName' => app_name, + "kontenaPower" => kontena.to_s + }}}.to_json + + query_params = params + query_params.store('body', body) + + response = with_progress( Paint[ what.to_s == 'vscale' ? "Scaling Application #{app_name} by kontena(s) #{kontena}" : "Descaling Application #{app_name} by kontena(s) #{kontena}", :yellow]) do |s| + build_post_request body, query_params, "app", what + end + + check_transaction_status response["transactionId"], previous_completed = 0, "#{what}d" if response["success"] == true && response["transactionId"] + response['success'] ? (return true) : (message "#{response['description']}", true, 'red') + + rescue Interrupt + puts Paint[" Command cancelled.", :red] + exit! + rescue Exception => e + puts e + exit! + end + end + # common methods for app42paas config request like runtimes,frameworks etc def interactive_get resource, get_obj begin response = build_get_request params, resource, get_obj rescue Exception => e @@ -632,10 +694,51 @@ rescue Exception => e puts e end end + # All application operation will take placed like app start, stop etc. + # expect +what+ as operation and +setup_name+ as BPaaS name. + def clouldapi_operation what, setup_name + begin + if what.to_s == 'stop' + response = with_progress(Paint[ "Stopping BPaaS Setup #{setup_name}", :yellow]) do |s| + body = {'app42' => {"request"=> { + "setupName" => setup_name + }}}.to_json + + query_params = params + query_params.store('body', body) + build_put_request body, query_params, "setup", "#{what}" if what.to_s == 'stop' + end + else + response = with_progress(Paint["#{what.capitalize}ing BPaaS Setup #{setup_name}", :yellow]) do |s| + body = {'app42' => {"request"=> { + "setupName" => setup_name + }}}.to_json + + query_params = params + query_params.store('body', body) + build_put_request body, query_params, "setup", "#{what}" if what.to_s == 'restart' || what.to_s == 'start' + end + end + + if response["success"] == true && response["transactionId"] + if what.to_s == 'stop' + check_transaction_status response["transactionId"], previous_completed = 0, "#{what}ped" + else + check_transaction_status response["transactionId"], previous_completed = 0, "#{what}ed" + end + end + + response['success'] ? (return true) : (message "#{response['description']}", true, 'red') + rescue Interrupt + puts Paint[" Command cancelled.", :red] + exit! + end + end + # reset service password and fetch service latest details # # ==== Parameters # service_name = service name provided by user # service_token = service token @@ -678,11 +781,11 @@ end end # All application operation will take placed like app start, stop etc. - # expect +what+ as operation and +app_name+ as application name. + # expect +what+ as operation and +service_name+ as Service name. def service_operation what, service_name begin if what.to_s == 'stop' response = with_progress(Paint[ "Stopping Service #{service_name}", :yellow]) do |s| body = {'app42' => {"request"=> { @@ -829,9 +932,29 @@ if instance_count return instance_count else message "#{Message::NOT_A_VALID_NUM}", true, 'red' get_instance obj + end + end + + # + # return no of kontena power + # + def get_kontena obj + kontena = @options[:kontena] if @options[:kontena] + unless kontena + kontena = nil + kontena = ask Paint[ "#{obj.capitalize} by kontena power(s)", :cyan], :default => 1 + end + + kontena_count = number_valid? kontena + + if kontena_count + return kontena_count + else + message "#{Message::NOT_A_VALID_NUM}", true, 'red' + get_kontena obj end end end end end \ No newline at end of file