Class: HammerCLIForeman::Command
- Inherits:
-
HammerCLI::Apipie::Command
- Object
- HammerCLI::Apipie::Command
- HammerCLIForeman::Command
show all
- Defined in:
- lib/hammer_cli_foreman/commands.rb
Direct Known Subclasses
Architecture, AssociatedCommand, Audit, AuthSource, AuthSourceExternal, AuthSourceLdap, Combination, CommonParameter, HammerCLIForeman::CommonParameter::SetCommand, ComputeAttribute, ComputeProfile, ComputeResource, ConfigGroup, ConfigReport, CreateCommand, Domain, ExternalUsergroup, Filter, Host, Hostgroup, HttpProxy, Image, Interface, ListCommand, Location, Medium, Model, OperatingSystem, OperatingSystem::DeleteOsDefaultTemplate, OperatingSystem::SetOsDefaultTemplate, Organization, Parameter::AbstractParameterCommand, PartitionTable, PersonalAccessToken, PingCommand, PingCommand::ForemanCommand, PuppetClass, PuppetEnvironment, Realm, ReportTemplate, ReportTemplate::ScheduleCommand, Role, SSHKeys, Settings, SingleResourceCommand, SmartClassParameter, SmartProxy, SmartProxy::ImportPuppetClassesCommand, SmartProxy::RefreshFeaturesCommand, SmartVariable, StatusCommand, StatusCommand::ForemanCommand, Subnet, Template, Template::BuildPXEDefaultCommand, User, Usergroup
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.alias_name_for_resource(resource, singular: true) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/hammer_cli_foreman/commands.rb', line 121
def self.alias_name_for_resource(resource, singular: true)
return nil if resource.nil?
return resource_alias_name_mapping[resource.name.to_sym] unless singular
resource_alias_name_mapping[resource.singular_name.to_sym]
end
|
.build_options(builder_params = {}) {|builder_params| ... } ⇒ Object
128
129
130
131
132
133
134
|
# File 'lib/hammer_cli_foreman/commands.rb', line 128
def self.build_options(builder_params={})
builder_params[:resource_mapping] ||= resource_name_mapping
builder_params = HammerCLIForeman::BuildParams.new(builder_params)
yield(builder_params) if block_given?
super(builder_params.to_hash, &nil)
end
|
.connection_name(resource_class) ⇒ Object
75
76
77
|
# File 'lib/hammer_cli_foreman/commands.rb', line 75
def self.connection_name(resource_class)
CONNECTION_NAME
end
|
.create_option_builder ⇒ Object
103
104
105
106
107
108
109
110
111
|
# File 'lib/hammer_cli_foreman/commands.rb', line 103
def self.create_option_builder
configurator = BuilderConfigurator.new(searchables, dependency_resolver)
builder = ForemanOptionBuilder.new(searchables)
builder.builders = []
builder.builders += configurator.builders_for(resource, resource.action(action)) if resource_defined?
builder.builders += super.builders
builder
end
|
.dependency_resolver ⇒ Object
.resource_alias_name_mapping ⇒ Object
.resource_config ⇒ Object
79
80
81
|
# File 'lib/hammer_cli_foreman/commands.rb', line 79
def self.resource_config
super.merge(HammerCLIForeman.resource_config)
end
|
.resource_name_mapping ⇒ Object
.searchables ⇒ Object
182
183
184
185
|
# File 'lib/hammer_cli_foreman/commands.rb', line 182
def self.searchables
@searchables ||= HammerCLIForeman::Searchables.new
@searchables
end
|
Instance Method Details
#customized_options ⇒ Object
195
196
197
198
199
|
# File 'lib/hammer_cli_foreman/commands.rb', line 195
def customized_options
options
end
|
#dependency_resolver ⇒ Object
87
88
89
|
# File 'lib/hammer_cli_foreman/commands.rb', line 87
def dependency_resolver
self.class.dependency_resolver
end
|
#exception_handler_class ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/hammer_cli_foreman/commands.rb', line 95
def exception_handler_class
HammerCLI.constant_path(self.class.name.to_s).reverse.each do |mod|
return mod.exception_handler_class if mod.respond_to? :exception_handler_class
end
HammerCLIForeman::ExceptionHandler
end
|
#get_identifier(all_opts = all_options) ⇒ Object
136
137
138
139
|
# File 'lib/hammer_cli_foreman/commands.rb', line 136
def get_identifier(all_opts=all_options)
@identifier ||= get_resource_id(resource, :all_options => all_opts)
@identifier
end
|
#get_resource_id(resource, options = {}) ⇒ Object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/hammer_cli_foreman/commands.rb', line 141
def get_resource_id(resource, options={})
resource_alias = self.class.alias_name_for_resource(resource)
all_opts = options[:all_options] || all_options
if options[:scoped]
opts = resolver.scoped_options(resource.singular_name, all_opts, :single)
else
opts = all_opts
end
begin
resolver.send("#{resource_alias || resource.singular_name}_id", opts)
rescue HammerCLIForeman::MissingSearchOptions => e
if (options[:required] == true || resource_search_requested(resource, opts))
logger.info "Error occured while searching for #{resource.singular_name}"
raise e
end
end
end
|
#get_resource_ids(resource, options = {}) ⇒ Object
159
160
161
162
163
164
165
166
167
168
169
170
171
|
# File 'lib/hammer_cli_foreman/commands.rb', line 159
def get_resource_ids(resource, options={})
resource_alias = self.class.alias_name_for_resource(resource)
all_opts = options[:all_options] || all_options
opts = resolver.scoped_options(resource.singular_name, all_opts, :multi)
begin
resolver.send("#{resource_alias || resource.singular_name}_ids", opts)
rescue HammerCLIForeman::MissingSearchOptions => e
if (options[:required] == true || resource_search_requested(resource, opts, true))
logger.info "Error occured while searching for #{resource.name}"
raise e
end
end
end
|
#request_params ⇒ Object
201
202
203
204
205
206
207
208
209
|
# File 'lib/hammer_cli_foreman/commands.rb', line 201
def request_params
params = customized_options
params_pruned = method_options(params)
id_option_name = HammerCLI.option_accessor_name('id')
params_pruned['id'] = params[id_option_name] if params[id_option_name]
params_pruned
end
|
#resolver ⇒ Object
83
84
85
|
# File 'lib/hammer_cli_foreman/commands.rb', line 83
def resolver
self.class.resolver
end
|
#searchables ⇒ Object
91
92
93
|
# File 'lib/hammer_cli_foreman/commands.rb', line 91
def searchables
self.class.searchables
end
|
#send_request ⇒ Object
187
188
189
|
# File 'lib/hammer_cli_foreman/commands.rb', line 187
def send_request
transform_format(super)
end
|