Method: Beaker::Subcommand#provision

Defined in:
lib/beaker/subcommand.rb

#provisionObject



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/beaker/subcommand.rb', line 105

def provision
  if options[:help]
    invoke :help, [], ["provision"]
    return
  end

  state = YAML::Store.new(SubcommandUtil::SUBCOMMAND_STATE)
  SubcommandUtil.error_with('Provisioned SUTs detected. Please destroy and reprovision.') if state.transaction { state['provisioned'] }

  @cli.parse_options
  @cli.provision

  # Sanitize the hosts
  cleaned_hosts = SubcommandUtil.sanitize_options_for_save(@cli.combined_instance_and_options_hosts)

  # Update each host provisioned with a flag indicating that it no longer needs
  # provisioning
  cleaned_hosts.each do |_host, host_hash|
    host_hash['provision'] = false
  end

  # should we only update the options here with the new host? Or update the settings
  # with whatever new flags may have been provided with provision?
  options_storage = YAML::Store.new(SubcommandUtil::SUBCOMMAND_OPTIONS)
  options_storage.transaction do
    @cli.logger.notify 'updating HOSTS key in subcommand_options'
    options_storage['HOSTS'] = cleaned_hosts
    options_storage['hosts_preserved_yaml_file'] = @cli.options[:hosts_preserved_yaml_file]
  end

  @cli.preserve_hosts_file

  state.transaction do
    state['provisioned'] = true
  end
end