Module: Kontena::Cli::Grids::Common::Parameters

Included in:
Kontena::Cli::Grids::CreateCommand, UpdateCommand
Defined in:
lib/kontena/cli/grids/common.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/kontena/cli/grids/common.rb', line 122

def self.included(base)
  base.option "--default-affinity", "[AFFINITY]", "Default affinity rule for the grid", multivalued: true
  base.option "--statsd-server", "STATSD_SERVER", "Statsd server address (host:port)"
  base.option "--log-forwarder", "LOG_FORWARDER", "Set grid wide log forwarder" do |log_forwarder|
    if log_forwarder == 'none'
      warn "[DEPRECATED] --log-forwarder none will be replaced with --no-log-forwarder"
    end
    log_forwarder
  end
  base.option "--no-log-forwarder", :flag, "Disable log forwarding"
  base.option "--log-opt", "[LOG_OPT]", "Set log options (key=value)", multivalued: true
end

Instance Method Details

#build_grid_parameters(payload) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/kontena/cli/grids/common.rb', line 158

def build_grid_parameters(payload)
  if statsd_server
    server, port = statsd_server.split(':')
    payload[:stats] = {
      statsd: {
        server: server,
        port: port || 8125
      }
    }
  end

  if log_forwarder || no_log_forwarder?
    payload[:logs] = {
      forwarder: no_log_forwarder? ? 'none' : log_forwarder,
      opts: parse_log_opts
    }
  end

  unless default_affinity_list.empty?
    payload[:default_affinity] = default_affinity_list
  end
end

#parse_log_optsObject



145
146
147
148
149
150
151
152
# File 'lib/kontena/cli/grids/common.rb', line 145

def parse_log_opts
  opts = {}
  log_opt_list.each do |opt|
    key, value = opt.split('=')
    opts[key.to_sym] = value
  end
  opts
end

#validate_grid_parametersObject



154
155
156
# File 'lib/kontena/cli/grids/common.rb', line 154

def validate_grid_parameters
  validate_log_opts
end

#validate_log_optsObject



135
136
137
138
139
140
141
142
143
# File 'lib/kontena/cli/grids/common.rb', line 135

def validate_log_opts
  if !log_opt_list.empty? && (log_forwarder.nil? || no_log_forwarder?)
    raise Kontena::Errors::StandardError.new(1, "Need to specify --log-forwarder when using --log-opt")
  end

  if no_log_forwarder? && !log_forwarder.nil? && log_forwarder != "none"
    exit_with_error "Can't use --log-forwarder and --no-log-forwarder together"
  end
end