Class: Vcloud::Launcher::Launch

Inherits:
Object
  • Object
show all
Defined in:
lib/vcloud/launcher/launch.rb

Defined Under Namespace

Classes: MissingConfigurationError, MissingPreambleError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file, cli_options = {}) ⇒ Launch

Returns a new instance of Launch.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vcloud/launcher/launch.rb', line 10

def initialize(config_file, cli_options = {})
  config_loader = ::Vcloud::Core::ConfigLoader.new
  @cli_options = cli_options

  set_logging_level
  @config = config_loader.load_config(config_file, Vcloud::Launcher::Schema::LAUNCHER_VAPPS)

  ignore_unspecified_machines

  validate_config
end

Instance Attribute Details

#cli_optionsObject (readonly)

Returns the value of attribute cli_options.



8
9
10
# File 'lib/vcloud/launcher/launch.rb', line 8

def cli_options
  @cli_options
end

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/vcloud/launcher/launch.rb', line 8

def config
  @config
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/vcloud/launcher/launch.rb', line 22

def run
  @config[:vapps].each do |vapp_config|
    Vcloud::Core.logger.info("Provisioning vApp #{vapp_config[:name]}.")
    begin
      if cli_options["dry-run"]
        # rubocop:disable Style/UselessAssignment
        vapp = ::Vcloud::Launcher::VappOrchestrator.provision(vapp_config, true)
        # rubocop:enable Style/UselessAssignment
      else
        vapp = ::Vcloud::Launcher::VappOrchestrator.provision(vapp_config)
        vapp.power_on unless cli_options["dont-power-on"]
        if cli_options["post-launch-cmd"]
          run_command(vapp_config, cli_options["post-launch-cmd"])
        end
      end
    Vcloud::Core.logger.info("Provisioned vApp #{vapp_config[:name]} successfully.")
    rescue RuntimeError => e
      Vcloud::Core.logger.error("Failure: Could not provision vApp: #{e.message}")
      break unless cli_options["continue-on-error"]
    end
  end
end