module HammerCLIForeman

Constants

AUTH_TYPES
CONNECTION_NAME
RESOURCE_ALIAS_NAME_MAPPING
RESOURCE_NAME_MAPPING

Public Class Methods

collection_to_common_format(data) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 46
def self.collection_to_common_format(data)
  if data.class <= Hash && data.has_key?('total') && data.has_key?('results')
    col = HammerCLI::Output::RecordCollection.new(data['results'],
      :total => data['total'],
      :subtotal => data['subtotal'],
      :page => data['page'],
      :per_page => data['per_page'],
      :search => data['search'],
      :sort_by => data['sort']['by'],
      :sort_order => data['sort']['order'])
  elsif data.class <= Hash
    col = HammerCLI::Output::RecordCollection.new(data)
  elsif data.class <= Array
    # remove object types. From [ { 'type' => { 'attr' => val } }, ... ]
    # produce [ { 'attr' => 'val' }, ... ]
    col = HammerCLI::Output::RecordCollection.new(data.map { |r| r.keys.length == 1 ? r[r.keys[0]] : r })
  else
    raise RuntimeError.new(_("Received data of unknown format."))
  end
  col
end
compute_resources() click to toggle source
# File lib/hammer_cli_foreman/compute_resource/register_compute_resources.rb, line 3
def self.compute_resources
  @compute_resources
end
exception_handler_class() click to toggle source
# File lib/hammer_cli_foreman.rb, line 7
def self.exception_handler_class
  HammerCLIForeman::ExceptionHandler
end
foreman_api() click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 21
def self.foreman_api
  foreman_api_connection
end
foreman_api_connection() click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 76
def self.foreman_api_connection
  HammerCLI.context[:api_connection].create(CONNECTION_NAME) do
    HammerCLIForeman::Api::Connection.new(HammerCLI::Settings, Logging.logger['API'], HammerCLI::I18n.locale)
  end
end
foreman_api_reconnect(auth_type) click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 82
def self.foreman_api_reconnect(auth_type)
  HammerCLI.context[:api_connection].drop(CONNECTION_NAME)
  HammerCLI.context[:api_connection].create(CONNECTION_NAME) do
    HammerCLIForeman::Api::Connection.new(
      HammerCLI::Settings,
      Logging.logger['API'],
      HammerCLI::I18n.locale,
      auth_type)
  end
end
foreman_resource(resource_name, options={}) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 34
def self.foreman_resource(resource_name, options={})
  begin
    foreman_resource!(resource_name, options)
  rescue NameError
    nil
  end
end
foreman_resource!(resource_name, options={}) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 25
def self.foreman_resource!(resource_name, options={})
  if options[:singular]
    resource_name = ApipieBindings::Inflector.pluralize(resource_name.to_s).to_sym
  else
    resource_name = resource_name.to_sym
  end
  foreman_api.resource(resource_name)
end
init_api_connection() click to toggle source
# File lib/hammer_cli_foreman/api/connection.rb, line 93
def self.init_api_connection
  foreman_api_connection
end
param_to_resource(param_name) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 42
def self.param_to_resource(param_name)
  HammerCLIForeman.foreman_resource(param_name.gsub(/_id[s]?$/, ""), :singular => true)
end
record_to_common_format(data) click to toggle source
# File lib/hammer_cli_foreman/commands.rb, line 68
def self.record_to_common_format(data)
    data.class <= Hash && data.keys.length == 1 ? data[data.keys[0]] : data
end
register_compute_resource(name, compute_resource) click to toggle source
# File lib/hammer_cli_foreman/compute_resource/register_compute_resources.rb, line 7
def self.register_compute_resource(name, compute_resource)
  @compute_resources[name] = compute_resource
end
version() click to toggle source
# File lib/hammer_cli_foreman/version.rb, line 2
def self.version
  @version ||= Gem::Version.new "2.2.0"
end