Class: RefArchSetup::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/ref_arch_setup/cli.rb

Overview

Implements the command line subcommands

Author:

  • Randell Pelak

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, bolt_options) ⇒ void

Initialize class

Parameters:

  • options (Hash)

    The options from the command line

Options Hash (options):

  • something (String)

    not yet defined

Author:

  • Randell Pelak



17
18
19
20
# File 'lib/ref_arch_setup/cli.rb', line 17

def initialize(options, bolt_options)
  @options = options
  @bolt_options = bolt_options
end

Instance Attribute Details

#optionshash

Options from the command line

Returns:

  • (hash)

    the current value of options



8
9
10
# File 'lib/ref_arch_setup/cli.rb', line 8

def options
  @options
end

Instance Method Details

#check_for_missing_valuevoid

This method returns an undefined value.

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 –

Examples:

check_for_missing_value


Raises:

  • (OptionParser::MissingArgument)

    Thrown if an option is missing and argument

Author:

  • Randell Pelak



36
37
38
39
40
# 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

#check_option(option, subcommand) ⇒ void

This method returns an undefined value.

Checks for an option that is required by the sub command

Examples:

check_option(“target_host”, “install”)


Parameters:

  • option (string)

    the name of the option

  • subcommand (string)

    the name of the subcommand

Raises:

Author:

  • Randell Pelak



54
55
56
57
58
59
# 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

#installboolean

Installs a bootstrap version of mono on the target host using the provided tarball and pe.conf

Returns:

  • (boolean)

    success of install

Author:

  • Randell Pelak



87
88
89
90
91
92
93
94
95
96
# 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

#install_bootstrapboolean

Installs a bootstrap version of PE on the target host using the provided tarball and pe.conf

Returns:

  • (boolean)

    success of install

Author:

  • Randell Pelak



114
115
116
117
118
119
120
121
122
# 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

#install_configureboolean

Configures infrastructure nodes and do initial perf tuning

Returns:

  • (boolean)

    success of all the things

Author:

  • Randell Pelak



139
140
141
142
# File 'lib/ref_arch_setup/cli.rb', line 139

def install_configure
  puts "Running configure subcommand of install command"
  return true
end

#install_generate_pe_confboolean

Generates a pe.conf for use doing the install

Returns:

  • (boolean)

    success of generating the pe.conf file

Author:

  • Randell Pelak



103
104
105
106
107
# 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

#install_pe_infra_agent_installboolean

Installs an agent on infrastructure nodes

Returns:

  • (boolean)

    success of agent install

Author:

  • Randell Pelak



129
130
131
132
# 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

#run(command, subcommand = nil) ⇒ boolean

Wrapper around commands

Parameters:

  • command (string)

    the name of the command to run

  • subcommand (string) (defaults to: nil)

    the name of the subcommand to run

Returns:

  • (boolean)

    success of install

Author:

  • Randell Pelak



69
70
71
72
73
74
75
76
77
78
79
80
# 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