require 'app42/command/base' require 'terminal-table' module App42 module Command class Gpaas < Base # Collect all required attributes for new GPaaS spawn # required inputs are setup_name, vm_type, iaas, setup_type and flavour def setup setup_name = get_setup_name_and_check_setup_url_availability if App42::Command::Auth.is_authorize_for_dedicated? vm_type = 'dedicated' # GPaaS need only dedicated server iaas = get_iaas_providers setup_type = get_setup_type flavour = get_instance_config iaas, vm_type ans = ask Paint["#{Message::ADD_STATIC_IP}", :red], :default => true ; print_new_line setup_cloud_api_res = App42::Command::Base.new.create_gpaas_setup setup_name, iaas, vm_type, setup_type, flavour, ans exit! if setup_cloud_api_res end # Delete App42 GPaaS setup, return true or error code/message def delete @options[:setup] = get_setup_name if @options[:setup].nil? response = delete_gpaas @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect GPaaS setup name from user and proceed GPaaS start request def start @options[:setup] = get_setup_name if @options[:setup].nil? response = gpaas_operation __method__, @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect GPaaS setup name from user and proceed GPaaS stop request def stop ans = ask Paint["#{Message::URL_WILL_CHANGE}", :red], :default => true ; print_new_line ans == true ? (@options[:setup] = get_setup_name if @options[:setup].nil?) : (exit!) response = gpaas_operation __method__, @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect GPaaS setup name from user and proceed GPaaS restart request def restart # ans = ask Paint["#{Message::URL_WILL_CHANGE}", :red], :default => true ; print_new_line # ans == true ? (@options[:setup] = get_setup_name if @options[:setup].nil?) : (exit!) @options[:setup] = get_setup_name if @options[:setup].nil? response = gpaas_operation __method__, @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect GPaaS setup name from user and proceed GPaaS upgrade request def upgrade @options[:setup] = get_setup_name if @options[:setup].nil? print_new_line iaas, vm_type = get_iaas_and_vm_type @options[:setup] flavour = get_instance_config_for_upgrade_or_downgrade iaas, vm_type, @options[:setup], __method__.to_s if is_setup_name_exist? @options[:setup] response = upgrade_or_downgrade_gpaas __method__, @options[:setup], flavour exit! if response end # collect GPaaS setup name from user and proceed GPaaS downgrade request def downgrade @options[:setup] = get_setup_name if @options[:setup].nil? print_new_line iaas, vm_type = get_iaas_and_vm_type @options[:setup] flavour = get_instance_config_for_upgrade_or_downgrade iaas, vm_type, @options[:setup], __method__.to_s if is_setup_name_exist? @options[:setup] response = upgrade_or_downgrade_gpaas __method__, @options[:setup], flavour exit! if response end # Update GPaaS Dashboard def update @options[:setup] = get_setup_name if @options[:setup].nil? print_new_line response = update_gpaas_dashboard @options[:setup] if is_setup_name_exist? @options[:setup] end # return setup type def get_setup_type setup_type_hash = {} setup_type = App42::Command::Config.new.get_setup_type_fm_server setup_type['setupTypes'].select {|each_setup_type| setup_type_hash["#{each_setup_type['id']}"] = each_setup_type['name']} return setup_type_hash.keys.first end # return instance configuration def get_instance_config iaas, vm_type instance_config_hash = {} instance_config_type = App42::Command::Config.new.get_instance_config_type iaas, vm_type instance_config_type['IMList'].select {|each_instance_config| instance_config_hash["#{each_instance_config['id']}"] = each_instance_config['name']} instance_config = input "Select Instance Configuration", instance_config_hash.values, true instance_config_id = nil instance_config_hash.each_pair{|ic| instance_config_id = ic[0] if ic[1] == instance_config} return instance_config_id end # return setup details def get_iaas_and_vm_type setup_name setup_details = App42::Command::Config.new.get_setup_details setup_name return setup_details['iaas'], setup_details['containerType'] if setup_details['success'] end # get details information of App42 GPaaS setup def info @options[:setup] = get_setup_name if @options[:setup].nil? query_params = params query_params.store('setupName', @options[:setup]) setup_info = build_get_request query_params, 'gpaas', "#{@options[:setup]}" rows, rows_header_final, rows_header = [], [], nil if setup_info && setup_info['setupInfo'] rows_header = setup_info['setupInfo'].keys rows << setup_info['setupInfo'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{@options[:setup]} Details ===", :green], :headings => rows_header_final, :rows => rows puts table end end # List all setups def setups query_params = params setups = build_get_request query_params, 'gpaas', nil rows, rows_header_final, rows_header = [], [], nil if setups && setups['setups'] setups['setups'].each do |e| rows_header = e.keys rows << e.values end rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== Setups List ===", :green], :headings => rows_header_final, :rows => rows puts table end end end end end