Module: HammerCLIForeman

Defined in:
lib/hammer_cli_foreman.rb,
lib/hammer_cli_foreman/api.rb,
lib/hammer_cli_foreman/auth.rb,
lib/hammer_cli_foreman/fact.rb,
lib/hammer_cli_foreman/host.rb,
lib/hammer_cli_foreman/i18n.rb,
lib/hammer_cli_foreman/ping.rb,
lib/hammer_cli_foreman/role.rb,
lib/hammer_cli_foreman/user.rb,
lib/hammer_cli_foreman/audit.rb,
lib/hammer_cli_foreman/image.rb,
lib/hammer_cli_foreman/media.rb,
lib/hammer_cli_foreman/model.rb,
lib/hammer_cli_foreman/realm.rb,
lib/hammer_cli_foreman/domain.rb,
lib/hammer_cli_foreman/filter.rb,
lib/hammer_cli_foreman/logger.rb,
lib/hammer_cli_foreman/status.rb,
lib/hammer_cli_foreman/subnet.rb,
lib/hammer_cli_foreman/version.rb,
lib/hammer_cli_foreman/bookmark.rb,
lib/hammer_cli_foreman/commands.rb,
lib/hammer_cli_foreman/defaults.rb,
lib/hammer_cli_foreman/location.rb,
lib/hammer_cli_foreman/sessions.rb,
lib/hammer_cli_foreman/settings.rb,
lib/hammer_cli_foreman/ssh_keys.rb,
lib/hammer_cli_foreman/template.rb,
lib/hammer_cli_foreman/hostgroup.rb,
lib/hammer_cli_foreman/interface.rb,
lib/hammer_cli_foreman/parameter.rb,
lib/hammer_cli_foreman/usergroup.rb,
lib/hammer_cli_foreman/exceptions.rb,
lib/hammer_cli_foreman/http_proxy.rb,
lib/hammer_cli_foreman/references.rb,
lib/hammer_cli_foreman/auth_source.rb,
lib/hammer_cli_foreman/combination.rb,
lib/hammer_cli_foreman/id_resolver.rb,
lib/hammer_cli_foreman/smart_proxy.rb,
lib/hammer_cli_foreman/task_helper.rb,
lib/hammer_cli_foreman/architecture.rb,
lib/hammer_cli_foreman/organization.rb,
lib/hammer_cli_foreman/registration.rb,
lib/hammer_cli_foreman/api/void_auth.rb,
lib/hammer_cli_foreman/config_report.rb,
lib/hammer_cli_foreman/param_filters.rb,
lib/hammer_cli_foreman/api/basic_auth.rb,
lib/hammer_cli_foreman/api/connection.rb,
lib/hammer_cli_foreman/openid_connect.rb,
lib/hammer_cli_foreman/compute_profile.rb,
lib/hammer_cli_foreman/option_builders.rb,
lib/hammer_cli_foreman/partition_table.rb,
lib/hammer_cli_foreman/report_template.rb,
lib/hammer_cli_foreman/virtual_machine.rb,
lib/hammer_cli_foreman/auth_source_ldap.rb,
lib/hammer_cli_foreman/common_parameter.rb,
lib/hammer_cli_foreman/compute_resource.rb,
lib/hammer_cli_foreman/operating_system.rb,
lib/hammer_cli_foreman/table_preference.rb,
lib/hammer_cli_foreman/api/authenticator.rb,
lib/hammer_cli_foreman/compute_attribute.rb,
lib/hammer_cli_foreman/exception_handler.rb,
lib/hammer_cli_foreman/mail_notification.rb,
lib/hammer_cli_foreman/api/negotiate_auth.rb,
lib/hammer_cli_foreman/authenticate/login.rb,
lib/hammer_cli_foreman/external_usergroup.rb,
lib/hammer_cli_foreman/dependency_resolver.rb,
lib/hammer_cli_foreman/associating_commands.rb,
lib/hammer_cli_foreman/auth_source_external.rb,
lib/hammer_cli_foreman/compute_resource/ec2.rb,
lib/hammer_cli_foreman/compute_resource/base.rb,
lib/hammer_cli_foreman/personal_access_token.rb,
lib/hammer_cli_foreman/compute_resource/ovirt.rb,
lib/hammer_cli_foreman/compute_resource/utils.rb,
lib/hammer_cli_foreman/user_mail_notification.rb,
lib/hammer_cli_foreman/command_extensions/ping.rb,
lib/hammer_cli_foreman/command_extensions/user.rb,
lib/hammer_cli_foreman/compute_resource/vmware.rb,
lib/hammer_cli_foreman/resource_supported_test.rb,
lib/hammer_cli_foreman/api/oauth/password_grant.rb,
lib/hammer_cli_foreman/compute_resource/libvirt.rb,
lib/hammer_cli_foreman/option_sources/id_params.rb,
lib/hammer_cli_foreman/testing/api_expectations.rb,
lib/hammer_cli_foreman/command_extensions/domain.rb,
lib/hammer_cli_foreman/command_extensions/fields.rb,
lib/hammer_cli_foreman/command_extensions/status.rb,
lib/hammer_cli_foreman/command_extensions/subnet.rb,
lib/hammer_cli_foreman/option_sources/ids_params.rb,
lib/hammer_cli_foreman/option_sources/new_params.rb,
lib/hammer_cli_foreman/option_sources/self_param.rb,
lib/hammer_cli_foreman/api/interactive_basic_auth.rb,
lib/hammer_cli_foreman/compute_resource/openstack.rb,
lib/hammer_cli_foreman/option_sources/user_params.rb,
lib/hammer_cli_foreman/hosts/common_update_options.rb,
lib/hammer_cli_foreman/option_sources/fields_params.rb,
lib/hammer_cli_foreman/command_extensions/update_common.rb,
lib/hammer_cli_foreman/api/session_authenticator_wrapper.rb,
lib/hammer_cli_foreman/command_extensions/option_sources.rb,
lib/hammer_cli_foreman/api/interactive_basic_auth_external.rb,
lib/hammer_cli_foreman/api/oauth/authentication_code_grant.rb,
lib/hammer_cli_foreman/command_extensions/hosts/help/interfaces.rb,
lib/hammer_cli_foreman/compute_resource/register_compute_resources.rb,
lib/hammer_cli_foreman/option_sources/referenced_resource_id_params.rb,
lib/hammer_cli_foreman/command_extensions/compute_resource_subcommand.rb,
lib/hammer_cli_foreman/command_extensions/hosts/help/compute_resources.rb

Defined Under Namespace

Modules: Api, AssociatingCommands, Authenticate, CommandExtensions, ComputeResources, HostgroupUpdateCreateCommons, Hosts, I18n, OptionSources, Output, Parameter, References, ResourceSupportedTest, SubnetUpdateCreateCommons, TaskHelper, Testing Classes: AbstractParamsFilter, AddAssociatedCommand, Architecture, AssociatedCommand, AssociatedListSearchCommand, AssociatedResourceListCommand, Audit, Auth, AuthSource, AuthSourceExternal, AuthSourceLdap, Bookmark, BuildParams, BuilderConfigurator, Combination, Command, CommonParameter, ComputeAttribute, ComputeProfile, ComputeResource, ConfigReport, CreateCommand, Defaults, DeleteCommand, DependencyResolver, DependentSearchablesArrayOptionBuilder, DependentSearchablesOptionBuilder, Domain, DownloadCommand, ExceptionHandler, ExternalUsergroup, Fact, Filter, ForemanOptionBuilder, Host, Hostgroup, HttpProxy, IdArrayParamsFilter, IdOptionBuilder, IdParamsFilter, IdResolver, Image, InfoCommand, Interface, ListCommand, Location, MailNotification, Medium, MissingSearchOptions, Model, OpenidConnect, OperatingSystem, OperationNotSupportedError, Organization, ParamsFlattener, ParamsNameFilter, PartitionTable, PersonalAccessToken, PingCommand, Realm, Registration, RemoveAssociatedCommand, ReportTemplate, ResolverError, Role, SSHKeys, Searchable, Searchables, SearchablesAbstractOptionBuilder, SearchablesOptionBuilder, SearchablesUpdateOptionBuilder, Session, Sessions, Settings, SingleResourceCommand, SmartProxy, StatusCommand, Subnet, TablePreference, Template, UpdateCommand, UpdateDependentSearchablesOptionBuilder, User, UserMailNotification, Usergroup, VirtualMachine

Constant Summary collapse

RESOURCE_NAME_MAPPING =
{
  :usergroup => :user_group,
  :usergroups => :user_groups,
  :ptable => :partition_table,
  :ptables => :partition_tables,
}
RESOURCE_ALIAS_NAME_MAPPING =
{ }
CONNECTION_NAME =
'foreman'
AUTH_TYPES =
{
  basic_auth: 'Basic_Auth',
  basic_auth_external: 'Basic_Auth_External',
  negotiate: 'Negotiate_Auth',
  oauth_authentication_code_grant: 'Oauth_Authentication_Code_Grant',
  oauth_password_grant: 'Oauth_Password_Grant'
}.freeze

Class Method Summary collapse

Class Method Details

.collection_to_common_format(data) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/hammer_cli_foreman/commands.rb', line 39

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_resourcesObject



3
4
5
# File 'lib/hammer_cli_foreman/compute_resource/register_compute_resources.rb', line 3

def self.compute_resources
  @compute_resources
end

.exception_handler_classObject



7
8
9
# File 'lib/hammer_cli_foreman.rb', line 7

def self.exception_handler_class
  HammerCLIForeman::ExceptionHandler
end

.foreman_apiObject



14
15
16
# File 'lib/hammer_cli_foreman/commands.rb', line 14

def self.foreman_api
  foreman_api_connection
end

.foreman_api_connectionObject



79
80
81
82
83
# File 'lib/hammer_cli_foreman/api/connection.rb', line 79

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) ⇒ Object



85
86
87
88
89
90
91
92
93
94
# File 'lib/hammer_cli_foreman/api/connection.rb', line 85

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 = {}) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/hammer_cli_foreman/commands.rb', line 27

def self.foreman_resource(resource_name, options={})
  begin
    foreman_resource!(resource_name, options)
  rescue NameError
    nil
  end
end

.foreman_resource!(resource_name, options = {}) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/hammer_cli_foreman/commands.rb', line 18

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_connectionObject



96
97
98
# File 'lib/hammer_cli_foreman/api/connection.rb', line 96

def self.init_api_connection
  foreman_api_connection
end

.param_to_resource(param_name) ⇒ Object



35
36
37
# File 'lib/hammer_cli_foreman/commands.rb', line 35

def self.param_to_resource(param_name)
  HammerCLIForeman.foreman_resource(param_name.gsub(/_id[s]?$/, ""), :singular => true)
end

.record_to_common_format(data) ⇒ Object



61
62
63
# File 'lib/hammer_cli_foreman/commands.rb', line 61

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) ⇒ Object



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

.versionObject



2
3
4
# File 'lib/hammer_cli_foreman/version.rb', line 2

def self.version
  @version ||= Gem::Version.new "3.12.0"
end