Class: EPC::Command::UpdateRuntimeCommand

Inherits:
UpdateCommand show all
Defined in:
lib/epc/command/runtime/update_runtime_command.rb

Constant Summary collapse

UPDATABLE_ATTRIBUTES =
["name", "target", "deployment_stage", "username", "password", "agility_topology", "agility_environment", "runtime_env_type_id", "info"]

Constants inherited from BaseCommand

BaseCommand::GIVEUP_TICKS, BaseCommand::SLEEP_TIME, BaseCommand::TICKER_TICKS

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #klass_name, #object_id, #object_type, #options, #target_id, #target_type

Instance Method Summary collapse

Methods inherited from BaseCommand

#check_options, #context_params, #context_params=, #go, include_module, inherited, #initialize, required_options, #say_err

Methods included from PersistentAttributes

#auth_token, #caller_id, #target_url

Constructor Details

This class inherits a constructor from EPC::Command::BaseCommand

Instance Method Details

#execute(args) ⇒ Object

Raises:



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/epc/command/runtime/update_runtime_command.rb', line 6

def execute(args)
  require_object

  raise FatalError, "You need to specify at least one attribute to update" if args.size < 1
  params = {}

  args.each do |arg|
    key, val = arg.split("=")
    next if key.blank?
    params[key] = val
  end

  params.each do |attr, val|
    unless UPDATABLE_ATTRIBUTES.include?(attr)
      params.delete(attr)
      say_err("Cannot update #{attr}. Updatable attributes are: [#{UPDATABLE_ATTRIBUTES.join(', ')}]")
      next
    end
  end

  raise InputError, "You need to specify at least one attribute to update" if params.blank?

  status, response, headers = client.get(EPC::Config::RUNTIMES_PATH + "/#{object_id}")

  unless status.successful?
    say_err("Request failed: [#{response[:message]}]")
    return 1
  end

  runtime_attrs = response.merge(params.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo})
   
  status, response, headers = client.put(EPC::Config::RUNTIMES_PATH + "/#{object_id}", runtime_attrs)

  if status.successful?
    say("Plugin updated")
  else
    say_err("Request failed: [#{response[:message]}]")
  end

  return status

end