Chef服务器REST API

时间:2014-07-03 13:24:58

标签: rest chef

我正在为项目目的探索Chef的Rest api。我能够获取,发布和删除节点/节点数据。但是我无法执行PUT请求,即更新服务器上的节点相关数据。这是我得到的错误的屏幕截图。enter image description here

以下是发出请求的代码。我已正确指定了身份验证参数,并且它们正常运行。

rest = Chef::REST.new(server_url, client_name, signing_key_filename)
print "Enter the node you want to edit :\n"
editnode = gets.chomp
node = rest.get_rest("/nodes/#{editnode}")
print "#{node.name}\n"
print "\t#{node.run_list}\n"
print "Now updating the node as per the parameters specified :\n"
update_node = {
"run_list" => "recipe[123]"
}
rest.put_rest("nodes/#{editnode}","update_node")    

请提出一些解决方案。

1 个答案:

答案 0 :(得分:3)

所以有两个问题:

  1. 主要问题是你在put_rest中引用了"update_node",因此当服务器需要哈希时,你将它作为文字发回。
  2. 您不能只发送PUT的运行列表,您需要发送完整的节点数据结构。最简单的方法是从GET修改从服务器返回的那个。