python - 获取 Chef.Exceptions.ChefServerError : Method Not Allowed while creating Role in chef

标签 python chef-infra pychef

我正在尝试使用 PyChef api 创建一个角色。我能够成功检索节点或角色列表(GET 方法),但是当我尝试创建角色(POST 方法)时,我收到运行时异常,即方法不允许。 这是我的代码:

import json
import requests
import re
import chef
from chef.exceptions import ChefError, ChefServerNotFoundError
from chef.base import ChefQuery, ChefObject
from chef import Role

pem_file = "path-to-validator.pem/chef-validator.pem"
client_name = "validator"
node_name = "root"
role_url = "ChefServer-URL/roles/"
rolelist =[]

chef_api = chef.ChefAPI(role_url,pem_file,client_name,ssl_verify=False)

create_role = chef.Role.create(name='myrole', api=chef_api ,description='A test role', run_list=['recipe[foo]'],default_attributes={'attr': 'foo'}, override_attributes={'attr': 'bar'})

rolelst = chef.Role.list()
for j in rolelst:
  rolelist.append(j)
print rolelist

这是我面临的错误:

Traceback (most recent call last):
File "roleapi.py", line 37, in <module>
create_role = chef.Role.create(name='myrole', api=chef_api ,description='A 
test role', run_list=['recipe[foo]'],default_attributes={'attr': 'foo'}, 
override_attributes={'attr': 'bar'})
File "/usr/lib/python2.6/site-packages/chef/base.py", line 99, in create
api.api_request('POST', cls.url, data=obj)
File "/usr/lib/python2.6/site-packages/chef/api.py", line 217, in 
api_request
response = self.request(method, path, headers, data)
File "/usr/lib/python2.6/site-packages/chef/api.py", line 207, in request
raise ChefServerError.from_error(response.reason, code=response.status_code)
chef.exceptions.ChefServerError: Method Not Allowed

所以请建议我如何解决此错误。预先感谢您。

最佳答案

URL 应该是 Chef 服务器的基础,可能类似于 https://myserver.com/organizations/foo

关于python - 获取 Chef.Exceptions.ChefServerError : Method Not Allowed while creating Role in chef,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44002987/

相关文章:

python - 如何使用 PyChef 执行 'knife client delete' 和 'knife client create' ?

python - 如何在 Twilio 中获取最新录音?

ruby - 带有循环的 Chefspec 测试资源

ssl - 为什么 Chef 在 Chef-Workstation 上使用 knife Command 时会抛出 SSL 错误?

python - pychef中的ssl证书验证

python - Tanh-sinh求积数值积分法收敛到错误值

python - 整个 session 的 pytest 超时

python - Numpy:获取排序后高于 0 的最高值的索引

configuration - 创建用户时的 Chef 服务器错误(/etc/opscode/pivotal.rb 不存在)