PHP code example of scalify / puppet-master-client
1. Go to this page and download the library: Download scalify/puppet-master-client library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
scalify / puppet-master-client example snippets
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;
rrently 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(), "http://localhost", "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);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.