lib/app42/command/base.rb in app42-0.6.1 vs lib/app42/command/base.rb in app42-0.6.2
- old
+ new
@@ -61,10 +61,14 @@
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
+
+ def get_subscription
+ subscription = App42::Command::Config.new.subscription
+ end
# @return iaas providers
def get_iaas_providers
iaas_provider_hash = {}
iaas_providers = App42::Command::Config.new.get_iaas_provider
@@ -363,21 +367,61 @@
transaction_params.store('setupName', setup_name)
host_response = build_get_request transaction_params, "setup", "#{setup_name}"
end
if host_response['success']
- puts Paint["Your setup has been completed successfully, For details, Login to AppHQ console.", :green]
+ 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
+ # setup GPaaS
+ 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
+
# setup wordpress
def create_wordpress_setup wordpress_name, iaas, vm_type, flavour
begin
body = {'app42' => {"request"=> {
"setupName" => wordpress_name,
@@ -403,11 +447,11 @@
transaction_params.store('setupName', wordpress_name)
host_response = build_get_request transaction_params, "setup", "#{wordpress_name}"
end
if host_response['success']
- puts Paint["Your wordpress setup has been completed successfully, For details, Login to AppHQ console.", :green]
+ puts Paint["#{Message::WORDPRESS_SUCCESSFUL}", :green]
return true
else
puts Paint["#{response['description']}", :red]
end
rescue Interrupt
@@ -424,11 +468,11 @@
#
# ==== return
# true:: if cloud setup upgraded
# OR
# ERROR message in case failed
- def upgrade_or_downgrade_clouldapi action, setup_name, flavour
+ 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,
@@ -442,14 +486,46 @@
response['success'] ? (return true) : (message "#{response['description']}", true, 'red')
rescue Interrupt
puts Paint[" Command cancelled.", :red]
exit!
rescue Exception => e
- puts e
+ puts e
end
end
+ # 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
+ 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) : (message "#{response['description']}", true, 'red')
+ rescue Interrupt
+ puts Paint[" Command cancelled.", :red]
+ exit!
+ rescue Exception => e
+ puts e
+ end
+ end
+
# upgrade Wordpress, as a
#
# ==== Parameters
# wordpress_name = wordpress_name provided by user
# flavour = flavour provided by user
@@ -750,21 +826,21 @@
end
end
# Custom operation will take placed like add, remove etc.
# expect +what+ as operation, +app_name+ as application name and +url+ custom url.
- def costom_url_operation what, app_name, url
+ 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"
+ 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)
@@ -891,11 +967,11 @@
#
# ==== return
# true:: if cloud setup deleted
# OR
# ERROR message in case failed
- def delete_clouldapi setup_name
+ 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}"
@@ -910,10 +986,38 @@
rescue Exception => e
puts e
end
end
+ # 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
+ 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) : (message "#{response['description']}", true, 'red')
+ rescue Interrupt
+ puts Paint[" Command cancelled.", :red]
+ exit!
+ rescue Exception => e
+ puts e
+ end
+ end
+
# delete wordpress setup, as a
#
# ==== Parameters
# wordpress_name = wordpress_name provided by user
#
@@ -940,11 +1044,11 @@
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
+ 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
@@ -977,9 +1081,50 @@
response['success'] ? (return true) : (message "#{response['description']}", true, 'red')
rescue Interrupt
puts Paint[" Command cancelled.", :red]
exit!
end
+ end
+
+ # All GPaaS operation will take placed like start, stop etc.
+ # expect +what+ as operation and +setup_name+ as BPaaS name.
+ 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) : (message "#{response['description']}", true, 'red')
+ rescue Interrupt
+ puts Paint[" Command cancelled.", :red]
+ exit!
+ end
end
# All wordpress operation will take placed like app start, stop etc.
# expect +what+ as operation and +wordpress_name+ as wordpress name.
def wordpress_operation what, setup_name
\ No newline at end of file