lib/app42/command/base.rb in app42-0.6.4 vs lib/app42/command/base.rb in app42-0.7.0
- old
+ new
@@ -56,24 +56,24 @@
available = wordpress_url_availability wordpress_name
return available if available
end
# get supported virtual machine type by app42paas
- def get_vm_types
- vm_type = App42::Command::Config.new.get_vm_type
+ def get_vm_types resource_type
+ vm_type = App42::Command::Config.new.get_vm_type resource_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
+ def get_iaas_providers vm_type
iaas_provider_hash = {}
- iaas_providers = App42::Command::Config.new.get_iaas_provider
+ iaas_providers = App42::Command::Config.new.get_iaas_provider vm_type
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
@@ -116,14 +116,15 @@
valid_setup_name = validate_setup_name "Setup name", setup_name.strip
valid_setup_name ? (return valid_setup_name) : get_setup_name
end
# get supported runtime by app42paas
- def get_runtime
- runtime_hash = {}
- runtimes = App42::Command::Config.new.get_runtimes
-
+ def get_runtime iaas, vm_type
+ runtime_hash, runtimes = {}, nil
+ runtimes = App42::Command::Config.new.get_runtimes_for_dedicated iaas, vm_type if vm_type == "Dedicated"
+ runtimes = App42::Command::Config.new.get_runtimes_for_shared if vm_type == "Shared"
+
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}
@@ -298,20 +299,33 @@
end
# infrastructure setup call
def create_infrastructure app_name, iaas, vm_type, runtime, framework, webserver, os, kontena
begin
- body = {'app42' => {"request"=> {
+ if vm_type == "Shared"
+ body = {'app42' => {"request"=> {
"appName" => app_name,
"iaas" => iaas,
"vmType" => vm_type,
"runtime" => runtime,
"framework" => framework,
"webServer" => webserver,
"os" => os,
"kontenaPower" => kontena
}}}.to_json
+ else
+ body = {'app42' => {"request"=> {
+ "appName" => app_name,
+ "iaas" => iaas,
+ "vmType" => vm_type,
+ "runtime" => runtime,
+ "framework" => framework,
+ "webServer" => webserver,
+ "os" => os,
+ "memoryConfig" => kontena
+ }}}.to_json
+ end
query_params = params
query_params.store('body', body)
response = with_progress(Paint["Setting up the infrastructure", :yellow]) do |s|
@@ -688,16 +702,25 @@
return response
end
# Scale or descale application by no of instance,
# expect +what+ as operation and instance as no of instance
- def scale_or_descale_app what, instance, app_name
- begin
- body = {'app42' => {"request"=> {
- 'appName' => app_name,
- "instanceCount" => instance.to_s
- }}}.to_json
+ def scale_or_descale_app what, instance, app_name, action_type = nil
+ begin
+ if action_type == "vm"
+ body = {"app42" => {"request"=> {
+ "appName" => app_name,
+ "memoryConfig" => instance.to_s,
+ "actionType" => action_type
+ }}}.to_json
+ else
+ body = {"app42" => {"request"=> {
+ "appName" => app_name,
+ "instanceCount" => instance.to_s,
+ "actionType" => action_type
+ }}}.to_json
+ end
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|
@@ -778,16 +801,17 @@
return response
end
# All application operation will take placed like app start, stop etc.
# expect +what+ as operation and +app_name+ as application name.
- def app_operation what, app_name
+ def app_operation what, app_name, action_type = nil
begin
if what.to_s == 'stop'
response = with_progress(Paint[ "Stopping Application #{app_name}", :yellow]) do |s|
body = {'app42' => {"request"=> {
- "appName" => app_name
+ "appName" => app_name,
+ "actionType" => action_type
}}}.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'
@@ -798,11 +822,12 @@
query_params = params
query_params.store('appName', app_name)
build_delete_request query_params, "app", "#{app_name}"
else
body = {'app42' => {"request"=> {
- "appName" => app_name
+ "appName" => app_name,
+ "actionType" => action_type
}}}.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'
@@ -1453,6 +1478,6 @@
get_kontena obj
end
end
end
end
-end
\ No newline at end of file
+end