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, CommonParameter, HammerCLIForeman::CommonParameter::SetCommand, ComputeResource, CreateCommand, Domain, Environment, Filter, Host, Hostgroup, Image, ListCommand, Location, Medium, Model, OperatingSystem, OperatingSystem::DeleteOsDefaultTemplate, OperatingSystem::SetOsDefaultTemplate, Organization, Parameter::AbstractParameterCommand, PartitionTable, PuppetClass, Report, Role, SingleResourceCommand, SmartClassParameter, SmartProxy, SmartProxy::ImportPuppetClassesCommand, SmartProxy::RefreshFeaturesCommand, SmartVariable, Subnet, Template, User, Usergroup
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.build_options(builder_params = {}) {|builder_params| ... } ⇒ Object
123
124
125
126
127
128
129
|
# File 'lib/hammer_cli_foreman/commands.rb', line 123
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
89
90
91
|
# File 'lib/hammer_cli_foreman/commands.rb', line 89
def self.connection_name(resource_class)
CONNECTION_NAME
end
|
.create_option_builder ⇒ Object
109
110
111
112
113
114
115
116
117
|
# File 'lib/hammer_cli_foreman/commands.rb', line 109
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_config ⇒ Object
.resource_name_mapping ⇒ Object
.searchables ⇒ Object
158
159
160
161
|
# File 'lib/hammer_cli_foreman/commands.rb', line 158
def self.searchables
@searchables ||= HammerCLIForeman::Searchables.new
@searchables
end
|
Instance Method Details
#customized_options ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/hammer_cli_foreman/commands.rb', line 167
def customized_options
params = options
IdParamsFilter.new(:only_required => false).for_action(resource.action(action)).each do |api_param|
param_resource = HammerCLIForeman.param_to_resource(api_param.name)
if param_resource && respond_to?(HammerCLI.option_accessor_name("#{param_resource.singular_name}_id"))
resource_id = get_resource_id(param_resource, :scoped => true, :required => api_param.required?)
params[HammerCLI.option_accessor_name(api_param.name)] = resource_id if resource_id
end
end
id_option_name = HammerCLI.option_accessor_name('id')
params[id_option_name] ||= get_identifier if respond_to?(id_option_name)
params
end
|
#dependency_resolver ⇒ Object
101
102
103
|
# File 'lib/hammer_cli_foreman/commands.rb', line 101
def dependency_resolver
self.class.dependency_resolver
end
|
#get_identifier ⇒ Object
131
132
133
134
|
# File 'lib/hammer_cli_foreman/commands.rb', line 131
def get_identifier
@identifier ||= get_resource_id(resource)
@identifier
end
|
#get_resource_id(resource, options = {}) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/hammer_cli_foreman/commands.rb', line 136
def get_resource_id(resource, options={})
if options[:scoped]
opts = resolver.scoped_options(resource.singular_name, all_options)
else
opts = all_options
end
begin
resolver.send("#{resource.singular_name}_id", opts)
rescue HammerCLIForeman::MissingSeachOptions => e
raise e unless (options[:required] == false)
end
end
|
#request_params ⇒ Object
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/hammer_cli_foreman/commands.rb', line 184
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
97
98
99
|
# File 'lib/hammer_cli_foreman/commands.rb', line 97
def resolver
self.class.resolver
end
|
#searchables ⇒ Object
105
106
107
|
# File 'lib/hammer_cli_foreman/commands.rb', line 105
def searchables
self.class.searchables
end
|