require 'app42/command/base' require 'terminal-table' module App42 module Command class Wordpress < Base # Collect all required attributes for new wordpress setup spawn # required inputs are wordpress_name, vm_type, iaas, setup_type and flavour def setup wordpress_name = get_wordpress_name_and_check_wordpress_url_availability vm_type = get_vm_types iaas = get_iaas_providers flavour = get_flavour setup_cloud_api_res = App42::Command::Base.new.create_wordpress_setup wordpress_name, iaas, vm_type, flavour exit! if setup_cloud_api_res end # Delete wordpress setup, return true or error code/message def delete @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? response = delete_wordpress @options[:wordpress] if is_setup_name_exist? @options[:wordpress] exit! if response end # collect wordpress setup name from user and proceed wordpress start request def start @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? response = wordpress_operation __method__, @options[:wordpress] if is_setup_name_exist? @options[:wordpress] exit! if response end # collect wordpress setup name from user and proceed wordpress stop request def stop @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? response = wordpress_operation __method__, @options[:wordpress] if is_setup_name_exist? @options[:wordpress] exit! if response end # collect wordpress setup name from user and proceed wordpress restart request def restart @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? response = wordpress_operation __method__, @options[:wordpress] if is_setup_name_exist? @options[:wordpress] exit! if response end # collect Wordpress setup name from user and proceed Wordpress upgrade request def upgrade @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? flavour = get_flavour_for_upgrade_or_downgrade @options[:wordpress], __method__.to_s if is_setup_name_exist? @options[:wordpress] response = upgrade_or_downgrade_wordpress __method__, @options[:wordpress], flavour exit! if response end # collect Wordpress setup name from user and proceed Wordpress downgrade request def downgrade @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? flavour = get_flavour_for_upgrade_or_downgrade @options[:wordpress], __method__.to_s if is_setup_name_exist? @options[:wordpress] response = upgrade_or_downgrade_wordpress __method__, @options[:wordpress], flavour exit! if response 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 Wordpress setup def info @options[:wordpress] = get_wordpress_name if @options[:wordpress].nil? query_params = params query_params.store('setupName', @options[:wordpress]) setup_info = build_get_request query_params, 'setup', "#{@options[:wordpress]}" 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[:wordpress]} Details ===", :green], :headings => rows_header_final, :rows => rows puts table end end # List all Wordpress setups def wordpresssetups query_params = params setups = build_get_request query_params, 'wordpress', 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["=== Wordpress Setups List ===", :green], :headings => rows_header_final, :rows => rows puts table end end end end end