Class: Vanagon::CLI::Inspect

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

Constant Summary collapse

DOCUMENTATION =
"Usage:\ninspect [options] <project-name> <platforms>\n\nOptions:\n  -h, --help                       Display help\n  -c, --configdir DIRECTORY        Configuration directory [default: \#{Dir.pwd}/configs]\n  -e, --engine ENGINE              Custom engine to use [default: always_be_scheduling]\n\n  -p, --preserve [RULE]            Rule for VM preservation: never, on-failure, always\n                                     [Default: on-failure]\n  -w, --workdir DIRECTORY          Working directory on the local host\n  -v, --verbose                    Only here for backwards compatibility. Does nothing.\n\nEngines:\n  always_be_scheduling: default engine using Puppet's ABS infrastructure\n  docker: a docker container on the local host\n  ec2: an Amazon EC2 instance\n  hardware: a dedicated hardware device\n  local: the local machine, cannot be used with a target\n  pooler: [deprecated] Puppet's vmpooler\n".freeze

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
# 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