Last active
August 29, 2015 14:01
-
-
Save jamiehannaford/f447818d4bc65093e30b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This is the new OpenStack name | |
$containerName = 'Keystone'; | |
// This is the previous OpenStack name | |
$objectName = 'Pillar'; | |
require 'vendor/autoload.php'; | |
use OpenCloud\Rackspace; | |
// Initialize client | |
$client = new Rackspace(Rackspace::US_IDENTITY_ENDPOINT, array( | |
'username' => 'rccc21', | |
'apiKey' => 'a952e2c3fb3745f2b1ecadd3f3dc55ae' | |
)); | |
$service = $client->objectStoreService('cloudFiles', 'DFW'); | |
// List and traverse over containers | |
$containers = $service->listContainers(); | |
foreach ($containers as $_container) { | |
if ($_container->getName() == $containerName) { | |
$container = $_container; | |
break; | |
} | |
} | |
if (!isset($container)) { | |
throw \Exception(sprintf("%s container not found!", $containerName)); | |
} | |
// List and iterate over objects | |
$files = $container->objectList(); | |
foreach ($files as $_file) { | |
if ($_file->getName() == $objectName . '.txt') { | |
$file = $_file; | |
break; | |
} | |
} | |
if (!isset($file)) { | |
throw \Exception(sprintf("%s object not found", $objectName)); | |
} | |
// Retrieve body | |
$file->refresh(); | |
// Cast Guzzle\Http\EntityBody object to string | |
echo $file->getContent(), PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment