lib/gaptool-client.rb in gaptool-client-0.6.15 vs lib/gaptool-client.rb in gaptool-client-0.6.16
- old
+ new
@@ -14,15 +14,16 @@
nodes.each do |node|
@host = "#{node['role']}:#{node['environment']}:#{node['instance']}"
unless grepable
puts Rainbow(@host).green
end
- node.keys.each do |key|
+ keys = node.keys.sort
+ keys.each do |key|
if grepable
puts "#{@host}|#{key}|#{node[key]}"
else
- unless key == node.keys.last
+ unless key == keys.last
puts " ┠ #{Rainbow(key).cyan}: #{node[key]}"
else
puts " ┖ #{Rainbow(key).cyan}: #{node[key]}\n\n"
end
end
@@ -212,26 +213,55 @@
option ["-r", "--role"], "ROLE", "Role name, e.g. frontend", :required => false
option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => false
option ["-i", "--instance"], "INSTANCE", "Node instance, leave blank to query avilable nodes", :required => false
option ["-p", "--parseable"], :flag, "Display in non-pretty parseable JSON"
option ["-g", "--grepable"], :flag, "Display in non-pretty grep-friendly text"
+ option ['-H', '--hidden'], :flag, 'Display hidden hosts'
def execute
@nodes = Array.new
+ params = hidden? ? {hidden: true} : {}
if instance
@nodes = [$api.getonenode(instance)]
elsif role && environment
- @nodes = $api.getenvroles(role, environment)
+ @nodes = $api.getenvroles(role, environment, params)
elsif role && !environment
- @nodes = $api.getrolenodes(role)
+ @nodes = $api.getrolenodes(role, params)
else
- @nodes = $api.getallnodes()
+ @nodes = $api.getallnodes(params)
end
infohelper(@nodes, parseable?, grepable?)
end
end
+ class SetCommand < Clamp::Command
+ option ["-i", "--instance"], "INSTANCE", "Node instance, required", required: true
+ option ["-p", "--parseable"], :flag, "Display in non-pretty parseable JSON"
+ option ["-g", "--grepable"], :flag, "Display in non-pretty grep-friendly text"
+ option ['-k', '--parameter'], 'NAME', 'Set parameter for the node', required: true, multivalued: true
+ option ['-v', '--value'], 'VALUE', 'Value for parameter', required: true, multivalued: true
+
+ def convert_bool(v)
+ case v.downcase
+ when "true"
+ true
+ when "false"
+ false
+ else
+ v
+ end
+ end
+
+ def execute
+ if parameter_list.length != value_list.length
+ puts Rainbow("parameter and value length mismatch").red
+ end
+ params = Hash[parameter_list.each_with_index.map {|p, i| [p, convert_bool(value_list[i])]}]
+ infohelper([$api.setparameters(instance, params)], parseable?, grepable?)
+ end
+ end
+
class ChefrunCommand < Clamp::Command
option ["-r", "--role"], "ROLE", "Role name to ssh to", :required => true
option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
option ["-i", "--instance"], "INSTANCE", "Instance ID, e.g. i-12345678", :required => false
option ["-A", "--attribute"], "ATTRIBUTE", "Pass one or more parameters to the deploy recipe in recipe.attr=value format", :multivalued => true
@@ -286,17 +316,19 @@
option ["-e", "--environment"], "ENVIRONMENT", "Which environment, e.g. production", :required => true
option ["-b", "--branch"], "BRANCH", "Git branch to deploy, default is master", :required => false
option ["-r", "--rollback"], :flag, "Toggle this to rollback last deploy"
option ["-i", "--instance"], "INSTANCE", "Instance ID, e.g. i-12345678", :required => false
option ["-A", "--attribute"], "ATTRIBUTE", "Pass one or more parameters to the deploy recipe in recipe.attr=value format", :multivalued => true
+ option ['-H', '--hidden'], :flag, 'Display hidden hosts'
def execute
attrs = split_attrs(attribute_list)
if instance
nodes = [$api.getonenode(instance)]
else
- nodes = $api.getappnodes(app, environment)
+ params = hidden? ? {hidden: true} : {}
+ nodes = $api.getappnodes(app, environment, params)
end
nodes.peach do |node|
if node['chef_runlist'].nil?
runlist = ['recipe[deploy]']
elsif node['chef_runlist'].is_a? Array
@@ -358,9 +390,10 @@
subcommand "info", "Displays information about nodes", InfoCommand
subcommand "init", "Create new application cluster", InitCommand
subcommand "terminate", "Terminate instance", TerminateCommand
subcommand "ssh", "ssh to cluster host", SshCommand
+ subcommand "set", "update properties for a node", SetCommand
subcommand "chefrun", "chefrun on a resource pool", ChefrunCommand
subcommand "deploy", "deploy on an application", DeployCommand
subcommand "rehash", "Regenerate all host metadata. KNOW WHAT THIS DOES BEFORE RUNNING IT", RehashCommand
subcommand "runcmd", "Run command on instance", RuncmdCommand
subcommand "version", "Show version", VersionCommand