Class: Chef::Knife::JobStart
- Inherits:
-
Chef::Knife
- Object
- Chef::Knife
- Chef::Knife::JobStart
- Includes:
- JobHelpers
- Defined in:
- lib/chef/knife/job_start.rb
Instance Method Summary collapse
Methods included from JobHelpers
#file_helper, #get_env, #get_quorum, #process_search, #run_helper, #status_code, #status_string
Instance Method Details
#run ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/chef/knife/job_start.rb', line 87 def run job_name = @name_args[0] if job_name.nil? ui.error "No job specified." show_usage exit 1 end @node_names = process_search(config[:search], name_args[1, @name_args.length - 1]) job_json = { "command" => job_name, "nodes" => @node_names, } job_json["quorum"] = get_quorum(config[:quorum], @node_names.length) v2_json = job_json.dup v2_json["file"] = "raw:" + file_helper(config[:send_file]) if config[:send_file] v2_json["capture_output"] = config[:capture_output] env = get_env(config) v2_json["env"] = env if env v2_json["dir"] = config[:in_dir] if config[:in_dir] v2_json["user"] = config[:as_user] if config[:as_user] begin job = run_helper(config, v2_json) rescue Net::HTTPClientException => e raise e if e.response.code != "400" ui.warn "Falling back to Push Jobs v1 mode." unless env.empty? ui.error "Sending Environment attributes isn't possible for Push Jobs 1.0" exit 1 end %i{ send_file dir user }.each do |feature| if config[feature] ui.error "Can't use a 2.0 feature (#{feature}) with a 1.0 server" exit 1 end end job = run_helper(config, job_json) end output(job) exit(status_code(job)) end |