Class: Vanagon::CLI::Inspect

Inherits:
Vanagon::CLI show all
Defined in:
lib/vanagon/cli/inspect.rb

Constant Summary collapse

DOCUMENTATION =
<<~DOCOPT.freeze
  Usage:
  inspect [options] <project-name> <platforms>

  Options:
    -h, --help                       Display help
    -c, --configdir DIRECTORY        Configuration directory [default: #{Dir.pwd}/configs]
    -e, --engine ENGINE              Custom engine to use [default: always_be_scheduling]

    -p, --preserve [RULE]            Rule for VM preservation: never, on-failure, always
                                       [Default: on-failure]
    -w, --workdir DIRECTORY          Working directory on the local host
    -v, --verbose                    Only here for backwards compatibility. Does nothing.

  Engines:
    always_be_scheduling: default engine using Puppet's ABS infrastructure
    docker: a docker container on the local host
    ec2: an Amazon EC2 instance
    hardware: a dedicated hardware device
    local: the local machine, cannot be used with a target
    pooler: [deprecated] Puppet's vmpooler
DOCOPT

Instance Method Summary collapse

Instance Method Details

#options_translate(docopt_options) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/vanagon/cli/inspect.rb', line 49

def options_translate(docopt_options)
  translations = {
    '--verbose' => :verbose,
    '--workdir' => :workdir,
    '--configdir' => :configdir,
    '--engine' => :engine,
    '--preserve' => :preserve,
    '<project-name>' => :project_name,
    '<platforms>' => :platforms
  }
  return docopt_options.map { |k, v| [translations[k], v] }.to_h
end

#options_validate(options) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/vanagon/cli/inspect.rb', line 62

def options_validate(options)
  # Handle --preserve option checking
  valid_preserves = %w[always never on-failure]
  unless valid_preserves.include? options[:preserve]
    raise InvalidArgument, "--preserve option can only be one of: " +
                           valid_preserves.join(', ')
  end
  options[:preserve] = options[:preserve].to_sym
  return options
end

#parse(argv) ⇒ Object



31
32
33
34
35
36
# File 'lib/vanagon/cli/inspect.rb', line 31

def parse(argv)
  Docopt.docopt(DOCUMENTATION, { argv: argv })
rescue Docopt::Exit => e
  VanagonLogger.error e.message
  exit 1
end

#run(options) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/vanagon/cli/inspect.rb', line 38

def run(options)
  platforms = options[:platforms].split(',')
  project = options[:project_name]

  platforms.each do |platform|
    driver = Vanagon::Driver.new(platform, project, options)
    components = driver.project.components.map(&:to_hash)
    VanagonLogger.warn JSON.pretty_generate(components)
  end
end