Class: HammerCLIForeman::ComputeAttribute::AddVolume

Inherits:
UpdateCommand show all
Defined in:
lib/hammer_cli_foreman/compute_attribute.rb

Overview

Using the Update command because adding a new volume is done by modifying existing compute_attribute

Instance Method Summary collapse

Methods inherited from UpdateCommand

#clean_up_context, command_name, create_option_builder, inherited, #method_options_for_params, #success_message

Methods inherited from HammerCLIForeman::Command

alias_name_for_resource, build_options, connection_name, create_option_builder, #customized_options, #dependency_resolver, dependency_resolver, #exception_handler_class, #get_identifier, #get_resource_id, #get_resource_ids, resolver, #resolver, resource_alias_name_mapping, resource_config, resource_name_mapping, #searchables, searchables, #send_request, #transform_format

Instance Method Details

#request_paramsObject

Raises:

  • (ArgumentError)


236
237
238
239
240
241
242
243
244
245
246
# File 'lib/hammer_cli_foreman/compute_attribute.rb', line 236

def request_params
  params = HammerCLIForeman::ComputeAttribute.get_params(options)
  raise ArgumentError, "Compute profile value to update does not exist yet; it needs to be created first" if !params['compute_attribute'].key?('id')
  volume_attr =  params['compute_attribute']['vm_attrs']['volumes_attributes'] || {}
  new_volume_id = (volume_attr.keys.max.to_i + 1 ).to_s if volume_attr.any?
  new_volume_id ||= "0"
  params['id'] = params['compute_attribute']['id']
  params['compute_attribute']['vm_attrs']['volumes_attributes'] ||= {}
  params['compute_attribute']['vm_attrs']['volumes_attributes'][new_volume_id] = option_volume
  params
end

#validate_optionsObject



230
231
232
233
234
# File 'lib/hammer_cli_foreman/compute_attribute.rb', line 230

def validate_options
  super
  validator.any(:option_compute_profile_id, :option_compute_profile_name).required
  validator.any(:option_compute_resource_id, :option_compute_resource_name).required
end