Class: HammerCLIForeman::ComputeAttribute

Inherits:
Command
  • Object
show all
Defined in:
lib/hammer_cli_foreman/compute_attribute.rb

Defined Under Namespace

Classes: AddInterface, AddVolume, Create, RemoveInterface, RemoveVolume, Update, UpdateInterface, UpdateVolume

Class Method Summary collapse

Methods inherited from 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, #request_params, resolver, #resolver, resource_alias_name_mapping, resource_config, resource_name_mapping, #searchables, searchables, #send_request, #transform_format

Class Method Details

.alter_interface(interface) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/hammer_cli_foreman/compute_attribute.rb', line 24

def self.alter_interface(interface)
  # move each attribute starting with "compute_" to compute_attributes
    interface.keys.each do |key|
      if key.start_with? 'compute_'
        interface[key.gsub('compute_', '')] = interface.delete(key)
      end
    end
    interface
end

.alter_interfaces_list(interfaces_list) ⇒ Object



34
35
36
37
38
# File 'lib/hammer_cli_foreman/compute_attribute.rb', line 34

def self.alter_interfaces_list(interfaces_list)
  interfaces_list.collect do |nic|
    alter_interface(nic)
  end
end

.attribute_hash(attribute_list) ⇒ Object



20
21
22
# File 'lib/hammer_cli_foreman/compute_attribute.rb', line 20

def self.attribute_hash(attribute_list)
  attribute_list.size.times.map { |idx| idx.to_s }.zip(attribute_list).to_h
end

.get_params(options) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/hammer_cli_foreman/compute_attribute.rb', line 9

def self.get_params(options)
  params = {}
  params['compute_attribute'] = {}
  profile = HammerCLIForeman.record_to_common_format(
      HammerCLIForeman.foreman_resource(:compute_profiles).call(:show, 'id' => options['option_compute_profile_id'] )
  )
  params['compute_attribute'] = profile['compute_attributes'].select { |hash| hash['compute_resource_id'].to_s == options['option_compute_resource_id'].to_s}[0] || {}
  params['compute_attribute'].delete('attributes') if params['compute_attribute']['attributes']
  params
end