fluke/devops-client/lib/devops-client/handler/network.rb

36 lines
838 B
Ruby
Raw Normal View History

2014-05-08 15:34:26 +04:00
require "devops-client/handler/handler"
require "devops-client/options/network_options"
require "json"
require "devops-client/output/network"
class Network < Handler
2015-04-14 15:29:02 +03:00
output_with Output::Network
2014-05-08 15:34:26 +04:00
def initialize(host, def_options={})
2015-04-14 15:29:02 +03:00
@host, @options = host, def_options
2014-05-08 15:34:26 +04:00
@options_parser = NetworkOptions.new(ARGV, def_options)
end
def handle
2015-04-14 15:29:02 +03:00
current_command = ARGV[1].to_sym
@options, @args = @options_parser.parse_options_for!(current_command)
case current_command
when :list
list_handler(@args[2])
2014-05-08 15:34:26 +04:00
output
end
end
2015-04-14 15:29:02 +03:00
def list_handler(provider=nil)
r = inspect_parameters @options_parser.list_params, provider
2014-05-08 15:34:26 +04:00
unless r.nil?
@options_parser.invalid_list_command
abort(r)
end
2015-04-14 15:29:02 +03:00
@list = get("/networks/#{provider}").sort!{|x,y| x["name"] <=> y["name"]}
2014-05-08 15:34:26 +04:00
end
end