Class: App42::Command::Base
- Inherits:
-
Object
- Object
- App42::Command::Base
- Includes:
- Base::HttpHelper, Base::Util, UserToken, Interact::Progress, Interactive
- Defined in:
- lib/app42/command/base.rb
Instance Method Summary collapse
-
#app_information(what, app_name) ⇒ Object
It’s common methods of app information like app state, info etc.
-
#app_operation(what, app_name) ⇒ Object
All application operation will take placed like app start, stop etc.
-
#app_url_availability(app_name) ⇒ Object
check app availabilities.
-
#cloudapi_operation(what, setup_name) ⇒ Object
All application operation will take placed like app start, stop etc.
-
#collect_app_source(app_name) ⇒ Object
collect type of application source supported by app42paas.
-
#create_cloud_setup(setup_name, iaas, vm_type, setup_type, flavour) ⇒ Object
setup cloud API.
-
#create_gpaas_setup(setup_name, iaas, vm_type, setup_type, flavour) ⇒ Object
setup GPaaS.
-
#create_infrastructure(app_name, iaas, vm_type, runtime, framework, webserver, os, kontena) ⇒ Object
infrastructure setup call.
-
#create_service(service, service_name, database, vm_type, iaas, kontena, os) ⇒ Object
create service and get all relevant service information post service creation.
-
#create_service_tunnel(service_name, source_ip) ⇒ Object
Bind service to requested source IP and fetch service latest details.
-
#create_wordpress_setup(wordpress_name, iaas, vm_type, flavour) ⇒ Object
setup wordpress.
-
#custom_url_information(app_name) ⇒ Object
Get custom URL details.
-
#custom_url_operation(what, app_name, url) ⇒ Object
Custom operation will take placed like add, remove etc.
-
#delete_cloudapi(setup_name) ⇒ Object
delete setup cloud API, as a.
-
#delete_gpaas(setup_name) ⇒ Object
delete GPaaS setup, as a.
-
#delete_service(service_name) ⇒ Object
delete service, as a.
-
#delete_service_tunnel(service_name, source_ip) ⇒ Object
Unbind service to requested source IP.
-
#delete_wordpress(wordpress_name) ⇒ Object
delete wordpress setup, as a.
-
#get_app_name ⇒ Object
Ask application name from user and will wait for user response (user will enter application name).
-
#get_app_name_and_check_app_url_availability ⇒ Object
collect application name from user if application name will not available User can try 3 more times with different application name.
-
#get_app_source(app_name, iaas, vm_type) ⇒ Object
collect remaining vm configuration details from user.
-
#get_custom_url ⇒ Object
Ask custom URL from user and validate.
-
#get_framework(iaas, vm_type, rt) ⇒ Object
get supported frameworks.
-
#get_iaas_providers ⇒ Object
Iaas providers.
-
#get_instance(obj) ⇒ Object
return no of instance.
-
#get_kontena(obj) ⇒ Object
return no of kontena power.
-
#get_os_for_app(iaas, vm_type, rt, framework, webserver) ⇒ Object
get supported operating system for app.
-
#get_os_for_service(iaas, vm_type, service) ⇒ Object
get supported operating system for service.
-
#get_runtime ⇒ Object
get supported runtime by app42paas.
-
#get_setup_name(prompt = ) ⇒ Object
Ask setup name from user and will wait for user response (user will enter setup name).
-
#get_setup_name_and_check_setup_url_availability ⇒ Object
collect setup name from user if setup name will not available User can try 3 more times with different setup name.
- #get_subscription ⇒ Object
-
#get_vm_types ⇒ Object
get supported virtual machine type by app42paas.
-
#get_vmconfig ⇒ Object
get supported vm configuration by app42paas.
-
#get_webserver(iaas, vm_type, rt, framework) ⇒ Object
get supported webserver.
-
#get_wordpress_name ⇒ Object
Ask wordpress name from user and will wait for user response (user will enter wordpress name).
-
#get_wordpress_name_and_check_wordpress_url_availability ⇒ Object
collect wordpress name from user if wordpress name will not available User can try 3 more times with different wordpress name.
-
#gpaas_operation(what, setup_name) ⇒ Object
All GPaaS operation will take placed like start, stop etc.
-
#initialize(options = {}) ⇒ Object
constructor
dup argument to get a non-frozen string.
-
#interactive_get(resource, get_obj) ⇒ Object
common methods for app42paas config request like runtimes,frameworks etc.
-
#reset_password(service_name, service_token) ⇒ Object
reset service password and fetch service latest details.
-
#scale_or_descale_app(what, instance, app_name) ⇒ Object
Scale or descale application by no of instance, expect
what
as operation and instance as no of instance. -
#service_name_availability(service_name) ⇒ Object
check service availabilities.
-
#service_operation(what, service_name) ⇒ Object
All application operation will take placed like app start, stop etc.
-
#setup_url_availability(setup_name) ⇒ Object
check setup name availabilities.
-
#update_binary(app_name) ⇒ Object
Binary update call.
-
#upgrade_or_downgrade_cloudapi(action, setup_name, flavour) ⇒ Object
upgrade setup cloud API, as a.
-
#upgrade_or_downgrade_gpaas(action, setup_name, flavour) ⇒ Object
upgrade GPaaS setup, as a.
-
#upgrade_or_downgrade_wordpress(action, wordpress_name, flavour) ⇒ Object
upgrade Wordpress, as a.
-
#upload_binary(app_name, app_source, source_url) ⇒ Object
Binary upload call.
-
#upload_service_backup(service_name, path, restore) ⇒ Object
upload service backup.
-
#vscale_or_vdescale_app(what, kontena, app_name) ⇒ Object
vertical scale or descale application by no of kontena, expect
what
as operation and kontena as no of kontena. -
#vscale_or_vdescale_service(what, kontena, service_name) ⇒ Object
vertical scale or descale service by no of kontena, expect
what
as operation and kontena as no of kontena. -
#wordpress_operation(what, setup_name) ⇒ Object
All wordpress operation will take placed like app start, stop etc.
-
#wordpress_url_availability(wordpress_name) ⇒ Object
check wordpress name availabilities.
Methods included from Base::HttpHelper
#build_delete_request, #build_get_request, #build_post_request, #build_put_request, #delete_request, #get_request, #post_request, #put_request
Methods included from Base::Util
#app42_client_info, #ask_app_name, #camel_case_to_whitespace, #check_transaction_status, #check_transaction_status_of_setup, #escape_path, #get_flavour_for_upgrade_or_downgrade, #get_instance_config_for_upgrade_or_downgrade, #input, #ip_address_valid?, #is_app_exist?, #is_service_exist?, #is_setup_name_exist?, #json_parse, #message, #number_valid?, #numeric?, #numeric_including_zero?, #params, #parse_error_message, #print_new_line, #request_failed?, #resource_url, #show_wait_spinner, #signature, #status_call, #time_valid?, #util_base, #validate_app_and_service_name, #validate_database_name, #validate_git_url, #validate_setup_name, #validate_upload_backup_path, #validate_url, #validate_vm_config
Methods included from UserToken
#check_key_file?, #config_path, #ensure_config_dir, #ensure_key_file, #get_keys, #key_path, #local_app42_key, #remove_key_file
Constructor Details
#initialize(options = {}) ⇒ Object
dup argument to get a non-frozen string
19 20 21 22 23 24 25 |
# File 'lib/app42/command/base.rb', line 19 def initialize(={} ) @options = .dup @connection = App42::Client::App42RestClient.new HOST @api_key, @secret_key = get_keys if check_key_file? App42::Command::Auth.(@api_key, @secret_key) @host = HOST end |
Instance Method Details
#app_information(what, app_name) ⇒ Object
It’s common methods of app information like app state, info etc. methods expect what
as operation and app_name
as Application name
678 679 680 681 682 683 684 685 686 687 688 |
# File 'lib/app42/command/base.rb', line 678 def app_information what, app_name query_params = params query_params.store('appName', app_name) begin response = build_get_request query_params, "#{what}", "#{app_name}" rescue Exception => e puts e exit! end return response end |
#app_operation(what, app_name) ⇒ Object
All application operation will take placed like app start, stop etc. expect what
as operation and app_name
as application name.
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 |
# File 'lib/app42/command/base.rb', line 782 def app_operation what, app_name begin if what.to_s == 'stop' response = with_progress(Paint[ "Stopping Application #{app_name}", :yellow]) do |s| body = {'app42' => {"request"=> { "appName" => app_name }}}.to_json query_params = params query_params.store('body', body) build_put_request body, query_params, "app", "#{what}" if what.to_s == 'restart' || what.to_s == 'stop' || what.to_s == 'start' end else response = with_progress(Paint[ what.to_s == 'delete' ? "Deleting Application #{app_name}" : "#{what.capitalize}ing Application #{app_name}", :yellow]) do |s| if what.to_s == 'delete' query_params = params query_params.store('appName', app_name) build_delete_request query_params, "app", "#{app_name}" else body = {'app42' => {"request"=> { "appName" => app_name }}}.to_json query_params = params query_params.store('body', body) build_put_request body, query_params, "app", "#{what}" if what.to_s == 'restart' || what.to_s == 'stop' || what.to_s == 'start' end end end if response["success"] == true && response["transactionId"] if what.to_s == 'delete' check_transaction_status response["transactionId"], previous_completed = 0, "#{what}d" elsif 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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#app_url_availability(app_name) ⇒ Object
check app availabilities
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/app42/command/base.rb', line 226 def app_url_availability app_name query_params = params query_params.store('appName', app_name) response = with_progress(Paint["Checking App Name Availability", :yellow]) do |s| build_get_request query_params, 'app', 'availability' end if response["success"] print_new_line return app_name else "#{response['description']}", true, 'red' get_app_name_and_check_app_url_availability end end |
#cloudapi_operation(what, setup_name) ⇒ Object
All application operation will take placed like app start, stop etc. expect what
as operation and setup_name
as BPaaS name.
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 |
# File 'lib/app42/command/base.rb', line 1049 def cloudapi_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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#collect_app_source(app_name) ⇒ Object
collect type of application source supported by app42paas
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/app42/command/base.rb', line 201 def collect_app_source app_name app_source = 'Binary' proceed = ask( Paint["Would you like to deploy from the current directory?", :cyan], :default => true ) if proceed source_url = Dir.getwd app_file_name = is_binary_exist? source_url, app_name end unless proceed source_url = get_source_path app_source if source_url.include?('.zip') || source_url.include?('.war') || source_url.include?('.tar.gz') || source_url.include?('.gzip') return app_source, source_url end app_file_name = is_binary_exist? source_url, app_name end return app_source, app_file_name end |
#create_cloud_setup(setup_name, iaas, vm_type, setup_type, flavour) ⇒ Object
setup cloud API
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/app42/command/base.rb', line 344 def create_cloud_setup setup_name, iaas, vm_type, setup_type, flavour begin body = {'app42' => {"request"=> { "setupName" => setup_name, "iaas" => iaas, "vmType" => vm_type, "setupType" => setup_type, "flavour" => flavour }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Setting up the BPaaS infrastructure", :yellow]) do |s| build_post_request body, query_params, 'setup', nil end if response["success"] == true && response["transactionId"] transaction_success = check_transaction_status_of_setup response["transactionId"], previous_completed = 0, 'created' end if transaction_success transaction_params = params transaction_params.store('setupName', setup_name) host_response = build_get_request transaction_params, "setup", "#{setup_name}" end if host_response['success'] puts Paint["#{Message::BPAAS_SUCCESSFUL}", :green] return true else puts Paint["#{response['description']}", :red] end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#create_gpaas_setup(setup_name, iaas, vm_type, setup_type, flavour) ⇒ Object
setup GPaaS
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
# File 'lib/app42/command/base.rb', line 384 def create_gpaas_setup setup_name, iaas, vm_type, setup_type, flavour begin body = {'app42' => {"request"=> { "setupName" => setup_name, "iaas" => iaas, "vmType" => vm_type, "setupType" => 'setupGPaaS', "flavour" => flavour }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Setting up the GPaaS infrastructure", :yellow]) do |s| build_post_request body, query_params, "gpaas", nil end if response["success"] == true && response["transactionId"] transaction_success = check_transaction_status_of_setup response["transactionId"], previous_completed = 0, 'created' end if transaction_success transaction_params = params transaction_params.store('setupName', setup_name) host_response = build_get_request transaction_params, "gpaas", "#{setup_name}" end if host_response['success'] puts Paint["#{Message::GPAAS_SUCCESSFUL}", :green] return true else puts Paint["#{response['description']}", :red] end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#create_infrastructure(app_name, iaas, vm_type, runtime, framework, webserver, os, kontena) ⇒ Object
infrastructure setup call
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/app42/command/base.rb', line 301 def create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os, kontena begin body = {'app42' => {"request"=> { "appName" => app_name, "iaas" => iaas, "vmType" => vm_type, "runtime" => runtime, "framework" => framework, "webServer" => webserver, "os" => os, "kontenaPower" => kontena }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Setting up the infrastructure", :yellow]) do |s| build_post_request body, query_params, 'app', nil end if response["success"] == true && response["transactionId"] transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'created' end if transaction_success transaction_params = params transaction_params.store('appName', app_name) host_response = build_get_request transaction_params, "app", "#{app_name}" end if host_response['success'] puts Paint["Default application has been deployed. You can visit '#{host_response['appInfo']['appUrl']}' to see the default application.", :green] return true else puts Paint["#{response['description']}", :red] end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#create_service(service, service_name, database, vm_type, iaas, kontena, os) ⇒ Object
create service and get all relevant service information post service creation.
Parameters
service = type of service mysql,mongodb etc service_name = service name provided by user database = database name provided by user vm_type = shared OR dedicated iaas = zone where user want to create service vmconfig = virtual machine configuration details os = ubuntu OR Window
return
will display service details in tabular form and will exist console
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 |
# File 'lib/app42/command/base.rb', line 886 def create_service service, service_name ,database, vm_type, iaas, kontena, os body = {'app42' => {"request"=> { "service" => service, "serviceName" => service_name, "vmType" => vm_type, "database" => database, "iaas" => iaas, "kontenaPower" => kontena, "os" => os }}}.to_json query_params = params query_params.store('body', body) begin response = with_progress(Paint["Creating Service", :yellow]) do |s| build_post_request body, query_params, 'service', nil end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end if response["success"] == true && response["transactionId"] transaction_response = check_transaction_status response["transactionId"], previous_completed = 0, 'created' end if transaction_response service_info_params = params service_info_params.store('serviceName', service_name) service_details = build_get_request service_info_params, "service", "#{service_name}" end if service_details['success'] rows, rows_header_final, rows_header = [], [], nil rows_header = service_details['service'].keys rows << service_details['service'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{service_name} Details ===", :green], :headings => rows_header_final, :rows => rows puts table else puts Paint["#{response['description']}", :red] end end |
#create_service_tunnel(service_name, source_ip) ⇒ Object
Bind service to requested source IP and fetch service latest details
Parameters
service_name = service name provided by user source_ip = source IP to which service will get bind access_time = time duration user want to bind IP to service
return
display service bind details in tabular form OR ERROR message in case failed
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 |
# File 'lib/app42/command/base.rb', line 1267 def create_service_tunnel service_name, source_ip begin body = {'app42' => {"request"=> { "serviceName" => service_name, "sourceIp" => source_ip }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Binding IP to service", :yellow]) do |s| build_put_request body, query_params, 'service', "bind" end if response["success"] == true && response["transactionId"] transaction_response = check_transaction_status response["transactionId"], previous_completed = 0, 'created' end if transaction_response service_info_params = params service_info_params.store('serviceName', service_name) service_tunnel_details = build_get_request service_info_params, "service", "tunnel/#{service_name}" end if service_tunnel_details['success'] rows, rows_header_final, rows_header = [], [], nil rows_header = service_tunnel_details['service'].keys rows << service_tunnel_details['service'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{service_name} Details ===", :green], :headings => rows_header_final, :rows => rows puts table else puts Paint["#{response['description']}", :red] end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#create_wordpress_setup(wordpress_name, iaas, vm_type, flavour) ⇒ Object
setup wordpress
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/app42/command/base.rb', line 424 def create_wordpress_setup wordpress_name, iaas, vm_type, flavour begin body = {'app42' => {"request"=> { "setupName" => wordpress_name, "iaas" => iaas, "vmType" => vm_type, "setupType" => "setupWordPress", "flavour" => flavour }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Setting up the wordpress infrastructure", :yellow]) do |s| build_post_request body, query_params, 'wordpress', nil end if response["success"] == true && response["transactionId"] transaction_success = check_transaction_status_of_setup response["transactionId"], previous_completed = 0, 'created' end if transaction_success transaction_params = params transaction_params.store('setupName', wordpress_name) host_response = build_get_request transaction_params, "setup", "#{wordpress_name}" end if host_response['success'] puts Paint["#{Message::WORDPRESS_SUCCESSFUL}", :green] return true else puts Paint["#{response['description']}", :red] end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#custom_url_information(app_name) ⇒ Object
Get custom URL details
860 861 862 863 864 865 866 867 868 869 870 |
# File 'lib/app42/command/base.rb', line 860 def custom_url_information app_name query_params = params query_params.store('appName', app_name) begin response = build_get_request query_params, "app/customurl", nil rescue Exception => e puts e exit! end return response end |
#custom_url_operation(what, app_name, url) ⇒ Object
Custom operation will take placed like add, remove etc. expect what
as operation, app_name
as application name and url
custom url.
831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 |
# File 'lib/app42/command/base.rb', line 831 def custom_url_operation what, app_name, url begin if what.to_s == 'addcustomurl' response = with_progress(Paint[ "Adding Custom URL To Application #{app_name}", :yellow]) do |s| body = {'app42' => {"request"=> { "appName" => app_name, "url" => url }}}.to_json query_params = params query_params.store('body', body) build_post_request body, query_params, "app", "customurl" end else response = with_progress(Paint[ "Removing Custom URL", :yellow]) do |s| query_params = params query_params.store('appName', app_name) query_params.store('url', url) build_delete_request query_params, "app", "customurl" end end response['success'] ? (print Paint["#{response['message']}\n", :green]) : ( "#{response['message']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#delete_cloudapi(setup_name) ⇒ Object
delete setup cloud API, as a
Parameters
setup_name = setup_name provided by user
return
- true
-
if cloud setup deleted
OR ERROR message in case failed
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
# File 'lib/app42/command/base.rb', line 972 def delete_cloudapi setup_name begin response = with_progress(Paint["Deleting Setup", :yellow]) do |s| query_params = params query_params.store('setupName', setup_name) build_delete_request query_params, "setup", "#{setup_name}" end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#delete_gpaas(setup_name) ⇒ Object
delete GPaaS setup, as a
Parameters
setup_name = setup_name provided by user
return
- true
-
if gpaas setup deleted
OR ERROR message in case failed
1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 |
# File 'lib/app42/command/base.rb', line 1000 def delete_gpaas setup_name begin response = with_progress(Paint["Deleting Setup", :yellow]) do |s| query_params = params query_params.store('setupName', setup_name) build_delete_request query_params, "gpaas", "#{setup_name}" end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#delete_service(service_name) ⇒ Object
delete service, as a
Parameters
service_name = service name provided by user
return
- true
-
if service deleted
OR ERROR message in case failed
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 |
# File 'lib/app42/command/base.rb', line 944 def delete_service service_name begin response = with_progress(Paint["Deleting Service", :yellow]) do |s| query_params = params query_params.store('serviceName', service_name) build_delete_request query_params, "service", "#{service_name}" end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#delete_service_tunnel(service_name, source_ip) ⇒ Object
Unbind service to requested source IP
Parameters
service_name = service name provided by user source_ip = source IP to which service will get bind
return
display service bind details in tabular form OR ERROR message in case failed
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 |
# File 'lib/app42/command/base.rb', line 1323 def delete_service_tunnel service_name, source_ip begin body = {'app42' => {"request"=> { "serviceName" => service_name, "sourceIp" => source_ip }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Unbinding IP to service", :yellow]) do |s| build_put_request body, query_params, 'service', "unbind" end if response["success"] == true && response["transactionId"] transaction_response = check_transaction_status response["transactionId"], previous_completed = 0, 'created' return true end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#delete_wordpress(wordpress_name) ⇒ Object
delete wordpress setup, as a
Parameters
wordpress_name = wordpress_name provided by user
return
- true
-
if wordpress setup deleted
OR ERROR message in case failed
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 |
# File 'lib/app42/command/base.rb', line 1028 def delete_wordpress wordpress_name begin response = with_progress(Paint["Deleting WordPress Setup", :yellow]) do |s| query_params = params query_params.store('setupName', wordpress_name) build_delete_request query_params, "setup", "#{wordpress_name}" end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#get_app_name ⇒ Object
Ask application name from user and will wait for user response (user will enter application name)
91 92 93 94 95 |
# File 'lib/app42/command/base.rb', line 91 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 |
#get_app_name_and_check_app_url_availability ⇒ Object
collect application name from user if application name will not available User can try 3 more times with different application name
30 31 32 33 34 35 36 |
# File 'lib/app42/command/base.rb', line 30 def get_app_name_and_check_app_url_availability @aa_retry ||= 1 exit! if (@aa_retry += 1 ) >= 5 app_name = get_app_name available = app_url_availability app_name return available if available end |
#get_app_source(app_name, iaas, vm_type) ⇒ Object
collect remaining vm configuration details from user
85 86 87 |
# File 'lib/app42/command/base.rb', line 85 def get_app_source app_name, iaas, vm_type collect_vm_details app_name, iaas, vm_type end |
#get_custom_url ⇒ Object
Ask custom URL from user and validate
98 99 100 101 102 |
# File 'lib/app42/command/base.rb', line 98 def get_custom_url url = input "Enter Custom URL", [], true valid_url = validate_url url.strip valid_url ? (return valid_url) : get_custom_url end |
#get_framework(iaas, vm_type, rt) ⇒ Object
get supported frameworks
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/app42/command/base.rb', line 134 def get_framework iaas, vm_type, rt framework_hash = {} frameworks = App42::Command::Config.new.get_frameworks iaas, vm_type, rt frameworks['frameworks'].select {|each_fw| framework_hash["#{each_fw['id']}"] = each_fw['name'] + ' ' + each_fw['version']} framework = input "Select Framework", framework_hash.values, true framework_id = nil framework_hash.each_pair{|f| framework_id = f[0] if f[1] == framework} return framework_id end |
#get_iaas_providers ⇒ Object
Returns iaas providers.
72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/app42/command/base.rb', line 72 def get_iaas_providers iaas_provider_hash = {} iaas_providers = App42::Command::Config.new.get_iaas_provider iaas_providers['iaas'].select {|each_iaas| iaas_provider_hash["#{each_iaas['id']}"] = each_iaas['name'] + ' ' + each_iaas['zone']} iaas = input "Select IaaS Provider", iaas_provider_hash.values, true iaas_provider_id = nil iaas_provider_hash.each_pair{|ip| iaas_provider_id = ip[0] if ip[1] == iaas} return iaas_provider_id end |
#get_instance(obj) ⇒ Object
return no of instance
1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 |
# File 'lib/app42/command/base.rb', line 1352 def get_instance obj instance = @options[:instance] if @options[:instance] unless instance instance = nil instance = ask Paint[ obj == 'new_vm' ? "No of instances you want?" : "#{obj.capitalize} by instance(s)", :cyan], :default => 1 end instance_count = number_valid? instance if instance_count return instance_count else "#{Message::NOT_A_VALID_NUM}", true, 'red' get_instance obj end end |
#get_kontena(obj) ⇒ Object
return no of kontena power
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 |
# File 'lib/app42/command/base.rb', line 1373 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::NOT_A_VALID_NUM}", true, 'red' get_kontena obj end end |
#get_os_for_app(iaas, vm_type, rt, framework, webserver) ⇒ Object
get supported operating system for app
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/app42/command/base.rb', line 160 def get_os_for_app iaas, vm_type, rt, framework, webserver os_hash = {} = App42::Command::Config.new.( iaas, vm_type, rt, framework, webserver) if ['osDetail'].length > 1 ['osDetail'].select {|each_os| os_hash["#{each_os['id']}"] = each_os['name'] + ' ' + each_os['version']} os = input "Select Operating System", os_hash.values, true os_id = nil os_hash.each_pair{|o| os_id = o[0] if o[1] == os} return os_id else return ['osDetail'][0]['id'] end end |
#get_os_for_service(iaas, vm_type, service) ⇒ Object
get supported operating system for service
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/app42/command/base.rb', line 177 def get_os_for_service iaas, vm_type, service os_hash = {} = App42::Command::Config.new.( iaas, vm_type, service) if ['osDetail'].length > 1 ['osDetail'].select {|each_os| os_hash["#{each_os['id']}"] = each_os['name'] + ' ' + each_os['version']} os = input "Select Operating System", os_hash.values, true os_id = nil os_hash.each_pair{|o| os_id = o[0] if o[1] == os} return os_id else return ['osDetail'][0]['id'] end end |
#get_runtime ⇒ Object
get supported runtime by app42paas
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/app42/command/base.rb', line 121 def get_runtime runtime_hash = {} runtimes = App42::Command::Config.new.get_runtimes runtimes['runtimes'].select {|each_rt| runtime_hash["#{each_rt['id']}"] = each_rt['name'] + ' ' + each_rt['version']} rt = input "Select Runtime", runtime_hash.values, true rt_id = nil runtime_hash.each_pair{|r| rt_id = r[0] if r[1] == rt} return rt_id end |
#get_setup_name(prompt = ) ⇒ Object
Ask setup name from user and will wait for user response (user will enter setup name)
114 115 116 117 118 |
# File 'lib/app42/command/base.rb', line 114 def get_setup_name(prompt = Paint['Enter Setup Name', :cyan]) setup_name = ask(prompt) {|q| q.each = true} valid_setup_name = validate_setup_name "Setup name", setup_name.strip valid_setup_name ? (return valid_setup_name) : get_setup_name end |
#get_setup_name_and_check_setup_url_availability ⇒ Object
collect setup name from user if setup name will not available User can try 3 more times with different setup name
41 42 43 44 45 46 47 |
# File 'lib/app42/command/base.rb', line 41 def get_setup_name_and_check_setup_url_availability @aa_retry ||= 1 exit! if (@aa_retry += 1 ) >= 5 setup_name = get_setup_name available = setup_url_availability setup_name return available if available end |
#get_subscription ⇒ Object
67 68 69 |
# File 'lib/app42/command/base.rb', line 67 def get_subscription subscription = App42::Command::Config.new.subscription end |
#get_vm_types ⇒ Object
get supported virtual machine type by app42paas
61 62 63 64 65 |
# File 'lib/app42/command/base.rb', line 61 def get_vm_types vm_type = App42::Command::Config.new.get_vm_type vm_type_array = vm_type['deploymentType'].map(&:capitalize) input "Select Instance Type", vm_type_array, true end |
#get_vmconfig ⇒ Object
get supported vm configuration by app42paas
194 195 196 197 198 |
# File 'lib/app42/command/base.rb', line 194 def get_vmconfig kontena = input "Specify Kontena Power", [], true valid = validate_vm_config kontena valid ? (return valid) : get_vmconfig end |
#get_webserver(iaas, vm_type, rt, framework) ⇒ Object
get supported webserver
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/app42/command/base.rb', line 147 def get_webserver iaas, vm_type, rt, framework webserver_hash = {} webservers = App42::Command::Config.new.get_webservers( iaas, vm_type, rt, framework) webservers['webServer'].select {|each_ws| webserver_hash["#{each_ws['id']}"] = each_ws['name'] + ' ' + each_ws['version']} webserver = input "Select Web Server", webserver_hash.values, true webserver_id = nil webserver_hash.each_pair{|ws| webserver_id = ws[0] if ws[1] == webserver} return webserver_id end |
#get_wordpress_name ⇒ Object
Ask wordpress name from user and will wait for user response (user will enter wordpress name)
106 107 108 109 110 |
# File 'lib/app42/command/base.rb', line 106 def get_wordpress_name wordpress_name = input "Enter Wordpress Name", [], true valid_wordpress_name = validate_app_and_service_name "Wordpress name", wordpress_name.strip valid_wordpress_name ? (return valid_wordpress_name) : get_wordpress_name end |
#get_wordpress_name_and_check_wordpress_url_availability ⇒ Object
collect wordpress name from user if wordpress name will not available User can try 3 more times with different wordpress name
52 53 54 55 56 57 58 |
# File 'lib/app42/command/base.rb', line 52 def get_wordpress_name_and_check_wordpress_url_availability @aa_retry ||= 1 exit! if (@aa_retry += 1 ) >= 5 wordpress_name = get_wordpress_name available = wordpress_url_availability wordpress_name return available if available end |
#gpaas_operation(what, setup_name) ⇒ Object
All GPaaS operation will take placed like start, stop etc. expect what
as operation and setup_name
as BPaaS name.
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 |
# File 'lib/app42/command/base.rb', line 1090 def gpaas_operation what, setup_name begin if what.to_s == 'stop' response = with_progress(Paint[ "Stopping GPaaS 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, "gpaas", "#{what}" if what.to_s == 'stop' end else response = with_progress(Paint["#{what.capitalize}ing GPaaS 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, "gpaas", "#{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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#interactive_get(resource, get_obj) ⇒ Object
common methods for app42paas config request like runtimes,frameworks etc
771 772 773 774 775 776 777 778 |
# File 'lib/app42/command/base.rb', line 771 def interactive_get resource, get_obj begin response = build_get_request params, resource, get_obj rescue Exception => e puts e end return response end |
#reset_password(service_name, service_token) ⇒ Object
reset service password and fetch service latest details
Parameters
service_name = service name provided by user service_token = service token
return
- true
-
if reset password successful
OR ERROR message in case failed
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 |
# File 'lib/app42/command/base.rb', line 1180 def reset_password service_name, service_token begin body = {'app42' => {"request"=> { "serviceName" => service_name, "token" => service_token }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Resetting Password", :yellow]) do |s| build_put_request body, query_params, 'service', "password" end if response["success"] == true && response["transactionId"] transaction_response = check_transaction_status response["transactionId"], previous_completed = 0, 'created' end if transaction_response service_info_params = params service_info_params.store('serviceName', service_name) service_details = build_get_request service_info_params, "service", "#{service_name}" end service_details['success'] ? (return service_details) : ( "#{response['description']}", true , 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#scale_or_descale_app(what, instance, app_name) ⇒ Object
Scale or descale application by no of instance, expect what
as operation and instance as no of instance
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 |
# File 'lib/app42/command/base.rb', line 692 def scale_or_descale_app what, instance, app_name begin body = {'app42' => {"request"=> { 'appName' => app_name, "instanceCount" => instance.to_s }}}.to_json query_params = params query_params.store('body', body) response = with_progress( Paint[ what.to_s == 'scale' ? "Scaling Application #{app_name} by instance #{instance}" : "Descaling Application #{app_name} by instance #{instance}", :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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e exit! end end |
#service_name_availability(service_name) ⇒ Object
check service availabilities
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/app42/command/base.rb', line 283 def service_name_availability service_name query_params = params query_params.store('serviceName', service_name) response = with_progress(Paint["Checking Service Name Availability", :yellow]) do |s| build_get_request query_params, 'service', 'availability' end if response["success"] print_new_line return service_name else "#{response['description']}", true, 'red' return nil end end |
#service_operation(what, service_name) ⇒ Object
All application operation will take placed like app start, stop etc. expect what
as operation and service_name
as Service name.
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 |
# File 'lib/app42/command/base.rb', line 1217 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"=> { "serviceName" => service_name }}}.to_json query_params = params query_params.store('body', body) build_put_request body, query_params, "service", "#{what}" if what.to_s == 'stop' end else response = with_progress(Paint["#{what.capitalize}ing Service #{service_name}", :yellow]) do |s| body = {'app42' => {"request"=> { "serviceName" => service_name }}}.to_json query_params = params query_params.store('body', body) build_put_request body, query_params, "service", "#{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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#setup_url_availability(setup_name) ⇒ Object
check setup name availabilities
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/app42/command/base.rb', line 245 def setup_url_availability setup_name query_params = params query_params.store('setupName', setup_name) response = with_progress(Paint["Checking Setup Name Availability", :yellow]) do |s| build_get_request query_params, 'setup', 'availability' end if response["success"] print_new_line return setup_name else "#{response['description']}", true, 'red' get_setup_name_and_check_setup_url_availability end end |
#update_binary(app_name) ⇒ Object
Binary update call
608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 |
# File 'lib/app42/command/base.rb', line 608 def update_binary app_name @code_flag ||= 1 begin body = {'app42' => {"request"=> { "appName" => app_name }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Updating Application", :yellow]) do |s| build_put_request body, query_params, 'app/update', 'source' end if response["success"] == true && response["transactionId"] check_transaction_status response["transactionId"], previous_completed = 0, 'Uploaded' end if response['success'] exit! else puts Paint["#{response['description']}", :red] exit 1 if ( @code_flag += 1 ) > 3 get_binary_url app_name end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end return response end |
#upgrade_or_downgrade_cloudapi(action, setup_name, flavour) ⇒ Object
upgrade setup cloud API, as a
Parameters
setup_name = setup_name provided by user flavour = flavour provided by user
return
- true
-
if cloud setup upgraded
OR ERROR message in case failed
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 |
# File 'lib/app42/command/base.rb', line 473 def upgrade_or_downgrade_cloudapi action, setup_name, flavour begin response = with_progress(Paint[ action.to_s == "upgrade" ? "Upgrading Setup" : "Downgrading Setup", :yellow]) do |s| query_params = params body = {'app42' => {"request"=> { "setupName" => setup_name, "flavour" => flavour }}}.to_json query_params.store('body', body) build_put_request body, query_params, 'setup/upgrade', nil end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#upgrade_or_downgrade_gpaas(action, setup_name, flavour) ⇒ Object
upgrade GPaaS setup, as a
Parameters
setup_name = setup_name provided by user flavour = flavour provided by user
return
- true
-
if GpaaS setup upgraded
OR ERROR message in case failed
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/app42/command/base.rb', line 505 def upgrade_or_downgrade_gpaas action, setup_name, flavour begin response = with_progress(Paint[ action.to_s == "upgrade" ? "Upgrading Setup" : "Downgrading Setup", :yellow]) do |s| query_params = params body = {'app42' => {"request"=> { "setupName" => setup_name, "flavour" => flavour }}}.to_json query_params.store('body', body) build_put_request body, query_params, 'gpaas/upgrade', nil end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#upgrade_or_downgrade_wordpress(action, wordpress_name, flavour) ⇒ Object
upgrade Wordpress, as a
Parameters
wordpress_name = wordpress_name provided by user flavour = flavour provided by user
return
- true
-
if cloud setup upgraded
OR ERROR message in case failed
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/app42/command/base.rb', line 537 def upgrade_or_downgrade_wordpress action, wordpress_name, flavour begin response = with_progress(Paint[ action.to_s == "upgrade" ? "Upgrading Wordpress" : "Downgrading Wordpress", :yellow]) do |s| query_params = params body = {'app42' => {"request"=> { "setupName" => wordpress_name, "flavour" => flavour }}}.to_json query_params.store('body', body) build_put_request body, query_params, 'wordpress/upgrade', nil end transaction_success = check_transaction_status response["transactionId"], previous_completed = 0, 'deleted' if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end end |
#upload_binary(app_name, app_source, source_url) ⇒ Object
Binary upload call
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 |
# File 'lib/app42/command/base.rb', line 561 def upload_binary app_name, app_source, source_url @code_flag ||= 1 begin if source_url.include?('.war') || source_url.include?('.zip') || source_url.include?('.tar.gz') || source_url.include?('.gzip') query_params = params query_params.store('appName', app_name) "#{Message::WAIT_FOR_WHILE}", true, 'green' response = with_progress(Paint["Deploying Application", :yellow]) do |s| @connection.multipart(signature(query_params), resource_url("app/deploy", "binary"), query_params, query_params, source_url) end else body = {'app42' => {"request"=> { "appName" => app_name, "sourceType" => app_source, "sourceUrl" => source_url, }}}.to_json query_params = params query_params.store('body', body) response = with_progress(Paint["Deploying Application", :yellow]) do |s| build_put_request body, query_params, 'app/deploy', 'source' end end if response["success"] == true && response["transactionId"] check_transaction_status response["transactionId"], previous_completed = 0, 'Uploaded' end if response['success'] exit! else puts Paint["#{response['description']}", :red] exit 1 if ( @code_flag += 1 ) > 3 get_binary_url app_name end rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e end return response end |
#upload_service_backup(service_name, path, restore) ⇒ Object
upload service backup
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/app42/command/base.rb', line 644 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::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 "#{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 |
#vscale_or_vdescale_app(what, kontena, app_name) ⇒ Object
vertical scale or descale application by no of kontena, expect what
as operation and kontena as no of kontena
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 |
# File 'lib/app42/command/base.rb', line 720 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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e exit! end end |
#vscale_or_vdescale_service(what, kontena, service_name) ⇒ Object
vertical scale or descale service by no of kontena, expect what
as operation and kontena as no of kontena
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 |
# File 'lib/app42/command/base.rb', line 748 def vscale_or_vdescale_service what, kontena, service_name begin body = {'app42' => {"request"=> { 'serviceName' => service_name, "kontenaPower" => kontena.to_s }}}.to_json query_params = params query_params.store('body', body) response = with_progress( Paint[ what.to_s == 'vscale' ? "Scaling Service '#{service_name}' by kontena #{kontena}" : "Descaling Service '#{service_name}' by kontena #{kontena}", :yellow]) do |s| build_post_request body, query_params, "service", what end check_transaction_status response["transactionId"], previous_completed = 0, "#{what}d" if response["success"] == true && response["transactionId"] response['success'] ? (return true) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! rescue Exception => e puts e exit! end end |
#wordpress_operation(what, setup_name) ⇒ Object
All wordpress operation will take placed like app start, stop etc. expect what
as operation and wordpress_name
as wordpress name.
1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
# File 'lib/app42/command/base.rb', line 1131 def wordpress_operation what, setup_name begin if what.to_s == 'stop' response = with_progress(Paint[ "Stopping Wordpress 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 Wordpress 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) : ( "#{response['description']}", true, 'red') rescue Interrupt puts Paint[" Command cancelled.", :red] exit! end end |
#wordpress_url_availability(wordpress_name) ⇒ Object
check wordpress name availabilities
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/app42/command/base.rb', line 264 def wordpress_url_availability wordpress_name query_params = params query_params.store('setupName', wordpress_name) response = with_progress(Paint["Checking WordPress Name Availability", :yellow]) do |s| build_get_request query_params, 'wordpress', 'availability' end if response["success"] print_new_line return wordpress_name else "#{response['description']}", true, 'red' get_wordpress_name_and_check_wordpress_url_availability end end |