class RefArchSetup::CLI
Implements the command line subcommands
@author Randell Pelak @attr [hash] options Options from the command line
Public Class Methods
Initialize class
@author Randell Pelak
@param [Hash] options The options from the command line @option options [String] something not yet defined
@return [void]
# File lib/ref_arch_setup/cli.rb, line 17 def initialize(options, bolt_options) @options = options @bolt_options = bolt_options end
Public Instance Methods
Check values of options to see if they are really an option
optparse will gobble up the next option if no value is given This checks option values for things that start with – and then assumes the user forgot to provide a value This is okay as long as we don't need to support values with –
@author Randell Pelak
@raise [OptionParser::MissingArgument] Thrown if an option is missing and argument
@example check_for_missing_value
@return [void]
# File lib/ref_arch_setup/cli.rb, line 36 def check_for_missing_value @options.each do |key, value| raise OptionParser::MissingArgument, key if value =~ /^--/ end end
Checks for an option that is required by the sub command
@author Randell Pelak
@param [string] option the name of the option @param [string] subcommand the name of the subcommand
@example check_option
(“target_host”, “install”)
@raise [OptionParser::MissingOption] Thrown if option is missing
@return [void]
# File lib/ref_arch_setup/cli.rb, line 54 def check_option(option, subcommand) return unless @options[option].nil? || @options[option].empty? option.tr!("_", "-") raise OptionParser::MissingOption, \ "option --#{option} is required for the #{subcommand} subcommand" end
Installs a bootstrap version of mono on the target host using the provided tarball and pe.conf
@author Randell Pelak
@return [boolean] success of install
# File lib/ref_arch_setup/cli.rb, line 87 def install puts "Running install command" success = true success = install_generate_pe_conf unless @options.key?("pe_conf") # TODO: Pass pe.conf object along so we don't have to read/validate it in each subcommand success = install_bootstrap if success success = install_pe_infra_agent_install if success success = install_configure if success return success end
Installs a bootstrap version of PE on the target host using the provided tarball and pe.conf
@author Randell Pelak
@return [boolean] success of install
# File lib/ref_arch_setup/cli.rb, line 114 def install_bootstrap puts "Running bootstrap subcommand of install command" # none of these will be required in the future... but are for now check_option("primary_master", "install") install_obj = RefArchSetup::Install.new(@options["primary_master"]) success = install_obj.bootstrap(@options["pe_conf"], @options["pe_tarball"], @options["pe_version"]) return success end
Configures infrastructure nodes and do initial perf tuning
@author Randell Pelak
@return [boolean] success of all the things
# File lib/ref_arch_setup/cli.rb, line 139 def install_configure puts "Running configure subcommand of install command" return true end
Generates a pe.conf for use doing the install
@author Randell Pelak
@return [boolean] success of generating the pe.conf file
# File lib/ref_arch_setup/cli.rb, line 103 def install_generate_pe_conf puts "Running generate-pe-conf subcommand of install command" # check_option("console_password", "install") # password hardcoded in base file for now return true end
Installs an agent on infrastructure nodes
@author Randell Pelak
@return [boolean] success of agent install
# File lib/ref_arch_setup/cli.rb, line 129 def install_pe_infra_agent_install puts "Running pe-infra-agent-install subcommand of install command" return true end
Wrapper around commands
@author Randell Pelak
@param [string] command the name of the command to run @param [string] subcommand the name of the subcommand to run
@return [boolean] success of install
# File lib/ref_arch_setup/cli.rb, line 69 def run(command, subcommand = nil) check_for_missing_value BoltHelper.bolt_options = @bolt_options comm = command unless subcommand.nil? str = subcommand.tr("-", "_") comm += "_" + str end success = send(comm) return success end