<?php // (c)2012 Rackspace Hosting // See COPYING for licensing information require_once "php-opencloud.php"; define('AUTHURL', RACKSPACE_US); define('USERNAME', $_ENV['OS_USERNAME']); define('TENANT', $_ENV['OS_TENANT_NAME']); define('APIKEY', $_ENV['NOVA_API_KEY']); // establish our credentials $connection = new \OpenCloud\Rackspace(AUTHURL, array('username' => USERNAME, 'apiKey' => APIKEY)); // now, connect to the compute service $compute = $connection->Compute('cloudServersOpenStack', 'DFW'); // display our limits print "Rate limits:\n"; $lim = $compute->Limits(); foreach ($lim->rate as $limit) { printf("Limit url=%s regex=%s:\n", isset($limit->url) ? $limit->url : 'N/A', $limit->regex); foreach ($limit->limit as $item) { printf("\tVerb: %s Unit: %s Remaining: %d Value: %d\n", $item->verb, $item->unit, $item->remaining, $item->value); $next = 'next-available'; printf("\tNext available: %s\n", $item->{$next}); } } /** * Now, we're going to try to hit the rate limits */ /* uncomment if you really want to do this print("Trying to hit the rate limits\n"); $serverlist = $compute->ServerList(); $server = $serverlist->Next(); // we just need one server
* numbers each step */ function step($msg, $p1 = NULL, $p2 = NULL, $p3 = NULL) { global $STEPCOUNTER; printf("\nStep %d. %s\n", ++$STEPCOUNTER, sprintf($msg, $p1, $p2, $p3)); } function info($msg, $p1 = NULL, $p2 = NULL, $p3 = NULL) { printf(" %s\n", sprintf($msg, $p1, $p2, $p3)); } define('TIMEFORMAT', 'r'); step('Authenticate'); $rackspace = new \OpenCloud\Rackspace(AUTHURL, array('username' => USERNAME, 'apiKey' => APIKEY)); step('Connect to Cloud Servers'); $cloudservers = $rackspace->Compute('cloudServersOpenStack', 'DFW'); step('Create a network SAMPLENET'); $samplenet = $cloudservers->Network(); $samplenet->Create(array('label' => 'SAMPLENET', 'cidr' => '192.168.0.0/24')); step('List Networks'); $netlist = $cloudservers->NetworkList(); $netlist->Sort('label'); while ($net = $netlist->Next()) { info('%s: %s (%s)', $net->id, $net->label, $net->cidr); } step('Create two servers on SAMPLENET'); $list = $cloudservers->ImageList(TRUE, array('name' => 'CentOS 6.3')); $image = $list->First(); $flavor = $cloudservers->Flavor(2); // 512MB $server1 = $cloudservers->Server();
<?php // (c)2012 Rackspace Hosting. See COPYING for license. require_once "php-opencloud.php"; define('AUTHURL', RACKSPACE_US); define('USERNAME', $_ENV['OS_USERNAME']); define('TENANT', $_ENV['OS_TENANT_NAME']); define('APIKEY', $_ENV['NOVA_API_KEY']); define('MYREGION', $_ENV['OS_REGION_NAME']); $rackspace = new \OpenCloud\Rackspace(AUTHURL, array('username' => USERNAME, 'apiKey' => APIKEY)); $cservers = $rackspace->Compute('cloudServersOpenStack', MYREGION); $list = $cservers->ServerList(); setDebug(TRUE); $flavor = $cservers->Flavor(4); setDebug(FALSE); while ($server = $list->Next()) { if ($server->name == 'MODEL') { printf("Resizing %s [%s]\n", $server->Name(), $server->Id()); $server->Resize($flavor); } }
<?php // (c)2012 Rackspace Hosting // See COPYING for licensing information require_once "php-opencloud.php"; define('INIFILE', 'auth.ini'); /** * Load the .INI file into an associative array. The second parameter causes it * to store the various [sections] of the .ini file. In our example, the * [Identity] section contains the auth secret info. */ $ini = parse_ini_file(INIFILE, TRUE); if (!$ini) { printf("Unable to load .ini file [%s]\n", INIFILE); exit; } // establish our credentials $RAX = new \OpenCloud\Rackspace($ini['Identity']['url'], $ini['Identity']); $RAX->SetDefaults('Compute', $ini['Compute']['serviceName'], $ini['Compute']['region'], $ini['Compute']['urltype']); $compute = $RAX->Compute(); $serverlist = $compute->ServerList(); while ($server = $serverlist->Next()) { print $server->name . "\n"; }
* another. The constant MYSERVERID identifies the server that we want * to clone from, and we'll create a new server in a different region * using the exact same parameters. */ // this is the ID of the server that we want to clone define('MYSERVERID', '9bfd203a-0695-410d-8202-66c4194c967b'); // auth credentials define('AUTHURL', RACKSPACE_US); define('USERNAME', $_ENV['OS_USERNAME']); define('TENANT', $_ENV['OS_TENANT_NAME']); define('APIKEY', $_ENV['NOVA_API_KEY']); printf("Authenticating...\n"); // establish our credentials $rackspace = new \OpenCloud\Rackspace(AUTHURL, array('username' => USERNAME, 'apiKey' => APIKEY)); // now, connect to the compute service in Dallas and Chicago $dallas = $rackspace->Compute(NULL, 'DFW'); $chicago = $rackspace->Compute(NULL, 'ORD'); printf("Retrieving the original server...\n"); $original = $dallas->Server(MYSERVERID); printf("Copying it to a new, Chicago-based server...\n"); $copy = $chicago->Server($original); printf("Creating the new server...\n"); $copy->Create(); printf("Waiting for it to finish...\n"); $copy->WaitFor('ACTIVE', 'dotter'); printf("All done\n"); exit; /** * callback for WaitFor function, above */ function dotter($server)
<?php // (c)2012 Rackspace Hosting // See COPYING for licensing information require_once "php-opencloud.php"; define('AUTHURL', RACKSPACE_US); define('USERNAME', $_ENV['OS_USERNAME']); define('TENANT', $_ENV['OS_TENANT_NAME']); define('APIKEY', $_ENV['NOVA_API_KEY']); define('REGION', $_ENV['OS_REGION_NAME']); // establish our credentials $cloud = new \OpenCloud\Rackspace(AUTHURL, array('username' => USERNAME, 'apiKey' => APIKEY)); // DNS service $dns = $cloud->DNS(); // uncomment for debug output //setDebug(TRUE); // compute service $compute = $cloud->Compute(NULL, REGION); $slist = $compute->ServerList(); while ($server = $slist->Next()) { printf("PTR records for Server [%s]:\n", $server->Name()); try { $ptrlist = $dns->PtrRecordList($server); while ($ptr = $ptrlist->Next()) { printf("- %s=%s\n", $ptr->data, $ptr->name); } } catch (\OpenCloud\CollectionError $e) { echo "- No records found\n"; } }