Skip to content

PHP package to to deploy and configure virtual servers on the PCextreme infrastructure

Notifications You must be signed in to change notification settings

sandwave-io/cloud-sdk-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PCextreme Cloud API - PHP SDK

Codecov GitHub Workflow Status Packagist PHP Version Support Packagist PHP Version Support Packagist Downloads

How to contribute

Feel free to create a PR if you have any ideas for improvements. Or create an issue.

  • When adding code, make sure to add tests for it (phpunit).
  • Make sure the code adheres to our coding standards (use php-cs-fixer to check/fix).
  • Also make sure PHPStan does not find any bugs.
vendor/bin/php-cs-fixer fix

vendor/bin/phpstan analyze

vendor/bin/phpunit --coverage-text

These tools will also run in GitHub actions on PR's and pushes on master.

Usage

use PCextreme\CloudSdkPhp\CloudSdk;

$cloudSdk = new CloudSdk('your-pcextreme-api-key', 'your-pcextreme-account-uuid');

$cloudSdk->listServers(); // list all servers under your account

Available methods

The endpoints that are currently implemented are not all existing endpoints. If you need an other endpoint to be implemented, create an issue or open a PR. 🙂

Deploy server

$cloudSdk->deployServer(
    'example.com',
    'SuperSecretPassword',
    'pcexterme-offer-uuid', // check the listOffers method to get this id.
    'pcexterme-template-uuid', // check the listTemplates method to get this id.
    'pcexterme-datacenter-uuid' // check the listDatacenters method to get this id.
);

This will return the ID of the created server:

[
    'id' => 'aaaa-bbbb-cccc-dddd-eeee'
]

List servers

$cloudSdk->listServers();

This will return an array having all servers attached to your account.

[
    [
        'id'                    => 'aaaa-bbbb-cccc-dddd-eeee',
        'display_name'          => 'display_name',
        'status'                => 'Running',
        'rescue_iso_attached'   => false,
        'has_security_group'    => true,
    
        'created_at'            => '2020-04-02T09:50:13+00:00',
        'updated_at'            => '2020-04-02T09:50:13+00:00',
    ],
];

Show server

You can also check out a specific server.

$cloudSdk->showServer('aaaa-bbbb-cccc-dddd-eeee');
[
    'id'                    => 'aaaa-bbbb-cccc-dddd-eeee',
    'display_name'          => 'display_name',
    'status'                => 'Running',
    'rescue_iso_attached'   => false,
    'has_security_group'    => true,

    'created_at'            => '2020-04-02T09:50:13+00:00',
    'updated_at'            => '2020-04-02T09:50:13+00:00',
];

Server details

You could use this call to fetch data from the underlying Cloudstack system.

$cloudSdk->showDetails('aaaa-bbbb-cccc-dddd-eeee');

Check out the cloudstack docs to see all the available information.

[
    "id"        => "aaaa-bbbb-cccc-dddd-eeee",
    "name"      => "aaaa-bbbb-cccc-dddd-eeee",
    "displayname" => "Name",
    "account" => "3",
    "userid" => "ad09ecc3-0356-4fva-ab42-d3dee2b08d82",
    "username" => "3",
    "domainid" => "6f243d98-7f2f-4276-9381-68e2a76f8b33",
    "domain" => "3",
    "created" => "2019-12-04T10:10:28+0100",
    "state" => "Running",
    "haenable" => false,
    "zoneid" => "10c85e3a-b499-4b73-a78d-f2f48ca2a3ba",
    "zonename" => "zone03.ams02.cldin.net",
    "templateid" => "50ea3730-6cf4-47c2-9663-387d16fa8c72",
    "templatename" => "Ubuntu 18.04.2",
    "templatedisplaytext" => "Ubuntu 18.04.2 20GB",
    "passwordenabled" => true,
    "serviceofferingid" => "53a3b7ab-8f9f-4ee1-b289-db70a29168aa",
    "serviceofferingname" => "pcx_standard_custom",
    "cpunumber" => 16,
    "cpuspeed" => 2000,
    "memory" => 65536,
    "cpuused" => "0.11%",
    "networkkbsread" => 898116,
    "networkkbswrite" => 40097,
    "diskkbsread" => 672,
    "diskkbswrite" => 4583328,
    "memorykbs" => 67108864,
    "memoryintfreekbs" => 67005920,
    "memorytargetkbs" => 67108864,
    "diskioread" => 168,
    "diskiowrite" => 346239,
    "guestosid" => "4ba6aae8-a4a1-11e9-814e-5254000588f7",
    "rootdeviceid" => 0,
    "rootdevicetype" => "ROOT",
    "securitygroup" => [
        [
            "id" => "a259a05b-8ea8-4fb0-97fb-9735261de5cb",
            "name" => "epic-vm","account" => "3",
            "ingressrule" => [],
            "egressrule" => [],
            "tags" => [],
            "virtualmachineids" => [],
        ],
    ],
    "nic" => [
        [
            "id" => "b707be76-7f82-44d0-b900-9fbdaba591bc",
            "networkid" => "a0234ec3-bdb6-46b8-80a1-37144d7c3928",
            "networkname" => "Guest Network 1",
            "netmask" => "255.255.255.0",
            "gateway" => "185.109.216.3",
            "ipaddress" => "185.109.216.118",
            "isolationuri" => "vxlan:\/\/500",
            "broadcasturi" => "vxlan:\/\/500",
            "traffictype" => "Guest",
            "type" => "Shared",
            "isdefault" => true,
            "macaddress" => "1e:00:1f:00:00:72",
            "ip6gateway" => "2a05:1500:600::1",
            "ip6cidr" => "2a05:1500:600::\/64",
            "ip6address" => "2a05:1500:600:0:1c00:1fff:fe00:72",
            "secondaryip" => [],
            "extradhcpoption" => [],
        ]
    ],
    "hypervisor" => "KVM",
    "details" => [
        "cpuNumber" => "16",
        "memory" => "65536",
        "cpuSpeed" => "2000",
        "memoryOvercommitRatio" => "1.0",
        "cpuOvercommitRatio" => "4.0",
        "rootdisksize" => "1280",
        "rootDiskController" => "scsi"
    ],
    "affinitygroup" => [],
    "isdynamicallyscalable" => true,
    "ostypeid" => "4ba6aae8-a4a1-11e9-814e-5254000588f7",
    "tags" => []
];

Upgrade server

In the case that you want to upgrade an existing server, you can use upgradeServer.

Note that the VM must be stopped when you run this.

$cloudSdk->upgradeServer(
    'aaaa-bbbb-cccc-dddd-eeee',
    'pcexterme-offer-uuid' // check the listOffers method to get this id.
);

Reset server

$cloudSdk->resetServer('aaaa-bbbb-cccc-dddd-eeee');

Detach rescue ISO server

Rescue ISO's can be used to salvage a broken server.

$cloudSdk->detachRescueIso('aaaa-bbbb-cccc-dddd-eeee');

Attach rescue ISO server

Rescue ISO's can be used to salvage a broken server.

$cloudSdk->detachRescueIso('aaaa-bbbb-cccc-dddd-eeee');

Edit display name server

$cloudSdk->updateServerHostname(
    'aaaa-bbbb-cccc-dddd-eeee',
    'hostname',
);

Reboot server

$cloudSdk->rebootServer('aaaa-bbbb-cccc-dddd-eeee');

Start server

$cloudSdk->startServer('aaaa-bbbb-cccc-dddd-eeee');

Stop server

$cloudSdk->stopServer('aaaa-bbbb-cccc-dddd-eeee');

Delete server

$cloudSdk->deleteServer('aaaa-bbbb-cccc-dddd-eeee');

Note: there is a grace period within Cloudstack. So the data will not be immediately lost.

Get current RAM usage for account

Accounts are limited on resources by default. You can retrieve your current resource usage using this method.

If you wish to broaden your limits, contact PCextreme.

$cloudSdk->getUsage();
[
    'ram' => 1 // in GB's
];

Get offers for account

Before you deploy or upgrade a server, you must retrieve the offer ID that you want to use.

$cloudSdk->listOffers();
[
    [
        'id'                 => 'aaaa-bbbb-cccc-dddd-eeee',
        'account_id'         => null, // Contains your account ID in the case of a custom offering.
        'billing_period'     => 12, // Billing period in months
        'price'              => 9990, // Price in cents.
        'type'               => 'usage',
        'sku'                => 'compute_standard_2gb',
        'name'               => 'server',
        'description'        => 'server',
        'show_in_store'      => 0,
        'specifications'     => [
            // Filled with specifications depending on the offering.
        ],
    
        'created_at'         => '2020-04-02T09:50:13+00:00',
        'updated_at'         => '2020-04-02T09:50:13+00:00',
    ]
];

Get datacenters for account

For a deployment, you also need to know what datacenter to deploy in.

$cloudSdk->listDatacenters();

The response also contains the availability of standard and HA VM's. These are two different types of storage, the difference between the two VM's can also be identified based on the offer data.

[
    [
        'id'            => 'aaaa-bbbb-cccc-dddd-eeee',
        'name'          => 'ams01',
        'description'   => 'Amsterdam',
        'city'          => 'ams',
        'country'       => 'nl',
        'timezone'      => 'Europe/Amsterdam',
        'standard_enabled'  => true,
        'ha_enabled'        => true
    ]
];

Get templates for account

The templates used for VM deployments are predefined and can be seen using listTemplates.

$cloudSdk->listTemplates();
[
    [
        'id'            => 'aaaa-bbbb-cccc-dddd-eeee',
        'display_name'  => 'Fedora 30',
        'os'            => 'fedora',
        'version'       => 30,
        'created_at'    => '2020-04-02T09:50:13+00:00',
        'updated_at'    => '2020-04-02T09:50:13+00:00'
    ]
];

Get private networks for account

The templates used for VM deployments are predefined and can be seen using listTemplates.

$cloudSdk->listNetworks();
[
    [
        "id" => "d11c06f5-ff1c-41cd-8fc9-1ebcb3084501",
        "display_name" => "An example (No SG)",
        "datacenter_id" => "36616598-8e93-4118-a03c-94f99e5e1169",
        "manager" => "man.zone03.ams02.cldin.net",
        "cidr_ipv4" => "185.109.217.64/26",
        "cidr_ipv6" => "2a05:1500:600:4::/64",
        "created_at" => "2019-09-09T08:58:05+00:00",
        "updated_at" => "2019-09-09T08:58:05+00:00"
    ]
];

Get console url for current sever

If you wish to open a browser based console, you can use this method to generate a URL.

$cloudSdk->getConsoleUrl();
[
    'url' => 'www.test.nl'
];

About

PHP package to to deploy and configure virtual servers on the PCextreme infrastructure

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages