require 'app42/command/base' require 'terminal-table' module App42 module Command class Setup < Base # Collect all required attributes for new App42 cloud setup spawn # required inputs are setup_name, vm_type, iaas, setup_type and flavour def setup_cloud_api setup_name = get_setup_name_and_check_setup_url_availability vm_type = get_vm_types iaas = get_iaas_providers setup_type = get_setup_type flavour = get_flavour setup_cloud_api_res = App42::Command::Base.new.create_cloud_setup setup_name, iaas, vm_type, setup_type, flavour exit! if setup_cloud_api_res end # Delete App42 cloud API setup, return true or error code/message def delete_cloud_api @options[:setup] = get_setup_name if @options[:setup].nil? response = delete_cloudapi @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect BPaaS setup name from user and proceed BPaaS start request def start @options[:setup] = get_setup_name if @options[:setup].nil? response = cloudapi_operation __method__, @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect BPaaS setup name from user and proceed BPaaS stop request def stop @options[:setup] = get_setup_name if @options[:setup].nil? response = cloudapi_operation __method__, @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect BPaaS setup name from user and proceed BPaaS restart request def restart @options[:setup] = get_setup_name if @options[:setup].nil? response = cloudapi_operation __method__, @options[:setup] if is_setup_name_exist? @options[:setup] exit! if response end # collect BPaaS setup name from user and proceed BPaaS upgrade request def upgrade @options[:setup] = get_setup_name if @options[:setup].nil? print_new_line flavour = get_flavour_for_upgrade_or_downgrade @options[:setup], __method__.to_s if is_setup_name_exist? @options[:setup] response = upgrade_or_downgrade_cloudapi __method__, @options[:setup], flavour exit! if response end # collect BPaaS setup name from user and proceed BPaaS downgrade request def downgrade @options[:setup] = get_setup_name if @options[:setup].nil? print_new_line flavour = get_flavour_for_upgrade_or_downgrade @options[:setup], __method__.to_s if is_setup_name_exist? @options[:setup] response = upgrade_or_downgrade_cloudapi __method__, @options[:setup], flavour exit! if response 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 flavour def get_flavour flavour_hash = {} flavour_type = App42::Command::Config.new.get_flavour_type_fm_server flavour_type['flavours'].select {|each_flavour| flavour_hash["#{each_flavour['id']}"] = each_flavour['name']} flavour = input "Select Flavour", flavour_hash.values, true flavour_id = nil flavour_hash.each_pair{|fl| flavour_id = fl[0] if fl[1] == flavour} return flavour_id end # get details information of App42 cloud 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, 'setup', "#{@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, 'setup', 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