chromabits/tutum-php

This package is abandoned and no longer maintained. No replacement package was suggested.

PHP wrapper for Tutum API

0.2.0 2015-02-21 23:48 UTC

This package is not auto-updated.

Last update: 2024-01-20 12:26:48 UTC


README

A partial PHP wrapper of the Tutum API

About

This is a simple library for querying and discovering container links and managing services in Tutum However, it could be expanded to a full client in the future

Install

Add the following dependency to your composer.json:

{
    "require": {
        "chromabits/tutum-php": "dev-master"
    },
    "minimum-stability": "dev"
}

Usage within a container:

Example for getting all the links of a container:

require_once(__DIR__ . '/vendor/autoload.php');

use \Chromabits\TutumClient\ClientFactory;
use \Chromabits\TutumClient\Support\EnvUtils;

$client = (new ClientFactory())->makeFromEnvironment();
$env = new EnvUtils();

$response = $client->container->show($env->getContainerUuid());

$container = $response->get();

var_dump($container->findLinks('some-other-service'));

Deploying a service:

It is possible to programatically deploy services in Tutum using PHP:

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use Chromabits\TutumClient\Client;
use Chromabits\TutumClient\Requests\CreateServiceRequest;
use Chromabits\TutumClient\Entities\ContainerPort;

$client = new Client('someuser', 'vfjsblkdhbhkfhkajshkfj');

$nexusRequest = new CreateServiceRequest();

$nexusRequest->setName('nexus-staging');
$nexusRequest->setImage('eduard44/nexus:latest');
$nexusRequest->setTargetNumContainers(1);

$nexusRequest->addTag('staging');
$nexusRequest->addPort(new ContainerPort(80, ContainerPort::PROTO_TCP, 80, true));

$nexusRequest->setEnvironment('DB_DIALECT', 'mysql');
$nexusRequest->setEnvironment('DB_NAME', 'nexus');
$nexusRequest->setEnvironment('DB_USERNAME', 'nexus');
$nexusRequest->setEnvironment('DB_PASSWORD', 'suchSecretVarySafe');
$nexusRequest->setEnvironment('DB_HOST', 'some.host.hack');

$nexus = $client->service->create($nexusRequest)->get();

$client->service->start($nexus);

Other service actions are also supported:

$client->service->stop($nexus);

$client->service->redeploy($nexus);

$client->service->terminate($nexus);

Getting all services

The service->index() call lets you query current services on your Tutum account:

<?php

require_once(__DIR__ . '/vendor/autoload.php');

use Chromabits\TutumClient\Client;
use Chromabits\TutumClient\Entities\Service;

$client = new Client('someuser', 'vfjsblkdhbhkfhkajshkfj');

// Get all services
$response = $client->service->index();

// Get only services which have the state "Init"
$response = $client->service->index(Service::STATE_INIT);

// Get services by name
$response = $client->service->index(null, 'wordpress');