コード例 #1
0
ファイル: Catalog.php プロジェクト: karnajani/openstack
 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response)
 {
     $entries = Utils::jsonDecode($response)['access']['serviceCatalog'];
     foreach ($entries as $entry) {
         $this->entries[] = $this->model(Entry::class, $entry);
     }
 }
コード例 #2
0
ファイル: Image.php プロジェクト: kunalp/openstack
 private function getSchema()
 {
     if (null === $this->jsonSchema) {
         $response = $this->execute($this->api->getImageSchema());
         $this->jsonSchema = new Schema(Utils::jsonDecode($response, false));
     }
     return $this->jsonSchema;
 }
コード例 #3
0
 /**
  * Populates the current resource from a response object.
  *
  * @param ResponseInterface $response
  *
  * @return AbstractResource
  */
 public function populateFromResponse(ResponseInterface $response) : self
 {
     if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) {
         $json = Utils::jsonDecode($response);
         if (!empty($json)) {
             $this->populateFromArray(Utils::flattenJson($json, $this->resourceKey));
         }
     }
     return $this;
 }
コード例 #4
0
ファイル: OpenStack.php プロジェクト: php-opencloud/openstack
 /**
  * @param array $options
  *
  * @return Service
  */
 private function getDefaultIdentityService(array $options) : Service
 {
     if (!isset($options['authUrl'])) {
         throw new \InvalidArgumentException("'authUrl' is a required option");
     }
     $clientOptions = ['base_uri' => Utils::normalizeUrl($options['authUrl']), 'handler' => HandlerStack::create()];
     if (isset($options['requestOptions'])) {
         $clientOptions = array_merge($options['requestOptions'], $clientOptions);
     }
     return Service::factory(new Client($clientOptions));
 }
コード例 #5
0
ファイル: Network.php プロジェクト: alewitt/openstack
 /**
  * Creates multiple networks in a single request.
  *
  * @param array $data {@see \OpenStack\Networking\v2\Api::postNetworks}
  * @return Network[]
  */
 public function bulkCreate(array $data)
 {
     $response = $this->execute($this->api->postNetworks(), ['networks' => $data]);
     $networksData = Utils::jsonDecode($response)['networks'];
     $networks = [];
     foreach ($networksData as $resourceData) {
         $resource = $this->newInstance();
         $resource->populateFromArray($resourceData);
         $networks[] = $resource;
     }
     return $networks;
 }
コード例 #6
0
ファイル: Iterator.php プロジェクト: karnajani/openstack
 private function fetchResources()
 {
     if ($this->shouldNotSendAnotherRequest()) {
         return false;
     }
     $response = call_user_func($this->requestFn, $this->currentMarker);
     $json = Utils::flattenJson(Utils::jsonDecode($response), $this->resourcesKey);
     if ($response->getStatusCode() === 204 || empty($json)) {
         return false;
     }
     return $json;
 }
コード例 #7
0
ファイル: Object.php プロジェクト: alewitt/openstack
 /**
  * Retrieves the public URI for this resource.
  *
  * @return \GuzzleHttp\Psr7\Uri
  */
 public function getPublicUri()
 {
     //return $this->getHttpBaseUrl() . '/' . $this->containerName . '/' . $this->name;
     return Utils::addPaths($this->getHttpBaseUrl(), $this->containerName, $this->name);
 }
コード例 #8
0
ファイル: Volume.php プロジェクト: karnajani/openstack
 public function parseMetadata(ResponseInterface $response)
 {
     $json = Utils::jsonDecode($response);
     return isset($json['metadata']) ? $json['metadata'] : [];
 }
コード例 #9
0
ファイル: Server.php プロジェクト: php-opencloud/openstack
 public function parseMetadata(ResponseInterface $response) : array
 {
     return Utils::jsonDecode($response)['metadata'];
 }
コード例 #10
0
ファイル: AbstractResource.php プロジェクト: kunalp/openstack
 public function extractMultipleInstances(ResponseInterface $response, $key = null)
 {
     $key = $key ?: $this->getResourcesKey();
     $resourcesData = Utils::jsonDecode($response)[$key];
     $resources = [];
     foreach ($resourcesData as $resourceData) {
         $resource = $this->newInstance();
         $resource->populateFromArray($resourceData);
         $resources[] = $resource;
     }
     return $resources;
 }
コード例 #11
0
ファイル: Keypair.php プロジェクト: php-opencloud/openstack
 /**
  * {@inheritDoc}
  */
 public function populateFromArray(array $array) : self
 {
     return parent::populateFromArray(Utils::flattenJson($array, $this->resourceKey));
 }
コード例 #12
0
 /**
  * {@inheritDoc}
  */
 public function enumerate(array $def, array $userVals = [], callable $mapFn = null)
 {
     $operation = $this->getOperation($def);
     $markerKey = $this->markerKey ?: self::DEFAULT_MARKER_KEY;
     $supportsPagination = $operation->hasParam('marker');
     $limit = isset($userVals['limit']) ? $userVals : false;
     $count = 0;
     $totalReached = function ($count) use($limit) {
         return $limit && $count >= $limit;
     };
     while (true) {
         $response = $this->sendRequest($operation, $userVals);
         $json = Utils::jsonDecode($response);
         if (!$json) {
             break;
         }
         $json = Utils::flattenJson($json, $this->resourcesKey);
         if ($response->getStatusCode() === 204 || empty($json)) {
             break;
         }
         foreach ($json as $resourceData) {
             if ($totalReached($count)) {
                 break;
             }
             $count++;
             $resource = $this->newInstance();
             $resource->populateFromArray($resourceData);
             if ($mapFn) {
                 call_user_func_array($mapFn, [$resource]);
             }
             if ($supportsPagination) {
                 $userVals['marker'] = $resource->{$markerKey};
             }
             (yield $resource);
         }
         if ($totalReached($count) || !$supportsPagination) {
             break;
         }
     }
 }
コード例 #13
0
<?php

require 'vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use OpenStack\Identity\v2\Service;
use OpenStack\Common\Transport\Utils as TransportUtils;
use OpenStack\OpenStack;
$authUrl = 'https://example.com:5000/v2.0';
$httpClient = new Client(['base_uri' => TransportUtils::normalizeUrl($authUrl), 'handler' => HandlerStack::create()]);
$options = ['authUrl' => $authUrl, 'region' => 'RegionOne', 'username' => 'foo', 'password' => 'bar', 'tenantName' => 'baz', 'identityService' => Service::factory($httpClient)];
$openstack = new OpenStack($options);
コード例 #14
0
ファイル: Builder.php プロジェクト: php-opencloud/openstack
 private function httpClient(string $baseUrl, HandlerStack $stack) : ClientInterface
 {
     $clientOptions = ['base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack];
     if (isset($this->globalOptions['requestOptions'])) {
         $clientOptions = array_merge($this->globalOptions['requestOptions'], $clientOptions);
     }
     return new Client($clientOptions);
 }
コード例 #15
0
ファイル: Builder.php プロジェクト: karnajani/openstack
 private function httpClient($baseUrl, HandlerStack $stack)
 {
     return new Client(['base_uri' => Utils::normalizeUrl($baseUrl), 'handler' => $stack]);
 }
コード例 #16
0
ファイル: UtilsTest.php プロジェクト: kunalp/openstack
 public function test_it_adds_paths()
 {
     $uri = Utils::addPaths(uri_for('http://openstack.org/foo'), 'bar', 'baz', '1', '2');
     $this->assertInstanceOf(Uri::class, $uri);
     $this->assertEquals(uri_for('http://openstack.org/foo/bar/baz/1/2'), $uri);
 }
コード例 #17
0
ファイル: Server.php プロジェクト: karnajani/openstack
 /**
  * Retrieve the value for a specific metadata key.
  *
  * @param string $key {@see \OpenStack\Compute\v2\Api::getServerMetadataKey}
  *
  * @return mixed
  */
 public function getMetadataItem($key)
 {
     $response = $this->execute($this->api->getServerMetadataKey(), ['id' => $this->id, 'key' => $key]);
     return Utils::jsonDecode($response)['metadata'][$key];
 }
コード例 #18
0
ファイル: Utils.php プロジェクト: karnajani/openstack
 public static function getAuthOptsV2()
 {
     $httpClient = new Client(['base_uri' => CommonUtils::normalizeUrl(getenv('OS_AUTH_URL')), 'handler' => HandlerStack::create()]);
     return ['authUrl' => getenv('OS_AUTH_URL'), 'region' => getenv('OS_REGION_NAME'), 'username' => getenv('OS_USERNAME'), 'password' => getenv('OS_PASSWORD'), 'tenantName' => getenv('OS_TENANT_NAME'), 'identityService' => new Service($httpClient, new Api())];
 }
コード例 #19
0
ファイル: Token.php プロジェクト: karnajani/openstack
 /**
  * {@inheritDoc}
  */
 public function populateFromResponse(ResponseInterface $response)
 {
     $this->populateFromArray(Utils::jsonDecode($response)['access']['token']);
     return $this;
 }
コード例 #20
0
ファイル: Object.php プロジェクト: php-opencloud/openstack
 /**
  * Retrieves the public URI for this resource.
  *
  * @return \GuzzleHttp\Psr7\Uri
  */
 public function getPublicUri() : Uri
 {
     return Utils::addPaths($this->getHttpBaseUrl(), $this->containerName, $this->name);
 }