OPSCode Chef API 库

此包的规范存储库似乎已不存在,因此已冻结此包。

2.3.1 2021-04-26 18:40 UTC

This package is auto-updated.

Last update: 2021-04-26 18:41:28 UTC


README

Chef Server API 用于提供对 Chef 服务器上对象的访问,包括节点、环境、角色、食谱(以及食谱版本),以及管理 API 客户端列表和相关的 RSA 公钥对。

这是一个通用库,并提供了对 Laravel 框架的额外支持。

安装

andreseko/chef 添加到 composer.json 的依赖项中

{
    "require": {
        "andreseko/chef": "^v1.0.0"
    }
}

使用 composer update 更新您的包或使用 composer install 安装。

使用方法

创建一个如下所示的 chef 对象

// composer
require_once 'vendor/autoload.php';
use Andreseko\Chef\Chef;

// create chef object
$chef = new Chef($server, $client, $key, $version);

// API request
$response = $chef->api($endpoint, $method, $data);

有关所有可用端点的详细信息,请参阅 http://docs.opscode.com/api_chef_server.html

示例

获取节点

$nodes = $chef->get('/nodes');

创建数据袋

$bag = new stdClass;
$bag->name = "test";

$resp = $chef->post('/data', $bag);

更新节点

$node = $chef->get('/nodes/webserver1');
$node->attributes->type = "webserver";

$chef->put('/nodes/webserver1', $node);

删除数据袋

$chef->delete('/data/test/item');

Laravel

app/config/app.php 中将 Chef 包与 Laravel 注册,添加以下提供者

'Andreseko\Chef\ChefServiceProvider',

以及此别名

'Chef'            => 'Andreseko\Chef\Facades\Chef'

使用 Artisan 创建配置文件的副本

php artisan config:publish Andreseko/chef

app/config/packages/andreseko/chef/config.php 中编辑创建的配置文件以匹配您的环境

'server'  = the URL for the Chef Server
'client'  = the name used when authenticating to a Chef Server
'key'     = the location of the file which contains the client key
'version' = the version of the Chef Server API that is being used