bin/tl in testlab-0.6.4 vs bin/tl in testlab-0.6.5

- old
+ new

@@ -108,20 +108,20 @@ arg_name 'Describe arguments to node here' command :node do |c| c.desc 'Node ID or Name' c.arg_name 'node' - c.flag [:i, :id] + c.flag [:n, :name] # NODE SSH ########### c.desc 'Open an SSH console to a node' c.command :ssh do |ssh| ssh.action do |global_options,options,args| - help_now!('id is required') if options[:id].nil? + help_now!('name is required') if options[:name].nil? - node = @testlab.nodes.select{ |n| n.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |n| n.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!" node.ssh.console end end @@ -130,18 +130,18 @@ ############## 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? + if options[:name].nil? # No ID supplied; show everything ZTK::Report.new(:ui => @testlab.ui).spreadsheet(@testlab.nodes, TestLab::Node::STATUS_KEYS) do |node| OpenStruct.new(node.status) end else # ID supplied; show just that item - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].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 @@ -155,14 +155,14 @@ c.long_desc <<-EOF Up a node. The node is started and brought online. EOF c.command :up do |up| up.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!" node.up end end @@ -174,14 +174,14 @@ c.long_desc <<-EOF Down a node. The node is stopped taking it offline. EOF c.command :down do |down| down.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!" node.down end end @@ -193,14 +193,14 @@ c.long_desc <<-EOF Create a node. The node is created. EOF c.command :create do |create| create.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you screateplied!" node.create end end @@ -212,14 +212,14 @@ c.long_desc <<-EOF Destroy a node. The node is stopped and destroyed. EOF c.command :destroy do |destroy| destroy.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!" node.destroy end end @@ -231,14 +231,14 @@ c.long_desc <<-EOF Setup a node. The node is created, started and provisioned. EOF c.command :setup do |setup| setup.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!" node.setup end end @@ -250,14 +250,14 @@ c.long_desc <<-EOF Teardown a node. The node is offlined and destroyed. EOF c.command :teardown do |teardown| teardown.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - node = @testlab.nodes.select{ |c| c.id.to_sym == options[:id].to_sym }.first + node = @testlab.nodes.select{ |c| c.id.to_sym == options[:name].to_sym }.first node.nil? and raise TestLab::TestLabError, "We could not find the node you supplied!" node.teardown end end @@ -271,11 +271,11 @@ arg_name 'Describe arguments to network here' command :network do |c| c.desc 'Network ID or Name' c.arg_name 'network' - c.flag [:i, :id] + c.flag [:n, :name] # ROUTES ######### c.desc 'Manage routes' @@ -284,13 +284,13 @@ # ROUTE ADD ############ route.desc 'Add routes to lab networks' route.command :add do |add| add.action do |global_options,options,args| - help_now!('id is required') if options[:id].nil? + help_now!('name is required') if options[:name].nil? - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" network.manage_route(:add) @testlab.ui.stdout.puts("Added routes successfully!".green.bold) @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip @@ -300,13 +300,13 @@ # ROUTE DEL ############ route.desc 'Delete routes to lab networks' route.command :del do |del| del.action do |global_options,options,args| - help_now!('id is required') if options[:id].nil? + help_now!('name is required') if options[:name].nil? - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" network.manage_route(:del) @testlab.ui.stdout.puts("Deleted routes successfully!".red.bold) @testlab.ui.stdout.puts %x(netstat -nr | grep '#{network.node.ip}').strip @@ -316,13 +316,13 @@ # ROUTE SHOW ############# route.desc 'Show routes to lab networks' route.command :show do |show| show.action do |global_options,options,args| - help_now!('id is required') if options[:id].nil? + help_now!('name is required') if options[:name].nil? - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" @testlab.ui.stdout.puts("TestLab routes:".green.bold) case RUBY_PLATFORM when /darwin/ then @@ -338,11 +338,11 @@ ################# 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? + if options[:name].nil? # No ID supplied; show everything networks = @testlab.networks.delete_if{|n| n.node.dead? } if networks.count == 0 @testlab.ui.stderr.puts("You either have no networks defined or dead nodes!".yellow) else @@ -350,11 +350,11 @@ OpenStruct.new(network.status) end end else # ID supplied; show just that item - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].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 @@ -368,14 +368,14 @@ c.long_desc <<-EOF Up a network. The network is started and brought online. EOF c.command :up do |up| up.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" network.up end end @@ -387,14 +387,14 @@ c.long_desc <<-EOF Down a network. The network is stopped taking it offline. EOF c.command :down do |down| down.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" network.down end end @@ -406,14 +406,14 @@ c.long_desc <<-EOF Setup a network. The network is created, started and provisioned. EOF c.command :setup do |setup| setup.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" network.setup end end @@ -425,14 +425,14 @@ c.long_desc <<-EOF Teardown a network. The network is offlined and destroyed. EOF c.command :teardown do |teardown| teardown.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - network = @testlab.networks.select{ |c| c.id.to_sym == options[:id].to_sym }.first + network = @testlab.networks.select{ |c| c.id.to_sym == options[:name].to_sym }.first network.nil? and raise TestLab::TestLabError, "We could not find the network you supplied!" network.teardown end end @@ -446,11 +446,11 @@ arg_name 'Describe arguments to container here' command :container do |c| c.desc 'Container ID or Name' c.arg_name 'container' - c.flag [:i, :id] + c.flag [:n, :name] # CONTAINER SSH ################ c.desc 'Open an SSH console to a container' c.command :ssh do |ssh| @@ -459,21 +459,21 @@ ssh.arg_name 'username' ssh.flag [:u, :user] ssh.desc 'Specify an SSH Identity Key to use' ssh.arg_name 'key' - ssh.flag [:k, :key] + ssh.flag [:i, :identity] ssh.action do |global_options, options, args| - help_now!('id is required') if options[:id].nil? + help_now!('name is required') if options[:name].nil? - container = @testlab.containers.select{ |n| n.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |n| n.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" ssh_options = Hash.new ssh_options[:user] = options[:user] - ssh_options[:keys] = options[:key] + ssh_options[:keys] = options[:identity] container.ssh(ssh_options).console end end @@ -483,11 +483,11 @@ c.long_desc <<-EOF Displays the status of all containers or a single container if supplied via the ID parameter. EOF c.command :status do |status| status.action do |global_options, options, args| - if options[:id].nil? + if options[:name].nil? # No ID supplied; show everything containers = @testlab.containers.delete_if{ |c| c.node.dead? } if containers.count == 0 @testlab.ui.stderr.puts("You either have no containers defined or dead nodes!".yellow) else @@ -497,11 +497,11 @@ OpenStruct.new(container.status) end end else # ID supplied; show just that item - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].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 @@ -519,14 +519,14 @@ Down -> Destroy -> Create -> Up EOF c.command :recycle do |recycle| recycle.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.teardown container.setup end @@ -539,14 +539,14 @@ c.long_desc <<-EOF Up a container. The container is started and brought online. EOF c.command :up do |up| up.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.up end end @@ -558,14 +558,14 @@ c.long_desc <<-EOF Down a container. The container is stopped taking it offline. EOF c.command :down do |down| down.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.down end end @@ -577,14 +577,14 @@ c.long_desc <<-EOF Create a container. The container is created. EOF c.command :create do |create| create.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you screateplied!" container.create end end @@ -596,14 +596,14 @@ c.long_desc <<-EOF Destroy a container. The container is stopped and destroyed. EOF c.command :destroy do |destroy| destroy.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.destroy end end @@ -615,14 +615,14 @@ c.long_desc <<-EOF Setup a container. The container is created, started and provisioned. EOF c.command :setup do |setup| setup.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.setup end end @@ -634,14 +634,14 @@ c.long_desc <<-EOF Teardown a container. The container is offlined and destroyed. EOF c.command :teardown do |teardown| teardown.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.teardown end end @@ -653,13 +653,13 @@ c.long_desc <<-EOF Clone a container. The container is offlined and an ephemeral copy of it is started. EOF c.command :clone do |clone| clone.action do |global_options, options, args| - if options[:id].nil? - help_now!('id is required') if options[:id].nil? + if options[:name].nil? + help_now!('name is required') if options[:name].nil? else - container = @testlab.containers.select{ |c| c.id.to_sym == options[:id].to_sym }.first + container = @testlab.containers.select{ |c| c.id.to_sym == options[:name].to_sym }.first container.nil? and raise TestLab::TestLabError, "We could not find the container you supplied!" container.clone end end