主厨:了解Chef::resource规定?
chef: understanding Chef::resource provides?
我正在 https://github.com/chef-cookbooks/mysql/blob/master/libraries/resource_mysql_client.rb 学习关于 mysql 的厨师食谱。
class Chef
class Resource
class MysqlClient < Chef::Resource::LWRPBase
provides :mysql_client
但是,我没看懂provides :mysql_client
的意思。有人可以帮我弄清楚代码吗?例如,目的是什么?如果没有线,可以吗?
谢谢
有 a great blog post talking about Chef Provider resolution. I highly recommend you read that first. Historically, Chef has had a number of different ways to figure out which provider should be loaded for a particular resource -- by using a map of resource to provider, by using 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).
如果您在单个资源 class 和单个提供者 class 上使用提供,Chef(Chef 12.5.x)每次都会将该资源映射到该提供者。如果您省略 provides
,您将依赖 Chef 在上面的博客 post 中提到的其他匹配机制之一。几乎所有其他方法都已弃用或即将被弃用。
我也推荐 the Q&A from this blog post。它讨论了旧方法、弃用,并涵盖了提供程序资源解析的其他一些细微差别。
我正在 https://github.com/chef-cookbooks/mysql/blob/master/libraries/resource_mysql_client.rb 学习关于 mysql 的厨师食谱。
class Chef
class Resource
class MysqlClient < Chef::Resource::LWRPBase
provides :mysql_client
但是,我没看懂provides :mysql_client
的意思。有人可以帮我弄清楚代码吗?例如,目的是什么?如果没有线,可以吗?
谢谢
有 a great blog post talking about Chef Provider resolution. I highly recommend you read that first. Historically, Chef has had a number of different ways to figure out which provider should be loaded for a particular resource -- by using a map of resource to provider, by using 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 aprovides
with the given resource_name, it replaces that provides (so that you can provide your resource DSL only on certain OS's).
如果您在单个资源 class 和单个提供者 class 上使用提供,Chef(Chef 12.5.x)每次都会将该资源映射到该提供者。如果您省略 provides
,您将依赖 Chef 在上面的博客 post 中提到的其他匹配机制之一。几乎所有其他方法都已弃用或即将被弃用。
我也推荐 the Q&A from this blog post。它讨论了旧方法、弃用,并涵盖了提供程序资源解析的其他一些细微差别。