Skip to content

Instantly share code, notes, and snippets.

View jamiehannaford's full-sized avatar

Jamie Hannaford jamiehannaford

View GitHub Profile
@jamiehannaford
jamiehannaford / force_ipv4.php
Last active August 29, 2015 13:57
Force cURL to resolve IPv4
<?php
use OpenCloud\Rackspace;
use Guzzle\Log\MessageFormatter;
use Guzzle\Log\ClosureLogAdapter;
use Guzzle\Plugin\Log\LogPlugin;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
'apiKey' => 'bar',
@jamiehannaford
jamiehannaford / add_domain.php
Last active August 29, 2015 13:57
Adding new domain to DNS
<?php
require 'vendor/autoload.php';
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, [
'username' => 'foo',
'apiKey' => 'bar'
]);
@jamiehannaford
jamiehannaford / stream_videos.php
Created March 5, 2014 17:22
Return the URL for streaming videos
<?php
use OpenCloud\ObjectStore\Constants\UrlType;
// Will perform a HEAD operation, not a GET
$video = $container->getPartialObject($filename);
// Finds content-length from header, rather than entity body
if ($video->getContentLength()) {
@jamiehannaford
jamiehannaford / disable_ssl.php
Last active August 29, 2015 13:56
disables ssl verification
<?php
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
'apiKey' => 'bar',
'ssl.certificate_authority' => false
));
@jamiehannaford
jamiehannaford / create_volume.php
Last active August 29, 2015 13:56
Manually create a new Cinder volume
<?php
use Guzzle\Http\Exception\BadResponseException;
$url = clone $cinderService->getUrl();
$url->addPath('volumes');
$body = json_encode(array(
'size' => $vol_size,
'imageRef' => $img_id,
@jamiehannaford
jamiehannaford / add_db_to_user.php
Created February 11, 2014 12:02
Add a DB to a user
// First, retrieve the user
$user = $instance->user('<user_name>');
// Second, add the DB by name
$user->addDatabase('<db_name>');
// Third, update
$user->update();
@jamiehannaford
jamiehannaford / traverse_dbs.php
Created February 10, 2014 15:11
Traverse all the databases in a given instance
<?php
require 'vendor/autoload.php';
use OpenCloud\Rackspace;
$cloud = new OpenCloud\Rackspace(Rackspace::UK_IDENTITY_ENDPOINT, array(
'username' => 'tescloud',
'apiKey' => '___My___API___Key'
));
@jamiehannaford
jamiehannaford / http_debug.php
Last active August 29, 2015 13:56
debugging HTTP error
<?php
use Guzzle\Http\Exception\ClientErrorResponseException;
try {
// your code
} catch (ClientErrorResponseException $e) {
// Output HTTP request
echo $e->getRequest(), PHP_EOL;
@jamiehannaford
jamiehannaford / db_resize.php
Created February 4, 2014 09:36
check for db resize
use OpenCloud\Compute\Constants\ServerState;
$callback = function($server) {
if (!empty($server->error)) {
var_dump($server->error);
exit;
} else {
echo sprintf(
"Waiting on %s/%-12s %4s%%",
$server->name,
@jamiehannaford
jamiehannaford / resize_db_instance.php
Created January 31, 2014 13:31
resizes a DB instance
use OpenCloud\Rackspace;
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array(
'username' => 'foo',
'apiKey' => 'bar'
));
$service = $client->databaseService('cloudDatabases', 'DFW');
$instance = $service->instance('<instance_id>');