Skip to content

lesleydesmet/cloudstack-php

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

github-readme_header

PHP Cloudstack Client

Latest Version Software License Build Status Scrutinizer Coverage Status

This package makes it simple to integrate Cloudstack in your PHP applications.

Requirements

The following versions of PHP are supported.

  • PHP 5.5
  • PHP 5.6
  • PHP 7.0
  • HHVM

Installation

You can use composer require to add the client to your composer.json file.

$ composer require pcextreme/cloudstack

Or modify your composer.json and add the client to your require block followed by running composer update.

"require": {
    "pcextreme/cloudstack": "~0.2"
}

Usage

There are various ways to interact with the Cloudstack API using this package. The easiest and preferred way is to call the Cloudstack 'commands' directly as a method on the client.

Internally the client resolves the command using the __call magic method. The command will be automatically resolved and the provided options are verified. Also when everything goes as expected the API response is automatically parsed.

The client uses an API list mapping stored in the cache folder do determine if an API command exists and all required parameters are provided. This list is generated using Cloudstack's listApis command.

<?php

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

use PCextreme\Cloudstack\Client;

$client = new Client([
    'urlApi'    => 'https://api.auroracompute.eu/ams',
    'apiKey'    => 'YOUR-API-KEY',
    'secretKey' => 'YOUR-SECRET-KEY',
]);

var_dump($client->listAccounts(['name' => 'admin', 'listall' => 'true']));

Directly calling the command method

Its also possible to bypass the __call magic method and call the command method directly.

$client->command('listAccounts', ['name' => 'admin', 'listall' => 'true']);

Manually accessing the API

If for some reason the cache/api_list.php is removed, outdated or gets corrupted you can access the API directly by building a request manually. This bypasses all previously mentioned checks but still parses the response.

$command = 'listAccounts';
$options = ['name' => 'admin', 'listall' => 'true'];

$method  = $client->getCommandMethod($command);
$url     = $client->getCommandUrl($command, $options);
$request = $client->getRequest($method, $url, $options);

$accounts = $client->getResponse($request);

Updating the API list

You can update or regenerate the provided API list using the bin/cloudstack CLI.

$ php bin/cloudstack api:list

You can also get a list of available CLI commands.

$ php bin/cloudstack

Credits

License

The MIT License (MIT). Please see License File for more information.

About

Native PHP Cloudstack client

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%