Beispiel #1
0
 /**
  * Gets the singleton SoapClient which is used to connect to the TransIP Api.
  *
  * @param  mixed       $parameters  Parameters.
  * @return SoapClient               The SoapClient object to which we can connect to the TransIP API
  */
 public static function _getSoapClient($parameters = array())
 {
     $endpoint = Transip_ApiSettings::$endpoint;
     if (self::$_soapClient === null) {
         $extensions = get_loaded_extensions();
         $errors = array();
         if (!class_exists('SoapClient') || !in_array('soap', $extensions)) {
             $errors[] = 'The PHP SOAP extension doesn\'t seem to be installed. You need to install the PHP SOAP extension. (See: http://www.php.net/manual/en/book.soap.php)';
         }
         if (!in_array('openssl', $extensions)) {
             $errors[] = 'The PHP OpenSSL extension doesn\'t seem to be installed. You need to install PHP with the OpenSSL extension. (See: http://www.php.net/manual/en/book.openssl.php)';
         }
         if (!empty($errors)) {
             die('<p>' . implode("</p>\n<p>", $errors) . '</p>');
         }
         $classMap = array('Product' => 'Transip_Product', 'PrivateNetwork' => 'Transip_PrivateNetwork', 'Vps' => 'Transip_Vps', 'Snapshot' => 'Transip_Snapshot', 'OperatingSystem' => 'Transip_OperatingSystem');
         $options = array('classmap' => $classMap, 'encoding' => 'utf-8', 'features' => SOAP_SINGLE_ELEMENT_ARRAYS, 'trace' => false);
         $wsdlUri = "https://{$endpoint}/wsdl/?service=" . self::SERVICE;
         try {
             self::$_soapClient = new SoapClient($wsdlUri, $options);
         } catch (SoapFault $sf) {
             throw new Exception("Unable to connect to endpoint '{$endpoint}'");
         }
         self::$_soapClient->__setCookie('login', Transip_ApiSettings::$login);
         self::$_soapClient->__setCookie('mode', Transip_ApiSettings::$mode);
     }
     $timestamp = time();
     $nonce = uniqid('', true);
     self::$_soapClient->__setCookie('timestamp', $timestamp);
     self::$_soapClient->__setCookie('nonce', $nonce);
     self::$_soapClient->__setCookie('clientVersion', self::API_VERSION);
     self::$_soapClient->__setCookie('signature', self::_urlencode(self::_sign(array_merge($parameters, array('__service' => self::SERVICE, '__hostname' => $endpoint, '__timestamp' => $timestamp, '__nonce' => $nonce)))));
     return self::$_soapClient;
 }
<?php

/**
 * This example removes a VPS from a Private Network
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Remove the VPS from a private Network
    Transip_VpsService::removeVpsFromPrivateNetwork('vps-name', 'private-network-name');
    echo 'Removing VPS from Private Network';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example adds VPS to a private network
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // add the VPS to private network
    Transip_VpsService::addVpsToPrivateNetwork('vps-name', 'private-network-name');
    echo 'added Vps to private network';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example cancels a VPS
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // cancel VPS
    // end-time is either: 'immediately' or 'end' (end means end of contract)
    Transip_VpsService::cancelVps('vps-name', 'immediately');
    echo 'Cancelled Vps';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example reset a vps.
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Reset a vps
    Transip_VpsService::reset('vps-name');
    echo 'The vps has been resetted.';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example stops a vps.
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Stop a vps
    Transip_VpsService::stop('vps-name');
    echo 'The vps has been stopped.';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example orders a Vps,
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    $productName = 'vps-bladevps-x1';
    $addons = array();
    $operatingSystemName = 'freebsd-10.2';
    $hostname = '';
    Transip_VpsService::orderVps($productName, $addons, $operatingSystemName, $hostname);
    echo 'Ordered VPS';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example adds a ipv6 Address to a VPS from the assigned ipv6 range
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // add ipv6 to specific VPS (Ipv6 has to be in you Ipv6 Range)
    Transip_VpsService::addIpv6ToVps('vps-name', 'ipv6-address');
    echo 'added ipv6 to Vps';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example reverts a snapshot to a given vps
 *
 * @copyright Copyright 2016 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Revert snapshot taken from vps-name to destination-vps-name
    Transip_VpsService::revertSnapshotToOtherVps('vps-name', 'snapshot-name', 'destination-vps-name');
    echo 'Reverting snapshot from vps-name';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example updates a Ptr Record for a IP address
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Update the PTR Record for a IP
    Transip_VpsService::updatePtrRecord('ip-address', 'ptr-string');
    echo 'ptr string updated';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example reverts a snapshot for a given vps
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Revert snapshot for vps
    Transip_VpsService::revertSnapshot('vps-name', 'snapshot-name');
    echo 'Reverting snapshot';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example starts a vps.
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Start a vps
    Transip_VpsService::start('vps-name');
    echo 'The vps has been started.';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all Vps objects
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of all Vps objects
    $vpsList = Transip_VpsService::getVpses();
    print_r($vpsList);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns all traffic information for the current contract period per VPS
 *
 * @copyright Copyright 2014 TransIP BV
 * @author    TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get all the traffic information for the current contract period by vps name
    /**
     * Returns Array with the following Elements:
     *
     * 'startDate'
     * 'endDate'
     * 'usedInBytes'
     * 'usedTotalBytes'
     * 'maxBytes'
     */
    $trafficInformation = Transip_VpsService::getTrafficInformationForVps('vps-name');
    print_r($trafficInformation);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example orders a Addon for a Vps,
 * Be aware that ordering a Addon will automatically trigger a restart of the VPS
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // order the addon for specific VPS, use array
    $addon = array('addon-name');
    Transip_VpsService::orderAddon('vps-name', $addon);
    echo 'Ordered addon';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example clones a vps.
 *
 * @copyright Copyright 2016 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // clone this VPS to a new VPS with the same specs
    Transip_VpsService::cloneVps('vps-name');
    echo 'The vps clone has been started.';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a Vps object
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a vps by name
    $vps = Transip_VpsService::getVps('vpsName');
    print_r($vps);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example will enable and disable the CustomerLock for a Vps
 *
 * @copyright Copyright 2014 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // enable customer lock
    Transip_VpsService::setCustomerLock('vps-name', true);
    echo 'vps is customer locked';
    // disable customer lock
    Transip_VpsService::setCustomerLock('vps-name', false);
    echo 'vps is unlocked';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all possible upgrades for a specific VPS
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of the possible upgrades for a specific VPS
    $upgrades = Transip_VpsService::getAvailableUpgrades('vps-name');
    print_r($upgrades);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of the active addons of a specific Vps
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of all the available addons for specific Vps
    $addons = Transip_VpsService::getActiveAddonsForVps('vps-name');
    print_r($addons);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all the ips that are tight to the given Vps
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of Ip objects
    $ips = Transip_VpsService::getIpsForVps('vps-name');
    print_r($ips);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all snapshots for a vps
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of all snapshots for a vps
    $snapshotList = Transip_VpsService::getSnapshotsByVps('vps-name');
    print_r($snapshotList);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all the private networks that are attached to the given Vps
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of private network objects
    $privateNetworks = Transip_VpsService::getPrivateNetworksByVps('vps-name');
    print_r($privateNetworks);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example creates a snapshot for a given vps
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Create snapshot for vps
    Transip_VpsService::createSnapshot('vps-name', 'snapshot-description');
    echo 'Starting snapshot';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all ip's
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of all the Ips
    $allIps = Transip_VpsService::getAllIps();
    print_r($allIps);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of all private networks that are configured in your account
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of all PrivateNetwork objects in your account
    $privateNetworks = Transip_VpsService::getAllPrivateNetworks();
    print_r($privateNetworks);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example returns a list of the available VPS Products
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get a list of all the products
    $products = Transip_VpsService::getAvailableProducts();
    print_r($products);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example cancels a addon,
 * Be aware that cancelling a addon will automatically trigger a restart of the VPS
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // cancel the addon for specific VPS
    Transip_VpsService::cancelAddon('vps-name', 'addon-name');
    echo 'Cancelled addon';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example installs a operating on Vps
 * Note: if the operating system requires a licence, it will be billed automatically
 *
 * @copyright Copyright 2013 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // hostname is only used when installing a "preinstalled image" like plesk, directadmin or cpanel
    Transip_VpsService::installOperatingSystem('vps-name', 'operating-system-name', 'hostname');
    echo 'Operating system install in progress';
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}
<?php

/**
 * This example will get a list for all available backups for a specific vps
 *
 * @copyright Copyright 2016 TransIP BV
 * @author TransIP BV <*****@*****.**>
 */
// Include vpsservice
require_once 'Transip/VpsService.php';
try {
    // Get backups
    $backupList = Transip_VpsService::getVpsBackupsByVps('vps-name');
    print_r($backupList);
} catch (SoapFault $f) {
    // It is possible that an error occurs when connecting to the TransIP Soap API,
    // those errors will be thrown as a SoapFault exception.
    echo 'An error occurred: ' . $f->getMessage(), PHP_EOL;
}