Beispiel #1
0
/**
 * Sample code for creating back-ups of all servers, this is just proof-of-concept,
 * if you really need to back-up all of your servers you can create back-up
 * schedule using addBackupSchedule() method.
 *
 * @author Aleksey Korzun <*****@*****.**>
 * @link http://github.com/AlekseyKorzun/php-cloudservers/
 * @link http://www.schematic.com
 */
include '../Cloud/Exception.php';
// Provide your API ID (username) and API KEY (generated by Rackspace)
DEFINE('API_ID', '');
DEFINE('API_KEY', '');
try {
    // Initialize connection
    $cloud = new Cloud_Server(API_ID, API_KEY);
    // Retrieve all of available servers
    $servers = $cloud->getServers();
    // If list of servers was successfully retrieved we should now have an array
    // of servers that we can loop throught and create back-up images
    if (is_array($servers) && !empty($servers)) {
        foreach ($servers as $serverId => $server) {
            // Create back-up images
            if (!$cloud->createImage('Back up for: ' . $server['name'], $serverId)) {
                print 'Failed to back up server #: ' . $serverId;
            }
        }
    }
    // Get all of created back-up images
    print_r($cloud->getImages());
} catch (Cloud_Exception $e) {
Beispiel #2
0
<?php

/**
 * Sample code for creating a new server on Rackspace Cloud
 *
 * @author Aleksey Korzun <*****@*****.**>
 * @link http://github.com/AlekseyKorzun/php-cloudservers/
 * @link http://www.schematic.com
 */
include '../Cloud/Exception.php';
// Provide your API ID (username) and API KEY (generated by Rackspace)
DEFINE('API_ID', '');
DEFINE('API_KEY', '');
try {
    // Initialize connection
    $cloud = new Cloud_Server(API_ID, API_KEY);
    // Add custom MOTD file to our server
    $cloud->addServerFile('/etc/motd', 'This is a custom MOTD user(s) will see upon login');
    // Create a new server
    $server = $cloud->createServer('Server Name', 2, 1);
    // If server was successfully created we should now have an array
    // of server details that you can use to populate local database, etc
    if (is_array($server) && !empty($server)) {
        print_r($server);
    }
} catch (Cloud_Exception $e) {
    print $e->getMessage();
}