openstack.inc
Properties
Description
The OpenStack connection/cloud classIncludes
base.inc (Require Once)objectstore.inc (Require Once)
compute.inc (Require Once)
volumeservice.inc (Require Once)
Classes
OpenStack
Description
The OpenStack class represents a relationship (or "connection") between a user and a service.This is the primary entry point into an OpenStack system, and the only one where the developer is required to know and provide the endpoint URL (in all other cases, the endpoint is derived from the Service Catalog provided by the authentication system).
Since various providers have different mechanisms for authentication, users will often use a subclass of OpenStack. For example, the Rackspace class is provided for users of Rackspace's cloud services, and other cloud providers are welcome to add their own subclasses as well.
General usage example:
$username = 'My Username';
$secret = 'My Secret';
$connection = new OpenCloud\OpenStack($username, $secret);
// having established the connection, we can set some defaults
// this sets the default name and region of the Compute service
$connection->SetDefaults('Compute', 'cloudServersOpenStack', 'ORD');
// access a Compute service
$chicago = $connection->Compute();
// if we want to access a different service, we can:
$dallas = $connection->Compute('cloudServersOpenStack', 'DFW');
Methods
AppendUserAgent, Authenticate, CheckAttributePrefix, CheckJsonError, Compute, Credentials, GetHttpRequestObject, MakeQueryString, ObjectStore, Request, Secret, Service, ServiceCatalog, ServiceCatalogItem, ServiceList, SetDefaults, SetDownloadProgressCallback, SetProperty, SetTimeouts, SetUploadProgressCallback, Tenant, Token, Url, VolumeService, __construct, __set, _read_cb, _write_cb, debug, to_string,AppendUserAgent( string $agent, ) : void
Description
Allows the user to append a user agent stringPrograms that are using these bindings are encouraged to add their user agent to the one supplied by this SDK. This will permit cloud providers to track users so that they can provide better service.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $agent | string | an arbitrary user-agent string; e.g. "My Cloud App" |
Return value
| Type | Description |
|---|---|
| void |
Tags
| Name | Description |
|---|---|
| api |
Authenticate( ) : void
Description
Authenticates using the supplied credentialsReturn value
| Type | Description |
|---|---|
| void |
Tags
| Name | Description |
|---|---|
| api | |
| throws |
CheckAttributePrefix( string $property, array $prefixes = array(), ) : boolean
Description
Checks the attribute $property and only permits it if the prefix is in the specified $prefixes arrayThis is to support extension namespaces in some services.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $property | string | the name of the attribute |
|
| $prefixes | array | a list of prefixes |
array() |
Return value
| Type | Description |
|---|---|
| boolean | TRUE if valid; FALSE if not |
Tags
| Name | Description |
|---|---|
| inherited_from | \OpenCloud\Base::CheckAttributePrefix() |
CheckJsonError( ) : boolean
Description
Checks the most recent JSON operation for errorsThis function should be called after any json_*() function call.
This ensures that nasty JSON errors are detected and the proper
exception thrown.
Example:
$obj = json_decode($string);
if (check_json_error()) do something ...
Return value
| Type | Description |
|---|---|
| boolean | TRUE if an error occurred, FALSE if none |
Tags
| Name | Description |
|---|---|
| throws | |
| inherited_from | \OpenCloud\Base::CheckJsonError() |
Compute( string $name = NULL, string $region = NULL, string $urltype = NULL, ) : \OpenCloud\ObjectStore
Description
Creates a new Compute object (Nova/Cloud Servers)Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $name | string | the name of the Compute service to attach to |
NULL |
| $region | string | the name of the region to use |
NULL |
| $urltype | string | the URL type (normally "publicURL") |
NULL |
Return value
| Type | Description |
|---|---|
| \OpenCloud\ObjectStore |
Tags
| Name | Description |
|---|---|
| api |
Credentials( ) : string
Description
Creates and returns the formatted credentials to POST to the auth service.Return value
| Type | Description |
|---|---|
| string |
GetHttpRequestObject( $url, $method = 'GET', ) : n/a
Description
Returns a class that implements the HttpRequest interface.This can be stubbed out for unit testing and avoid making live calls.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $url | n/a | ||
| $method | n/a | 'GET' |
Return value
| Type | Description |
|---|---|
| n/a | n/a |
Tags
| Name | Description |
|---|---|
| inherited_from | \OpenCloud\Base::GetHttpRequestObject() |
MakeQueryString( array $arr, ) : string
Description
Converts an array of key/value pairs into a single query stringFor example, array('A'=>1,'B'=>2) would become 'A=1&B=2'.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $arr | array | array of key/value pairs |
Return value
| Type | Description |
|---|---|
| string |
Tags
| Name | Description |
|---|---|
| inherited_from | \OpenCloud\Base::MakeQueryString() |
ObjectStore( string $name = NULL, string $region = NULL, string $urltype = NULL, ) : \OpenCloud\ObjectStore
Description
Creates a new ObjectStore object (Swift/Cloud Files)Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $name | string | the name of the Object Storage service to attach to |
NULL |
| $region | string | the name of the region to use |
NULL |
| $urltype | string | the URL type (normally "publicURL") |
NULL |
Return value
| Type | Description |
|---|---|
| \OpenCloud\ObjectStore |
Tags
| Name | Description |
|---|---|
| api |
Request( string $url, string $method = 'GET', array $headers = array(), string $data = NULL, ) : \OpenCloud\HttpResponse
Description
Performs a single HTTP requestThe request() method is one of the most frequently-used in the entire library. It performs an HTTP request using the specified URL, method, and with the supplied headers and body. It handles error and exceptions for the request.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $url | string | url - the URL of the request |
|
| $method | string | method - the HTTP method (defaults to GET) |
'GET' |
| $headers | array | headers - an associative array of headers |
array() |
| $data | string | data - either a string or a resource (file pointer) to use as the request body (for PUT or POST) |
NULL |
Return value
| Type | Description |
|---|---|
| \OpenCloud\HttpResponse | object |
Tags
| Name | Description |
|---|---|
| api | |
| throws | HttpUnauthorizedError, HttpForbiddenError |
Service( string $class, string $name = NULL, string $region = NULL, string $urltype = NULL, ) : \OpenCloud\Service
Description
Generic Service factory methodContains code reused by the other service factory methods.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $class | string | the name of the Service class to produce |
|
| $name | string | the name of the Compute service to attach to |
NULL |
| $region | string | the name of the region to use |
NULL |
| $urltype | string | the URL type (normally "publicURL") |
NULL |
Return value
| Type | Description |
|---|---|
| \OpenCloud\Service | (or subclass such as Compute, ObjectStore) |
Tags
| Name | Description |
|---|---|
| throws |
ServiceCatalog( ) : \stdClass
Description
Returns the service catalog object from the auth serviceReturn value
| Type | Description |
|---|---|
| \stdClass |
ServiceCatalogItem( $info = array(), ) : n/a
Description
returns a service catalog itemThis is a helper function used to list service catalog items easily
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $info | n/a | array() |
Return value
| Type | Description |
|---|---|
| n/a | n/a |
ServiceList( ) : n/a
Description
Returns a Collection of objects with information on servicesNote that these are informational (read-only) and are not actually 'Service'-class objects.
Return value
| Type | Description |
|---|---|
| n/a | n/a |
SetDefaults( string $service, string $name = NULL, string $region = NULL, string $urltype = NULL, ) : void
Description
Sets default values for name, region, URL type for a serviceOnce these are set (and they can also be set by defining global constants), then you do not need to specify these values when creating new service objects.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $service | string | the name of a supported service; e.g. 'Compute' |
|
| $name | string | the service name; e.g., 'cloudServersOpenStack' |
NULL |
| $region | string | the region name; e.g., 'LON' |
NULL |
| $urltype | string | the type of URL to use; e.g., 'internalURL' |
NULL |
Return value
| Type | Description |
|---|---|
| void |
Tags
| Name | Description |
|---|---|
| api | |
| throws |
SetDownloadProgressCallback( \OpenCloud\callable $callback, ) : void
Description
Allows the user to define a function for tracking downloadsThis can be used to implement a progress bar or similar function. The callback function is called with a single parameter, the length of the data that is being downloaded on this call.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $callback | \OpenCloud\callable | the name of a global callback function, or an array($object, $functionname) |
Return value
| Type | Description |
|---|---|
| void |
SetProperty( string $property, mixed $value, array $prefixes = array(), ) : n/a
Description
Sets an extended (unrecognized) property on the current objectIf RAXSDK_STRICT_PROPERTY_CHECKS is TRUE, then the prefix of the property name must appear in the $prefixes array, or else an exception is thrown.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $property | string | the property name |
|
| $value | mixed | the value of the property |
|
| $prefixes | array | optional list of supported prefixes |
array() |
Return value
| Type | Description |
|---|---|
| n/a | n/a |
Tags
| Name | Description |
|---|---|
| throws | if strict checks are on and the property prefix is not in the list of prefixes. |
| inherited_from | \OpenCloud\Base::SetProperty() |
SetTimeouts( integer $t_http, integer $t_conn = NULL, integer $t_overlimit = NULL, ) : void
Description
Sets the timeouts for the current connectionArguments
| Name | Type | Description | Default |
|---|---|---|---|
| $t_http | integer | the HTTP timeout value (the max period that the OpenStack object will wait for any HTTP request to complete). Value is in seconds. |
|
| $t_conn | integer | the Connect timeout value (the max period that the OpenStack object will wait to establish an HTTP connection). Value is in seconds. |
NULL |
| $t_overlimit | integer | the overlimit timeout value (the max period that the OpenStack object will wait to retry on an overlimit condition). Value is in seconds. |
NULL |
Return value
| Type | Description |
|---|---|
| void |
Tags
| Name | Description |
|---|---|
| api |
SetUploadProgressCallback( \OpenCloud\callable $callback, ) : void
Description
Allows the user to define a function for tracking uploadsThis can be used to implement a progress bar or similar function. The callback function is called with a single parameter, the length of the data that is being uploaded on this call.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $callback | \OpenCloud\callable | the name of a global callback function, or an array($object, $functionname) |
Return value
| Type | Description |
|---|---|
| void |
Tenant( ) : string
Description
Returns the tenant ID, re-authenticating if necessaryReturn value
| Type | Description |
|---|---|
| string |
Tags
| Name | Description |
|---|---|
| api |
Token( ) : string
Description
Returns the cached token; if it has expired, then it re-authenticatesReturn value
| Type | Description |
|---|---|
| string |
Tags
| Name | Description |
|---|---|
| api |
Url( ) : string
Description
Returns the URL of this objectThe assumption is that nearly all objects will have a URL; at this base level, it simply throws an exception to enforce the idea that subclasses need to define this method.
Return value
| Type | Description |
|---|---|
| string |
Tags
| Name | Description |
|---|---|
| api | |
| throws |
VolumeService( string $name = NULL, string $region = NULL, string $urltype = NULL, ) : n/a
Description
Creates a new VolumeService (cinder) service objectThis is a factory method that is Rackspace-only (NOT part of OpenStack).
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $name | string | the name of the service (e.g., 'cloudBlockStorage') |
NULL |
| $region | string | the region (e.g., 'DFW') |
NULL |
| $urltype | string | the type of URL (e.g., 'publicURL'); |
NULL |
Return value
| Type | Description |
|---|---|
| n/a | n/a |
__construct( string $url, array $secret, ) : n/a
Description
Creates a new OpenStack objectThe OpenStack object needs two bits of information: the URL to authenticate against, and a "secret", which is an associative array of name/value pairs. Usually, the secret will be a username and a password, but other values may be required by different authentication systems. For example, OpenStack Keystone requires a username and password, but Rackspace uses a username, tenant ID, and API key. (See OpenCloud\Rackspace for that.)
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $url | string |
|
|
| $secret | array |
|
Return value
| Type | Description |
|---|---|
| n/a | n/a |
__set( string $property, mixed $value, ) : void
Description
Sets extended attributes on an object and validates themThis function is provided to ensure that attributes cannot arbitrarily added to an object. If this function is called, it means that the attribute is not defined on the object, and thus an exception is thrown.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $property | string | the name of the attribute |
|
| $value | mixed | the value of the attribute |
Return value
| Type | Description |
|---|---|
| void |
Tags
| Name | Description |
|---|---|
| inherited_from | \OpenCloud\Base::__set() |
_read_cb( resource $ch, resource $fd, integer $length, ) : string
Description
Callback function to handle reads for file uploadsInternal function for handling file uploads. Note that, although this function's visibility is public, this is only because it must be called from the HttpRequest interface. This should NOT be called by users directly.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $ch | resource | a CURL handle |
|
| $fd | resource | a file descriptor |
|
| $length | integer | the amount of data to read |
Return value
| Type | Description |
|---|---|
| string | the data read |
_write_cb( resource $ch, string $data, ) : integer
Description
Callback function to handle writes for file downloadsInternal function for handling file downloads. Note that, although this function's visibility is public, this is only because it must be called via the HttpRequest interface. This should NOT be called by users directly.
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $ch | resource | a CURL handle |
|
| $data | string | the data to be written to a file |
Return value
| Type | Description |
|---|---|
| integer | the number of bytes written |
debug( string $msg, mixed $p1 = NULL, mixed $p2 = NULL, mixed $p3 = NULL, mixed $p4 = NULL, mixed $p5 = NULL, ) : void
Description
Displays a debug message if $RAXSDK_DEBUG is TRUEThe primary parameter is a string in sprintf() format, and it can accept up to five optional parameters. It prints the debug message, prefixed with "Debug:" and the class name, to the standard output device.
Example:
$this->debug('Starting execution of %s', get_class($this))
Arguments
| Name | Type | Description | Default |
|---|---|---|---|
| $msg | string | The message string (required); can be in sprintf() format. |
|
| $p1 | mixed | Optional argument to be passed to sprintf() |
NULL |
| $p2 | mixed | Optional argument to be passed to sprintf() |
NULL |
| $p3 | mixed | Optional argument to be passed to sprintf() |
NULL |
| $p4 | mixed | Optional argument to be passed to sprintf() |
NULL |
| $p5 | mixed | Optional argument to be passed to sprintf() |
NULL |
Return value
| Type | Description |
|---|---|
| void |
Tags
| Name | Description |
|---|---|
| inherited_from | \OpenCloud\Base::debug() |
to_string( mixed $x, ) : string
Description
Converts a value to an HTTP-displayable string formArguments
| Name | Type | Description | Default |
|---|---|---|---|
| $x | mixed | a value to convert |
Return value
| Type | Description |
|---|---|
| string |
Tags
| Name | Description |
|---|---|
| inherited_from | \OpenCloud\Base::to_string() |
