/** * Test the validity of an existing resource. * * @access public * @param bool $debug (default: false) * @return void */ public function test($debug = false) { $json = json_encode($this->updateJson()); $this->checkJsonError(); $response = $this->getClient()->post($this->testExistingUrl($debug), array(), $json)->send(); return Formatter::decode($response); }
/** * Returns metadata properties associated with this Resource * * @return \stdClass */ public function getMetadata() { $url = clone $this->getUrl(); $url->addPath('metadata'); $response = $this->getClient()->get($url)->send(); $json = Formatter::decode($response); return $json->metadata; }
public function getSingleHistoryItem($checkId, $historyId) { $url = $this->url($checkId . '/' . $historyId); $response = $this->getClient()->get($url)->send(); if (null !== ($decoded = Formatter::decode($response))) { $this->populate($decoded); } return false; }
/** * @param $connectionId * @return mixed * @throws \OpenCloud\CloudMonitoring\Exception\AgentException */ public function getConnection($connectionId) { if (!$this->getId()) { throw new Exception\AgentException('Please specify an "ID" value'); } $url = clone $this->getUrl(); $url->addPath('connections')->addPath($connectionId); $response = $this->getClient()->get($url)->send(); $body = Formatter::decode($response); return $this->getService()->resource('AgentConnection', $body); }
/** * DNS PTR Delete() method requires a server * * Note that delete will remove ALL PTR records associated with the device * unless you pass in the parameter ip={ip address} * */ public function delete() { $this->link_rel = $this->server->getService()->Name(); $this->link_href = $this->server->Url(); $params = array('href' => $this->link_href); if (!empty($this->data)) { $params['ip'] = $this->data; } $url = clone $this->getUrl(); $url->addPath('rdns')->addPath($this->link_rel)->setQuery($params); $response = $this->getClient()->delete($url)->send(); return new AsyncResponse($this->getService(), Formatter::decode($response)); }
public function traceroute(array $options) { if (!$this->getId()) { throw new Exception\ZoneException('Please specify a zone ID'); } if (!isset($options['target']) || !isset($options['target_resolver'])) { throw new Exception\ZoneException('Please specify a "target" and "target_resolver" value'); } $params = (object) array('target' => $options['target'], 'target_resolver' => $options['target_resolver']); try { $response = $this->getService()->getClient()->post($this->url('traceroute'), array(), json_encode($params))->send(); $body = Formatter::decode($response); return isset($body->result) ? $body->result : false; } catch (ClientErrorResponseException $e) { return false; } }
/** * Contructs a Metadata object associated with a Server or Image object * * @param object $parent either a Server or an Image object * @param string $key the (optional) key for the metadata item * @throws MetadataError */ public function __construct(Server $parent, $key = null) { // construct defaults $this->setParent($parent); // set the URL according to whether or not we have a key if ($this->getParent()->getId()) { $this->url = $this->getParent()->url('metadata'); $this->key = $key; // in either case, retrieve the data $response = $this->getParent()->getClient()->get($this->getUrl())->send(); // parse and assign the server metadata $body = Formatter::decode($response); if (isset($body->metadata)) { foreach ($body->metadata as $key => $value) { $this->{$key} = $value; } } } }
/** * Authenticate the tenant using the supplied credentials * * @return void * @throws AuthenticationError */ public function authenticate() { $identity = IdentityService::factory($this); $response = $identity->generateToken($this->getCredentials()); $body = Formatter::decode($response); $this->setCatalog($body->access->serviceCatalog); $this->setTokenObject($identity->resource('Token', $body->access->token)); $this->setUser($identity->resource('User', $body->access->user)); if (isset($body->access->token->tenant)) { $this->setTenantObject($identity->resource('Tenant', $body->access->token->tenant)); } // Set X-Auth-Token HTTP request header $this->updateTokenHeader(); }
/** * returns an array of limit types * * @return array */ public function limitTypes() { $response = $this->getClient()->get($this->getUrl('limits/types'))->send(); $body = Formatter::decode($response); return $body->limitTypes; }
/** * Returns the home document for the CDN service * * @return \stdClass home document response */ public function getHomeDocument() { $url = clone $this->getUrl(); // This hack is necessary otherwise Guzzle will remove the trailing // slash from the URL and the request will fail because the service // expects the trailing slash :( $url->setPath($url->getPath() . '/'); $response = $this->getClient()->get($url)->send(); return Formatter::decode($response); }
/** * Parse a HTTP response for the required content * * @param Response $response * @return mixed */ public function parseResponse(Response $response) { $document = Formatter::decode($response); $topLevelKey = $this->jsonName(); return $topLevelKey && isset($document->{$topLevelKey}) ? $document->{$topLevelKey} : $document; }
/** * Returns the endpoint URL with a version in it * * @param string $url Endpoint URL * @param string $supportedServiceVersion Service version supported by the SDK * @param OpenCloud\OpenStack $client OpenStack client * @return Guzzle/Http/Url Endpoint URL with version in it */ private function getVersionedUrl($url, $supportedServiceVersion, OpenStack $client) { $versionRegex = '/\\/[vV][0-9][0-9\\.]*/'; if (1 === preg_match($versionRegex, $url)) { // URL has version in it; use it as-is return Url::factory($url); } // If there is no version in $url but no $supportedServiceVersion // is specified, just return $url as-is but log a warning if (is_null($supportedServiceVersion)) { $client->getLogger()->warning('Service version supported by SDK not specified. Using versionless service URL as-is, without negotiating version.'); return Url::factory($url); } // Make GET request to URL $response = Formatter::decode($client->get($url)->send()); // Attempt to parse response and determine URL for given $version if (!isset($response->versions) || !is_array($response->versions)) { throw new UnsupportedVersionError('Could not negotiate version with service.'); } foreach ($response->versions as $version) { if (($version->status == 'CURRENT' || $version->status == 'SUPPORTED') && $version->id == $supportedServiceVersion) { foreach ($version->links as $link) { if ($link->rel == 'self') { return Url::factory($link->href); } } } } // If we've reached this point, we could not find a versioned // URL in the response; throw an error throw new UnsupportedVersionError(sprintf('SDK supports version %s which is not currently provided by service.', $supportedServiceVersion)); }
public function getRecordedChecks() { $response = $this->getService()->getClient()->get($this->getHistoryUrl())->send(); $body = Formatter::decode($response); return isset($body->check_ids) ? $body->check_ids : false; }
/** * returns changes since a specified date/time * * @param string $since the date or time * @return DNS\Changes */ public function changes($since = null) { $url = clone $this->getUrl(); $url->addPath('changes'); if ($since) { $url->setQuery(array('since' => $since)); } $response = $this->getService()->getClient()->get($url)->send(); return Formatter::decode($response); }
/** * Retrieve a new page of elements from the API (based on a new request), parse its response, and append them to the * collection. * * @return $this|bool */ public function appendNewCollection() { $request = $this->resourceParent->getClient()->createRequest($this->getOption('request.method'), $this->constructNextUrl(), $this->getOption('request.headers'), $this->getOption('request.body'), $this->getOption('request.curlOptions')); try { $response = $request->send(); } catch (ClientErrorResponseException $e) { return false; } if (!($body = Formatter::decode($response)) || $response->getStatusCode() == 204) { return false; } $this->nextUrl = $this->extractNextLink($body); return $this->appendElements($this->parseResponseBody($body)); }
/** * Get server diagnostics * * Gets basic usage data for a specified server. * * @api * @return object */ public function diagnostics() { // The diagnostics is only available when the os-server-diagnostics extension is installed. $this->checkExtension('os-server-diagnostics'); $url = $this->getUrl('diagnostics'); $response = $this->getClient()->get($url)->send(); $body = Formatter::decode($response); return $body ?: (object) array(); }
/** * This operation claims a set of messages, up to limit, from oldest to * newest, skipping any that are already claimed. If no unclaimed messages * are available, FALSE is returned. * * You should delete the message when you have finished processing it, * before the claim expires, to ensure the message is processed only once. * Be aware that you must call the delete() method on the Message object and * pass in the Claim ID, rather than relying on the service's bulk delete * deleteMessages() method. This is so that the server can return an error * if the claim just expired, giving you a chance to roll back your processing * of the given message, since another worker will likely claim the message * and process it. * * Just as with a message's age, the age given for the claim is relative to * the server's clock, and is useful for determining how quickly messages are * getting processed, and whether a given message's claim is about to expire. * * When a claim expires, it is removed, allowing another client worker to * claim the message in the case that the original worker fails to process it. * * @param int $limit */ public function claimMessages(array $options = array()) { $limit = isset($options['limit']) ? $options['limit'] : Claim::LIMIT_DEFAULT; $grace = isset($options['grace']) ? $options['grace'] : Claim::GRACE_DEFAULT; $ttl = isset($options['ttl']) ? $options['ttl'] : Claim::TTL_DEFAULT; $json = json_encode((object) array('grace' => $grace, 'ttl' => $ttl)); $url = $this->getUrl('claims', array('limit' => $limit)); $response = $this->getClient()->post($url, self::getJsonHeader(), $json)->send(); if ($response->getStatusCode() == 204) { return false; } $options = array('resourceClass' => 'Message', 'baseUrl' => $url); return PaginatedIterator::factory($this, $options, Formatter::decode($response)); }
/** * List over all the tenants for this cloud account. * * @return \OpenCloud\Common\Collection\ResourceIterator */ public function getTenants() { $url = $this->getUrl(); $url->addPath('tenants'); $response = $this->getClient()->get($url)->send(); if ($body = Formatter::decode($response)) { return ResourceIterator::factory($this, array('resourceClass' => 'Tenant', 'key.collection' => 'tenants'), $body->tenants); } }
public function parseResponse(Response $response) { $body = Formatter::decode($response); $top = $this->jsonName(); if ($top && isset($body->{$top})) { $content = $body->{$top}; } else { $content = $body; } return $content; }
public function getAsyncJob($jobId, $showDetails = true) { $url = clone $this->getUrl(); $url->addPath('status'); $url->addPath((string) $jobId); $url->setQuery(array('showDetails' => $showDetails ? 'true' : 'false')); $response = $this->getClient()->get($url)->send(); return new AsyncResponse($this, Formatter::decode($response)); }
/** * Internal method for dispatching single batch delete requests. * * @param array $paths * @return \Guzzle\Http\Message\Response * @throws Exception\BulkOperationException */ private function executeBatchDeleteRequest(array $paths) { $entity = EntityBody::factory(implode(PHP_EOL, $paths)); $url = $this->getUrl()->setQuery(array('bulk-delete' => true)); $response = $this->getClient()->delete($url, array(Header::CONTENT_TYPE => Mime::TEXT), $entity)->send(); try { $body = Formatter::decode($response); if (!empty($body->Errors)) { throw new Exception\BulkOperationException((array) $body->Errors); } } catch (Exceptions\JsonError $e) { } return $response; }
/** * Returns TRUE if the root user is enabled * * @api * @return boolean TRUE if the root user is enabled; FALSE otherwise * @throws InstanceError if HTTP status is not Success */ public function isRootEnabled() { $response = $this->getClient()->get($this->url('root'))->send(); $body = Formatter::decode($response); return !empty($body->rootEnabled); }
public function test($debug = false) { $response = $this->getService()->getClient()->post($this->testUrl($debug))->send(); return Formatter::decode($response); }
/** * Constructs a specified URL from the subresource * * Given a subresource (e.g., "extensions"), this constructs the proper * URL and retrieves the resource. * * @param string $resource The resource requested; should NOT have slashes * at the beginning or end * @return \stdClass object */ private function getMetaUrl($resource) { $url = clone $this->getBaseUrl(); $url->addPath($resource); try { $response = $this->getClient()->get($url)->send(); return Formatter::decode($response); } catch (BadResponseException $e) { // @codeCoverageIgnoreStart return array(); // @codeCoverageIgnoreEnd } }
/** * Reset the API key for this user to a new arbitrary value (which is returned). * * @return string|null */ public function resetApiKey() { $url = $this->getUrl(); $url->addPath('OS-KSADM')->addPath('credentials')->addPath('RAX-KSKEY:apiKeyCredentials')->addPath('RAX-AUTH')->addPath('reset'); $response = $this->getClient()->post($url)->send(); if ($body = Formatter::decode($response)) { return isset($body->{'RAX-KSKEY:apiKeyCredentials'}->apiKey) ? $body->{'RAX-KSKEY:apiKeyCredentials'}->apiKey : null; } }
/** * returns changes since a specified date/time * * @param string $since the date or time * @return DNS\Changes */ public function changes($since = null) { $url = $this->url('changes', isset($since) ? array('since' => $since) : array()); $response = $this->getService()->getClient()->get($url)->send(); return Formatter::decode($response); }
/** * Authenticate the tenant using the supplied credentials * * @return void * @throws AuthenticationError */ public function authenticate() { // OpenStack APIs will return a 401 if an expired X-Auth-Token is sent, // so we need to reset the value before authenticating for another one. $this->updateTokenHeader(''); $identity = IdentityService::factory($this); $response = $identity->generateToken($this->getCredentials()); $body = Formatter::decode($response); $this->setCatalog($body->access->serviceCatalog); $this->setTokenObject($identity->resource('Token', $body->access->token)); $this->setUser($identity->resource('User', $body->access->user)); if (isset($body->access->token->tenant)) { $this->setTenantObject($identity->resource('Tenant', $body->access->token->tenant)); } // Set X-Auth-Token HTTP request header $this->updateTokenHeader($this->getToken()); }
/** * Delete() returns an asynchronous response * * @param array $params array of key/value pairs * @return AsyncResponse */ public function delete() { $body = Formatter::decode(parent::delete()); return new AsyncResponse($this->getService(), $body); }
/** * Get the current state of the scaling group, including the current set of * active entities, the number of pending entities, and the desired number * of entities. * * @return object|boolean * @throws Exceptions\HttpError * @throws Exceptions\ServerActionError */ public function getState() { $response = $this->getService()->getClient()->get($this->url('state'))->send(); $body = Formatter::decode($response); return !empty($body->group) ? $body->group : false; }
/** * Returns a console connection * Note: Where is this documented? * * @codeCoverageIgnore */ public function console($type = 'novnc') { $action = strpos('spice', $type) !== false ? 'os-getSPICEConsole' : 'os-getVNCConsole'; $object = (object) array($action => (object) array('type' => $type)); $response = $this->action($object); $body = Formatter::decode($response); return isset($body->console) ? $body->console : false; }