/** * Returns the URL of the container * * @return string * @param string $subresource not used; required for compatibility * @throws NoNameError */ public function Url($subresource = '') { if (!$this->name) { throw new Exceptions\NoNameError(Lang::translate('Container does not have an identifier')); } return Lang::noslash($this->Service()->Url(rawurlencode($this->name))); }
/** * Called when creating a new Compute service object * * _NOTE_ that the order of parameters for this is *different* from the * parent Service class. This is because the earlier parameters are the * ones that most typically change, whereas the later ones are not * modified as often. * * @param \OpenCloud\Identity $conn - a connection object * @param string $serviceRegion - identifies the region of this Compute * service * @param string $urltype - identifies the URL type ("publicURL", * "privateURL") * @param string $serviceName - identifies the name of the service in the * catalog */ public function __construct(OpenStack $conn, $serviceType, $serviceName, $serviceRegion, $urltype) { parent::__construct($conn, $serviceType, $serviceName, $serviceRegion, $urltype); $this->_url = Lang::noslash(parent::Url()); $this->getLogger()->info(Lang::translate('Initializing Nova...')); }
/** * Returns the IP address block for the Server or for a specific network. * * @api * @param string $network - if supplied, then only the IP(s) for the * specified network are returned. Otherwise, all IPs are returned. * @return object * @throws Exceptions\ServerIpsError */ public function ips($network = null) { $url = Lang::noslash($this->Url('ips/' . $network)); $response = $this->getClient()->get($url)->send(); $body = Formatter::decode($response); return isset($body->addresses) ? $body->addresses : (isset($body->network) ? $body->network : (object) array()); }
/** * Returns the URL of the data object * * If the object is new and doesn't have a name, then an exception is * thrown. * * @param string $subresource Not used * @return string * @throws NoNameError */ public function url($subresource = '') { if (!$this->name) { throw new Exceptions\NoNameError(Lang::translate('Object has no name')); } return Lang::noslash($this->container->url()) . '/' . str_replace('%2F', '/', rawurlencode($this->name)); }
/** * Returns the IP address block for the Server or for a specific network * * @api * @param string $network - if supplied, then only the IP(s) for * the specified network are returned. Otherwise, all IPs are returned. * @return object * @throws ServerIpsError */ public function ips($network = null) { $url = Lang::noslash($this->Url('ips/' . $network)); $response = $this->Service()->Request($url); // @codeCoverageIgnoreStart if ($response->HttpStatus() >= 300) { throw new Exceptions\ServerIpsError(sprintf(Lang::translate('Error in Server::ips(), status [%d], response [%s]'), $response->HttpStatus(), $response->HttpBody())); } $object = json_decode($response->httpBody()); $this->checkJsonError(); if (isset($object->addresses)) { return $object->addresses; } elseif (isset($object->network)) { return $object->network; } else { return new \stdClass(); } // @codeCoverageIgnoreEnd }
/** * Returns the URL of this object * * @api * @param string $subresource specified subresource * @return string */ public function Url($subresource = 'tokens') { return Lang::noslash($this->url) . '/' . $subresource; }
/** * 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) { $urlBase = $this->getEndpoint($this->service_type, $this->service_name, $this->service_region, RAXSDK_URL_PUBLIC); $url = Lang::noslash($urlBase) . '/' . $resource; $response = $this->request($url); // check for NOT FOUND response if ($response->httpStatus() == 404) { return array(); } // @codeCoverageIgnoreStart if ($response->httpStatus() >= 300) { throw new Exceptions\HttpError(sprintf(Lang::translate('Error accessing [%s] - status [%d], response [%s]'), $urlBase, $response->httpStatus(), $response->httpBody())); } // @codeCoverageIgnoreEnd // we're good; proceed $object = json_decode($response->httpBody()); $this->checkJsonError(); return $object; }
/** * 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) { $urlbase = $this->get_endpoint($this->service_type, $this->service_name, $this->service_region, RAXSDK_URL_PUBLIC); if ($urlbase == '') { return array(); } $ext_url = Lang::noslash($urlbase) . '/' . $resource; $response = $this->Request($ext_url); // check for NOT FOUND response if ($response->HttpStatus() == 404) { return array(); } // check for error status if ($response->HttpStatus() >= 300) { throw new Exceptions\HttpError(sprintf(Lang::translate('Error accessing [%s] - status [%d], response [%s]'), $urlbase, $response->HttpStatus(), $response->HttpBody())); } // we're good; proceed $obj = json_decode($response->HttpBody()); if ($this->CheckJsonError()) { return false; } return $obj; }
/** * Returns the URL of the data object * * If the object is new and doesn't have a name, then an exception is * thrown. * * @param string $subresource Not used * @return string * @throws NoNameError */ public function Url($subresource = '') { if (!$this->name) { throw new Exceptions\NoNameError(Lang::translate('Object has no name')); } $this_name = $this->name; if (gettype($this->name) == 'array') { $this->name = $this->name['name']; } return Lang::noslash($this->container->Url()) . '/' . str_replace('%2F', '/', rawurlencode($this->name)); }
public function test_noslash() { $this->assertEquals(Lang::noslash('String/'), 'String'); $this->assertEquals(Lang::noslash('String'), 'String'); }
/** * Called when creating a new Compute service object * * _NOTE_ that the order of parameters for this is *different* from the * parent Service class. This is because the earlier parameters are the * ones that most typically change, whereas the later ones are not * modified as often. * * @param \OpenCloud\Identity $conn - a connection object * @param string $serviceRegion - identifies the region of this Compute * service * @param string $urltype - identifies the URL type ("publicURL", * "privateURL") * @param string $serviceName - identifies the name of the service in the * catalog */ public function __construct(OpenStack $conn, $serviceType, $serviceName, $serviceRegion, $urltype) { $this->debug(Lang::translate('initializing Nova...')); parent::__construct($conn, $serviceType, $serviceName, $serviceRegion, $urltype); $this->_url = Lang::noslash(parent::Url()); }