Class: TungstenAPI::ReplicatorAPICall

Inherits:
APICall
  • Object
show all
Defined in:
lib/tungsten/api.rb

Overview

ReplicatorAPICall is a class that handles API Calls through Tungsten Replicator tools

It uses the same interface as APICall, but it is initialized differently

Public instance methods:

  • initialize (name, tools_path, tool, command, help, rmi_port=10000)

  • get (service)

Constant Summary collapse

@@template =
'%-15s %-10s %-25s %s'

Instance Attribute Summary collapse

Attributes inherited from APICall

#name, #prefix, #return_structure, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from APICall

#description, #evaluate_response, #from_hash, #make_uri, #post, set_api_root, set_return_on_call_fail

Constructor Details

#initialize(name, tools_path, tool, command, help, rmi_port = 10000) ⇒ ReplicatorAPICall

Initializes a ReplicatorAPICall object

name : how to identify the API call
tool : which tool we are calling
tools_path : where to find the tool
rmi_port : which port should trepctl use
help : a brief description of the API call


272
273
274
275
276
277
278
279
# File 'lib/tungsten/api.rb', line 272

def initialize (name, tools_path, tool, command, help, rmi_port=10000)
    @name = name
    @tool = tool
    @command = command
    @tools_path = tools_path
    @rmi_port = rmi_port
    @help = help
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



256
257
258
# File 'lib/tungsten/api.rb', line 256

def command
  @command
end

Class Method Details

.dashesObject

override ancestor’s dashes



315
316
317
# File 'lib/tungsten/api.rb', line 315

def self.dashes
    return sprintf(@@template, '----', '----', '-------', '----')
end

.headerObject

override ancestor’s header



308
309
310
# File 'lib/tungsten/api.rb', line 308

def self.header
    return sprintf(@@template, :name.to_s, :tool.to_s, :command.to_s, :help.to_s)
end

Instance Method Details

#get(service, host, more_options) ⇒ Object

Get a JSON object from the output of a command, such as ‘trepctl status -json’ If ‘service’ and host are given, the command is called with -service #service and -host #host



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/tungsten/api.rb', line 285

def get(service, host, more_options)
    service_clause=''
    host_clause=''
    port_clause=''
    more_options = '' unless more_options
    if service
        service_clause = "-service #{service}"
    end
    if host
        host_clause = "-host #{host}"
    end
    if @rmi_port
        port_clause= "-port #{@rmi_port}"
    end
    full_command = "#{@tools_path}/#{@tool} #{port_clause} #{host_clause} #{service_clause} #{command} #{more_options}"
    puts full_command if ENV["SHOW_INTERNALS"]
    json_text = %x(#{full_command}) 
    return JSON.parse(json_text)
end

#to_hashObject



323
324
325
# File 'lib/tungsten/api.rb', line 323

def to_hash
    return  { :name.to_s => @name, :tool.to_s => @tool,  :command.to_s => @command , :help.to_s => @help }
end

#to_sObject



319
320
321
# File 'lib/tungsten/api.rb', line 319

def to_s
    return sprintf(@@template, @name, @tool, @command, @help)
end