module App42::Command class Service < Base # list all available service of requested user def get_services build_get_request params, 'info', 'services' end # ask service name to user def get_service service_hash = {} get_services['services'].select {|each_service| service_hash["#{each_service['id']}"] = each_service['name'] + ' ' + each_service['version']} service = input "Select Service", service_hash.values, true service_id = nil service_hash.each_pair{|s| service_id = s[0] if s[1] == service} return service_id end def get_user_services#:nodoc: build_get_request params, 'service', nil end def get_uploadbackup_path #:nodoc: path = ask(Paint["\nEnter Backup File Path", :cyan]) valid_path = validate_upload_backup_path path.strip valid_path ? (return valid_path) : get_uploadbackup_path end # ask service name to user def ask_service_name service_name = ask Paint["Enter Service Name", :cyan] valid_service_name = validate_app_and_service_name "Service name", service_name.strip valid_service_name ? (return valid_service_name) : ask_service_name end # ask old password to user def ask_service_token input "Enter Service Token", [], true end # ask source id to user which he want to bind to service def ask_source_ip what ip = input "#{Message::BIND_NOTE}", [], true if what.to_s == 'bind' ip = input "#{Message::UNBIND_NOTE}", [], true if what.to_s == 'unbind' ip_address = ip.strip if ip_address_valid? ip_address return ip_address else message "#{Message::IP_NOT_VALID}", true, 'red' ask_source_ip what end end # ask database name to user def ask_database_name database_name = input "Enter Database Name", [], true valid_database_name = validate_database_name "Database name", database_name valid_database_name ? (return valid_database_name) : ask_database_name end # ask users service name to user def ask_user_service_name service_list = [] get_user_services['services'].select {|service| service_list << service['name'] } input "Select Service", service_list, true end # ask service name to user def get_service_name service_name = ask_service_name service_name = service_name_availability service_name service_name ? (return service_name) : get_service_name end # collect all required data from user to create new service def create service_name = get_service_name service = get_service database = ask_database_name vm_type = get_vm_types iaas = get_iaas_providers os = get_os_for_service iaas, vm_type, service kontena = get_vmconfig create_service service, service_name , database, vm_type, iaas, kontena, os end # collect service name from user and proceed service delete request def delete @options[:service] = ask_service_name if @options[:service].nil? response = delete_service @options[:service] if is_service_exist? @options[:service] exit! if response end # collect service name from user and proceed service start request def start @options[:service] = ask_service_name if @options[:service].nil? response = service_operation __method__, @options[:service] if is_service_exist? @options[:service] exit! if response end # collect service name from user and proceed service restart request def restart @options[:service] = ask_service_name if @options[:service].nil? response = service_operation __method__, @options[:service] if is_service_exist? @options[:service] exit! if response end # collect service name from user and proceed service stop request def stop @options[:service] = ask_service_name if @options[:service].nil? response = service_operation __method__, @options[:service] if is_service_exist? @options[:service] exit! if response end # read +app name+ and number of +instance+ from user # then vertically descale app by no of instance def uploadbackup @options[:service] = ask_service_name if @options[:service].nil? path = get_uploadbackup_path if is_service_exist? @options[:service] restore = ask( Paint["\nDo you also want to restore uploaded backup?", :cyan], :default => true ) status = upload_service_backup @options[:service], path, restore return status end # collect service name from user and proceed service resetPassword request def reset_pass @options[:service] = ask_service_name if @options[:service].nil? service_token = ask_service_token if is_service_exist? @options[:service] res = reset_password @options[:service], service_token (puts message "Your new password is: #{res['service']['password']}", false, 'green') && exit! if res end # collect service name,source IP and access time from user and proceed service resetPassword request def service_bind @options[:service] = ask_service_name if @options[:service].nil? source_ip = ask_source_ip 'bind' if is_service_exist? @options[:service] create_service_tunnel @options[:service], source_ip end # collect service name and source IP from user and proceed service unbind request def service_unbind @options[:service] = ask_service_name if @options[:service].nil? source_ip = ask_source_ip 'unbind' if is_service_exist? @options[:service] res = delete_service_tunnel @options[:service], source_ip exit! if res end # list details of specific service def service_bindInfo @options[:service] = ask_user_service_name if @options[:service].nil? query_params = params query_params.store('serviceName', @options[:service]) service_info = build_get_request query_params, 'service', "tunnel/#{@options[:service]}" rows, rows_header_final, rows_header = [], [], nil if service_info && service_info['service'] rows_header = service_info['service'].keys rows << service_info['service'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{@options[:service]} Details ===", :green], :headings => rows_header_final, :rows => rows puts table end end # list all available service on app42pass def app42pass_services rows, rows_header_final, rows_header = [], [], nil services = get_services if services && services['services'] services['services'].each do |e| e.delete('id') rows_header = e.keys rows << e.values end #unless services.nil? rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== App42 PaaS Services ===", :green], :headings => rows_header_final, :rows => rows puts table end end # list all available service on app42pass def services rows, rows_header_final, rows_header = [], [], nil services = get_user_services if services && services['services'] services['services'].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["=== Service List ===", :green], :headings => rows_header_final, :rows => rows puts table end end # list details of specific service def info @options[:service] = ask_user_service_name if @options[:service].nil? query_params = params query_params.store('serviceName', @options[:service]) service_info = build_get_request query_params, 'service', "#{@options[:service]}" rows, rows_header_final, rows_header = [], [], nil if service_info && service_info['service'] rows_header = service_info['service'].keys rows << service_info['service'].values rows_header.map { |e| rows_header_final << camel_case_to_whitespace(e) } table = Terminal::Table.new :title => Paint["=== #{@options[:service]} Details ===", :green], :headings => rows_header_final, :rows => rows puts table end end end end