gpt4 book ai didi

mysql - Chef :了解 Chef::resource 提供?

转载 作者:太空宇宙 更新时间:2023-11-03 17:47:17 25 4
gpt4 key购买 nike

我正在研究关于 mysql 的 Chef Recipe https://github.com/chef-cookbooks/mysql/blob/master/libraries/resource_mysql_client.rb .

class Chef
class Resource
class MysqlClient < Chef::Resource::LWRPBase
provides :mysql_client

不过,我没看懂provides :mysql_client的意思。有人可以帮我弄清楚代码吗?例如,目的是什么?如果没有线,可以吗?

谢谢

最佳答案

a great blog post谈论 Chef Provider 决议。我强烈建议您先阅读该内容。从历史上看,Chef 有许多不同的方法来确定应该为特定资源加载哪个提供者——通过使用 a map of resource to provider。 , 通过使用 a class name matching algorithm ,最近,正如您所指出的,使用 provides:

provides 旨在 signal that the class provides a particular DSL object .该方法的注释特别有启发性:

Resources have an automatic DSL based on their resource_name, equivalent to provides :resource_name (providing the resource on all OS's). If you declare a provides with the given resource_name, it replaces that provides (so that you can provide your resource DSL only on certain OS's).

如果您在单个资源类和单个提供者类上使用提供,Chef(Chef 12.5.x)每次都会将该资源映射到该提供者。如果您省略 provides,您将依赖 Chef 在上面的博文中提到的其他匹配机制之一。几乎所有其他方法都已弃用或即将被弃用。

我还推荐 the Q&A from this blog post .它讨论了旧方法、弃用,并涵盖了提供程序资源解析的其他一些细微差别。

关于mysql - Chef :了解 Chef::resource 提供?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33584376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com