bin/tl in testlab-0.3.0 vs bin/tl in testlab-0.3.1
- old
+ new
@@ -1,6 +1,25 @@
#!/usr/bin/env ruby
+################################################################################
+#
+# Author: Zachary Patten <zachary AT jovelabs DOT com>
+# Copyright: Copyright (c) Zachary Patten
+# License: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+################################################################################
require 'gli'
require 'testlab'
include GLI::App
include TestLab::Utility::Misc
@@ -56,11 +75,18 @@
end
desc 'Display information on the status of the test lab'
command :status do |status|
status.action do |global_options,options,args|
- @testlab.status
+ @testlab.ui.stdout.puts("\nNODES:".green.bold)
+ commands[:node].commands[:status].execute({}, {}, [])
+
+ @testlab.ui.stdout.puts("\nNETWORKS:".green.bold)
+ commands[:network].commands[:status].execute({}, {}, [])
+
+ @testlab.ui.stdout.puts("\nCONTAINERS:".green.bold)
+ commands[:container].commands[:status].execute({}, {}, [])
end
end
desc 'Manage nodes'
arg_name 'Describe arguments to node here'
@@ -74,22 +100,64 @@
c.command :ssh do |ssh|
ssh.action do |global_options,options,args|
help_now!('id is required') if options[:id].nil?
node = @testlab.nodes.select{ |n| n.id.to_sym == options[:id].to_sym }.first
+ node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
+
node.ssh.console
end
end
+ c.desc 'Display the status of node(s)'
+ c.long_desc 'Displays the status of all nodes or a single node if supplied via the id parameter.'
+ c.command :status do |status|
+ status.action do |global_options, options, args|
+ if options[:id].nil?
+ ZTK::Report.new(:ui => @testlab.ui).spreadsheet(@testlab.nodes, TestLab::Node::STATUS_KEYS) do |node|
+ OpenStruct.new(node.status)
+ end
+ else
+ node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first
+ node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!"
+
+ ZTK::Report.new(:ui => @testlab.ui).list(node, TestLab::Node::STATUS_KEYS) do |node|
+ OpenStruct.new(node.status)
+ end
+ end
+ end
+ end
+
end
desc 'Manage networks'
arg_name 'Describe arguments to network here'
command :network do |c|
- c.action do |global_options,options,args|
- puts "network command ran"
+
+ c.desc 'Network ID or Name'
+ c.arg_name 'network'
+ c.flag [:i, :id]
+
+ c.desc 'Display the status of network(s)'
+ c.long_desc 'Displays the status of all networks or a single network if supplied via the id parameter.'
+ c.command :status do |status|
+ status.action do |global_options, options, args|
+ if options[:id].nil?
+ ZTK::Report.new(:ui => @testlab.ui).spreadsheet(@testlab.networks, TestLab::Network::STATUS_KEYS) do |network|
+ OpenStruct.new(network.status)
+ end
+ else
+ network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first
+ network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!"
+
+ ZTK::Report.new(:ui => @testlab.ui).list(network, TestLab::Network::STATUS_KEYS) do |network|
+ OpenStruct.new(network.status)
+ end
+ end
+ end
end
+
end
desc 'Manage containers'
arg_name 'Describe arguments to container here'
command :container do |c|
@@ -98,18 +166,39 @@
c.arg_name 'container'
c.flag [:i, :id]
c.desc 'Open an SSH console to a container'
c.command :ssh do |ssh|
- ssh.action do |global_options,options,args|
+ ssh.action do |global_options, options, args|
help_now!('id is required') if options[:id].nil?
container = @testlab.containers.select{ |n| n.id.to_sym == options[:id].to_sym }.first
+ container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!"
+
container.ssh.console
end
end
+ c.desc 'Display the status of container(s)'
+ c.long_desc 'Displays the status of all containers or a single container if supplied via the id parameter.'
+ c.command :status do |status|
+ status.action do |global_options, options, args|
+ if options[:id].nil?
+ ZTK::Report.new(:ui => @testlab.ui).spreadsheet(@testlab.containers, TestLab::Container::STATUS_KEYS) do |container|
+ OpenStruct.new(container.status)
+ end
+ else
+ container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first
+ container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!"
+
+ ZTK::Report.new(:ui => @testlab.ui).list(container, TestLab::Container::STATUS_KEYS) do |container|
+ OpenStruct.new(container.status)
+ end
+ end
+ end
+ end
+
end
desc 'Manage routes'
command :route do |c|
@@ -167,9 +256,10 @@
case exception
when GLI::BadCommandLine, GLI::UnknownCommand, GLI::UnknownCommandArgument, GLI::UnknownGlobalArgument then
command_regex = /Command '([\w]+)' /
command = exception.message.scan(command_regex).flatten.first
+ @ui.stderr.puts
commands[:help] and commands[:help].execute({}, {}, (command.nil? ? [] : [command.to_s]))
false
else
@logger.fatal { exception.inspect }