Class: EPC::Command::CreateServiceversionCommand

Inherits:
BaseCommand show all
Defined in:
lib/epc/command/serviceversion/create_serviceversion_command.rb

Constant Summary

Constants inherited from BaseCommand

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

Instance Attribute Summary

Attributes inherited from BaseCommand

#client, #options

Instance Method Summary collapse

Methods inherited from BaseCommand

#go, inherited, #initialize, required_options

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(*params) ⇒ Object

Raises:



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/epc/command/serviceversion/create_serviceversion_command.rb', line 4

def execute(*params)
  label = params[1]
  definition = params[2]

  raise FatalError, "Label and definition identifier are both required." if label.nil? || definition.nil?

  if numeric?(definition)
    definition_id = definition.to_i
  else
    definition_id = get_resource_id(EPC::Config::SERVICE_DEFINITIONS_PATH, "name", definition)
  end

  raise InputError, "Service definition not found" if definition_id.nil?

  up_script = read_file(@options[:up_script]) unless blank?(@options[:up_script])
  down_script = read_file(@options[:down_script]) unless blank?(@options[:down_script])

  status, response, headers = client.post(EPC::Config::SERVICE_VERSIONS_PATH, {:label => label, :definition_id => definition_id, :up_script => up_script, :down_script => down_script})

  if status.successful?
    say("Service version successfully created.")
  else
    say("Request failed: [#{response[:message]}]")
  end
  return status
end