Giter Club home page Giter Club logo

cloudstack-php's Introduction

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.

cloudstack-php's People

Contributors

kevindierkx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.