Module: HammerCLIForeman
- Defined in:
- lib/hammer_cli_foreman.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/role.rb,
lib/hammer_cli_foreman/user.rb,
lib/hammer_cli_foreman/image.rb,
lib/hammer_cli_foreman/media.rb,
lib/hammer_cli_foreman/model.rb,
lib/hammer_cli_foreman/domain.rb,
lib/hammer_cli_foreman/filter.rb,
lib/hammer_cli_foreman/report.rb,
lib/hammer_cli_foreman/subnet.rb,
lib/hammer_cli_foreman/version.rb,
lib/hammer_cli_foreman/commands.rb,
lib/hammer_cli_foreman/location.rb,
lib/hammer_cli_foreman/settings.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/references.rb,
lib/hammer_cli_foreman/auth_source.rb,
lib/hammer_cli_foreman/credentials.rb,
lib/hammer_cli_foreman/environment.rb,
lib/hammer_cli_foreman/id_resolver.rb,
lib/hammer_cli_foreman/smart_proxy.rb,
lib/hammer_cli_foreman/architecture.rb,
lib/hammer_cli_foreman/organization.rb,
lib/hammer_cli_foreman/puppet_class.rb,
lib/hammer_cli_foreman/param_filters.rb,
lib/hammer_cli_foreman/smart_variable.rb,
lib/hammer_cli_foreman/option_builders.rb,
lib/hammer_cli_foreman/partition_table.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/exception_handler.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/smart_class_parameter.rb,
lib/hammer_cli_foreman/resource_supported_test.rb
Defined Under Namespace
Modules: AssociatingCommands, CommonHostUpdateOptions, DomainUpdateCreateCommons, HostgroupUpdateCreateCommons, I18n, Output, Parameter, References, ResourceSupportedTest
Classes: AbstractParamsFilter, AddAssociatedCommand, Architecture, AssociatedCommand, AssociatedResourceListCommand, Auth, AuthSource, AuthSourceLdap, BasicCredentials, BuildParams, BuilderConfigurator, Command, CommonParameter, ComputeResource, CreateCommand, DeleteCommand, DependencyResolver, DependentSearchablesArrayOptionBuilder, DependentSearchablesOptionBuilder, Domain, Environment, ExceptionHandler, ExternalUsergroup, Fact, Filter, ForemanOptionBuilder, Host, Hostgroup, IdArrayParamsFilter, IdOptionBuilder, IdParamsFilter, IdResolver, Image, InfoCommand, Interface, ListCommand, Location, Medium, MissingSeachOptions, Model, OperatingSystem, OperationNotSupportedError, Organization, ParamsFlattener, ParamsNameFilter, PartitionTable, PuppetClass, RemoveAssociatedCommand, Report, ResolverError, Role, Searchable, Searchables, SearchablesAbstractOptionBuilder, SearchablesOptionBuilder, SearchablesUpdateOptionBuilder, Settings, SingleResourceCommand, SmartClassParameter, SmartClassParametersBriefList, SmartClassParametersList, SmartProxy, SmartVariable, SmartVariablesBriefList, SmartVariablesList, Subnet, Template, UpdateCommand, User, Usergroup
Constant Summary
collapse
- CONNECTION_NAME =
'foreman'
- RESOURCE_NAME_MAPPING =
{
:usergroup => :user_group,
:usergroups => :user_groups,
:ptable => :partition_table,
:ptables => :partition_tables,
:puppetclass => :puppet_class,
:puppetclasses => :puppet_classes
}
Class Method Summary
collapse
Class Method Details
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/hammer_cli_foreman/commands.rb', line 66
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
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
|
.credentials ⇒ Object
14
15
16
17
18
19
20
|
# File 'lib/hammer_cli_foreman/commands.rb', line 14
def self.credentials
@credentials ||= BasicCredentials.new(
:username => (HammerCLI::Settings.get(:_params, :username) || ENV['FOREMAN_USERNAME'] || HammerCLI::Settings.get(:foreman, :username)),
:password => (HammerCLI::Settings.get(:_params, :password) || ENV['FOREMAN_PASSWORD'] || HammerCLI::Settings.get(:foreman, :password))
)
@credentials
end
|
.exception_handler_class ⇒ Object
.foreman_api_connection ⇒ Object
37
38
39
40
41
42
43
|
# File 'lib/hammer_cli_foreman/commands.rb', line 37
def self.foreman_api_connection
HammerCLI::Connection.create(
CONNECTION_NAME,
HammerCLI::Apipie::Command.resource_config.merge(resource_config),
HammerCLI::Apipie::Command.connection_options
)
end
|
.foreman_resource(resource_name, options = {}) ⇒ Object
54
55
56
57
58
59
60
|
# File 'lib/hammer_cli_foreman/commands.rb', line 54
def self.foreman_resource(resource_name, options={})
begin
foreman_resource!(resource_name, options)
rescue NameError
nil
end
end
|
.foreman_resource!(resource_name, options = {}) ⇒ Object
45
46
47
48
49
50
51
52
|
# File 'lib/hammer_cli_foreman/commands.rb', line 45
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_connection.api.resource(resource_name)
end
|
.param_to_resource(param_name) ⇒ Object
62
63
64
|
# File 'lib/hammer_cli_foreman/commands.rb', line 62
def self.param_to_resource(param_name)
HammerCLIForeman.foreman_resource(param_name.gsub(/_id[s]?$/, ""), :singular => true)
end
|
88
89
90
|
# File 'lib/hammer_cli_foreman/commands.rb', line 88
def self.record_to_common_format(data)
data.class <= Hash && data.keys.length == 1 ? data[data.keys[0]] : data
end
|
.resource_config ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/hammer_cli_foreman/commands.rb', line 22
def self.resource_config
config = {}
config[:uri] = HammerCLI::Settings.get(:_params, :host) || HammerCLI::Settings.get(:foreman, :host)
config[:credentials] = credentials
config[:logger] = Logging.logger['API']
config[:api_version] = 2
config[:aggressive_cache_checking] = HammerCLI::Settings.get(:foreman, :refresh_cache) || false
config[:headers] = { "Accept-Language" => HammerCLI::I18n.locale }
config[:language] = HammerCLI::I18n.locale
config[:timeout] = HammerCLI::Settings.get(:foreman, :request_timeout)
config[:timeout] = -1 if (config[:timeout] && config[:timeout].to_i < 0)
config[:apidoc_authenticated] = false
config
end
|
.version ⇒ Object
2
3
4
|
# File 'lib/hammer_cli_foreman/version.rb', line 2
def self.version
@version ||= Gem::Version.new '0.4.0'
end
|