Class: HammerCLIForeman::Parameter::SetCommand

Inherits:
HammerCLI::Apipie::Command
  • Object
show all
Includes:
HammerCLI::Messages
Defined in:
lib/hammer_cli_foreman/parameter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.command_name(name = nil) ⇒ Object



23
24
25
# File 'lib/hammer_cli_foreman/parameter.rb', line 23

def self.command_name(name=nil)
  super(name) || "set_parameter"
end

.resource(resource = nil) ⇒ Object



27
28
29
# File 'lib/hammer_cli_foreman/parameter.rb', line 27

def self.resource(resource=nil)
  super(resource) || HammerCLI::Apipie::ResourceDefinition.new(ForemanApi::Resources::Parameter)
end

Instance Method Details

#base_action_paramsObject



42
43
44
# File 'lib/hammer_cli_foreman/parameter.rb', line 42

def base_action_params
  {}
end

#create_parameterObject



62
63
64
65
66
67
68
69
70
71
# File 'lib/hammer_cli_foreman/parameter.rb', line 62

def create_parameter
  params = {
    "parameter" => {
      "name" => option_name,
      "value" => option_value
    }
  }.merge base_action_params

  HammerCLIForeman.record_to_common_format(resource.call(:create, params))
end

#executeObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/hammer_cli_foreman/parameter.rb', line 31

def execute
  if parameter_exist?
    update_parameter
    print_message success_message_for :update if success_message_for :update
  else
    create_parameter
    print_message success_message_for :create if success_message_for :create
  end
  HammerCLI::EX_OK
end

#parameter_exist?Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/hammer_cli_foreman/parameter.rb', line 46

def parameter_exist?
  params = HammerCLIForeman.collection_to_common_format(resource.call(:index, base_action_params)[0])
  params.find { |p| p["name"] == option_name }
end

#update_parameterObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/hammer_cli_foreman/parameter.rb', line 51

def update_parameter
  params = {
    "id" => option_name,
    "parameter" => {
      "value" => option_value
    }
  }.merge base_action_params

  HammerCLIForeman.record_to_common_format(resource.call(:update, params))
end