scalify/puppet-master-client

此软件包已被弃用且不再维护。未建议替代软件包。

用于 puppet-master HTTP API 的客户端库

1.1.4 2018-10-02 23:00 UTC

This package is not auto-updated.

Last update: 2022-09-04 14:46:28 UTC


README

PHP 客户端用于 puppet-master.io 公共 API。puppet-master 通过抽象 HTTP API 后的代码执行,以可扩展的方式为您调度任务,使得网站交互的执行变得超级简单。更多信息请访问 puppet-master 文档

安装

composer require scalify/puppet-master-client:~1.0

示例用法

<?php

use Scalify\PuppetMaster\Client\Client;
use Scalify\PuppetMaster\Client\ClientException;
use Scalify\PuppetMaster\Client\ClientInterface;
use Scalify\PuppetMaster\Client\CreateJob;
use Scalify\PuppetMaster\Client\Job;

require __DIR__ . '/vendor/autoload.php';

/**
 * @param $client
 */
function printCurrentJobs(ClientInterface $client)
{
    foreach (["created", "queued", "done"] as $status) {
        $jobs = $client->getJobsByStatus($status, 1, 1000);
        echo(sprintf("API currently has %s jobs at status %s", count($jobs), $status) . PHP_EOL);
    }

    $jobs = $client->getJobs(1, 1000);
    echo(sprintf("API currently has %s jobs at all", count($jobs)) . PHP_EOL);

    /** @var Job $job */
    foreach ($jobs as $job) {
        echo(sprintf("API has job %s at status %s", $job->getUUID(), $job->getStatus()) . PHP_EOL);
    }
}

function newTestCreateJob(): CreateJob
{
    $data = json_decode(file_get_contents("test-data/create-request.json"), true);

    return new CreateJob($data["code"], $data["vars"], []);
}

try {
    $client = new Client(new \GuzzleHttp\Client(), "https://", "puppet");

    printCurrentJobs($client);

    $createdJob = $client->createJob(newTestCreateJob());
    echo(sprintf("Created Job %s at status %s", $createdJob->getUUID(), $createdJob->getStatus()) . PHP_EOL);

    do {
        $gotJob = $client->getJob($createdJob->getUUID());
        echo(sprintf("Got Job %s at status %s", $gotJob->getUUID(), $gotJob->getStatus()) . PHP_EOL);

        if ($gotJob->getStatus() !== Job::STATUS_DONE) {
            echo("Sleeping for 1 second ..." . PHP_EOL);
            sleep(1);
        }
    } while ($gotJob->getStatus() !== Job::STATUS_DONE);

    $client->deleteJob($createdJob->getUUID());
    echo(sprintf("Delete job %s", $createdJob->getUUID()) . PHP_EOL);
} catch (ClientException $e) {
    echo($e->getMessage() . PHP_EOL);
    exit(1);
}

许可证

版权所有 2018 Scalify GmbH

根据 Apache 许可证 2.0 版(“许可证”);除非符合许可证规定或书面同意,否则不得使用此文件。您可以在以下位置获取许可证副本:

	https://apache.ac.cn/licenses/LICENSE-2.0

除非适用法律要求或书面同意,否则在许可证下分发的软件按“原样”提供,不提供任何明示或暗示的保证或条件。有关许可证的具体语言规定,请参阅许可证。