-
-
Save solocommand/9978806 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 | |
require 'vendor/autoload.php'; | |
use OpenCloud\OpenStack; | |
use OpenCloud\Common\Service\CatalogService; | |
use OpenCloud\Common\Service\Endpoint; | |
use OpenCloud\Common\Exceptions; | |
use Guzzle\Http\ClientInterface; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
// Rackspace | |
//test('RAX', 'https://identity.api.rackspacecloud.com/v2.0', 'username', 'password'); | |
// HPCloud | |
test('HP', 'https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/', 'username', 'password'); | |
class HpService extends CatalogService | |
{ | |
public function __construct(ClientInterface $client, $type = null, $region = null, $urlType = null) | |
{ | |
$this->setClient($client); | |
$this->region = $region; | |
$this->type = $type; | |
$this->urlType = $urlType; | |
$this->setEndpoint($this->findHpEndpoint()); | |
$this->client->setBaseUrl($this->getBaseUrl()); | |
if ($this instanceof EventSubscriberInterface) { | |
$this->client->getEventDispatcher()->addSubscriber($this); | |
} | |
} | |
protected function findHpEndpoint() | |
{ | |
if (!$this->getClient()->getCatalog()) { | |
$this->getClient()->authenticate(); | |
} | |
$catalog = $this->getClient()->getCatalog(); | |
foreach ($catalog->getItems() as $service) { | |
if ($service->hasType($this->type)) { | |
return Endpoint::factory($service->getEndpointFromRegion($this->region)); | |
} | |
} | |
throw new Exceptions\EndpointError(sprintf( | |
'No endpoints for service type [%s], name [%s], region [%s] and urlType [%s]', | |
$this->type, | |
$this->name, | |
$this->region, | |
$this->urlType | |
)); | |
} | |
} | |
function test($cloud, $identity_url, $username, $password) | |
{ | |
try { | |
echo "OpenStack TEST<br>"; | |
$client = new OpenStack($identity_url, array('username' => $username, 'password' => $password)); | |
if ($cloud == 'RAX') { | |
$compute = $client->computeService("cloudServersOpenStack", "DFW"); | |
} else if ($cloud == 'HP') { | |
$compute = new HpService($client, 'Compute', 'US West', 'publicURL'); | |
} | |
var_dump($compute); | |
} catch (Exception $e) { | |
print "Error!: " . $e->getMessage() . "<br/>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment