Created
May 26, 2014 04:57
-
-
Save lorenzoaiello/66d028316d9eb1f3c0ed to your computer and use it in GitHub Desktop.
Requires Softlayer ObjectStorage Client (https://github.com/softlayer/softlayer-object-storage-php)
This file contains hidden or 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 | |
/** | |
USAGE | |
php file.php containers list | |
php file.php containers create CONTAINERNAME | |
php file.php containers delete CONTAINERNAME | |
php file.php cdn enable CONTAINERNAME | |
php file.php cdn disable CONTAINERNAME | |
php file.php cdn addurl CONTAINERNAME CNAMEURL | |
php file.php cdn removeurl CONTAINERNAME CNAMEURL | |
php file.php cdn list CONTAINERNAME | |
*/ | |
error_reporting(0); | |
require 'ObjectStorage.php'; | |
require 'ObjectStorage/Util.php'; | |
$options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10); | |
$host = 'https://DCENDPOINT.objectstorage.softlayer.net'; | |
$username = 'SL1234-0:1234'; | |
$password = 'yourapikeyhere'; | |
$objectStorage = new ObjectStorage($host, $username, $password, $options); | |
switch($argv[1]) | |
{ | |
case 'containers': | |
container($objectStorage,$argv); | |
break; | |
case 'cdn': | |
cdn($objectStorage,$argv); | |
break; | |
} | |
function container($objectStorage,$argv) | |
{ | |
switch($argv[2]) | |
{ | |
case 'list': | |
echo "Softlayer Containers\n---------------------\n"; | |
foreach($objectStorage->with()->get()->containers as $container) | |
{ | |
echo $container->getPath()."\n"; | |
} | |
break; | |
case 'create': | |
if($argv[3] != '') | |
{ | |
$objectStorage->with($argv[3])->create(); | |
echo "Container ".$argv[3]." Created\n"; | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
case 'delete': | |
if($argv[3] != '') | |
{ | |
$objectStorage->with($argv[3])->delete(); | |
echo "Container ".$argv[3]." Delete\n"; | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
} | |
} | |
function cdn($objectStorage,$argv) | |
{ | |
switch($argv[2]) | |
{ | |
case 'enable': | |
if($argv[3] != '') | |
{ | |
$objectStorage->with($argv[3])->enableCdn(); | |
echo "CDN for Container ".$argv[3]." Enabled\n"; | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
case 'disable': | |
if($argv[3] != '') | |
{ | |
$objectStorage->with($argv[3])->disableCdn(); | |
echo "CDN for Container ".$argv[3]." Disabled\n"; | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
case 'addurl': | |
if($argv[3] != '') | |
{ | |
$objectStorage->with($argv[3])->setContext('cdn')->setHeader('X-CDN-CNAME-Action','add')->setHeader('X-Cdn-CNAME',$argv[4]); | |
echo "CDN for Container ".$argv[3]." Enabled\n"; | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
case 'removeurl': | |
if($argv[3] != '') | |
{ | |
$objectStorage->with($argv[3])->setContext('cdn')->setHeader('X-CDN-CNAME-Action','delete')->setHeader('X-Cdn-CNAME',$argv[4]); | |
echo "CDN for Container ".$argv[3]." Enabled\n"; | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
case 'list': | |
if($argv[3] != '') | |
{ | |
echo "CDN URLs for ".$argv[3]."\n---------------------\n"; | |
foreach($objectStorage->with($argv[3])->get()->getCdnUrls() as $url) | |
{ | |
print_r($url); | |
//echo $url->getPath()."\n"; | |
} | |
}else{ | |
echo "Missing Container Name\n"; | |
} | |
break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment