lib/proto/command_interface_handler.rb in auser-poolparty-1.3.10 vs lib/proto/command_interface_handler.rb in auser-poolparty-1.3.11
- old
+ new
@@ -2,11 +2,35 @@
def run_command(cld, command, args)
cr = CloudThrift::CloudResponse.new
cr.name = cld.name
cr.command = command
- resp = begin
+
+ cr.response = format_response(get_response(cld, command, args))
+
+ return cr
+ end
+
+ def cast_command(cld, command, args)
+
+ cr = CloudThrift::CloudResponse.new
+ cr.name = cld.name
+ cr.command = command
+ cr.response = format_response("Running command: #{command}(#{args})")
+
+ fork do
+ get_response(cld, command, args)
+ end
+
+ return cr
+ end
+
+
+ private
+
+ def get_response(cld, command, args)
+ begin
the_cloud = clouds[cld.name]
if the_cloud
if command.include?(".")
command.split(".").inject(the_cloud) do |curr_cloud, cmd|
if cmd.match(/\((.*)\)/)
@@ -23,25 +47,20 @@
else
"Cloud not found: #{cld.name}"
end
rescue Exception => e
cr.response = "Error: #{e.inspect}"
- end
-
- cr.response = format_response(resp)
-
- return cr
+ end
end
- private
-
def format_response(resp)
case resp
when Array
resp.join(",")
when Hash
resp.map {|k,v| "#{k}:#{format_response(v.empty? ? "null" : v)}" }
else
[resp]
end.map {|ele| ele.to_s }
end
+
end
\ No newline at end of file