OpenCloud/OpenStack.php

Properties

Description

The OpenStack connection/cloud class

Classes

OpenStack

Properties

 
 
 
No 
No 

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, Compute, Credentials, Expiration, ExportCredentials, ImportCredentials, ObjectStore, Orchestration, Request, Secret, Service, ServiceCatalog, ServiceCatalogItem, ServiceList, SetDefaults, SetDownloadProgressCallback, SetTimeouts, SetUploadProgressCallback, Tenant, Token, Url, VolumeService, __construct, _read_cb, _write_cb,

AppendUserAgent( string   $agent, ) : void

Description

Allows the user to append a user agent string
Programs 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 credentials

Return value

Type Description
void

Tags

Name Description
api
throws

Compute( string   $name = null, string   $region = null, string   $urltype = null, ) : \OpenCloud\Compute

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\Compute

Tags

Name Description
api

Credentials( ) : string

Description

Creates and returns the formatted credentials to POST to the auth service.

Return value

Type Description
string

Expiration( ) : string

Description

Returns the cached expiration time; if it has expired, then it re-authenticates

Return value

Type Description
string

Tags

Name Description
api

ExportCredentials( ) : array

Description

exports saved token, expiration, tenant, and service catalog as an array
This could be stored in a cache (APC or disk file) and reloaded using ImportCredentials()

Return value

Type Description
array

ImportCredentials(   $values, ) : void

Description

imports credentials from an array
Takes the same values as ExportCredentials() and reuses them.

Arguments

Name Type Description Default
$values n/a

Return value

Type Description
void

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

Orchestration( string   $name = null, string   $region = null, string   $urltype = null, ) : \OpenCloud\Orchestration\Service

Description

Creates a new Orchestration (heat) service object

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\Orchestration\Service

Tags

Name Description
api

Request(   $url,   $method = 'GET',   $headers = array(),   $data = null, ) : \OpenCloud\HttpResponse

Description

Performs a single HTTP request
The 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 n/a
$method n/a 'GET'
$headers n/a array()
$data n/a null

Return value

Type Description
\OpenCloud\HttpResponse object

Tags

Name Description
api
throws HttpUnauthorizedError, HttpForbiddenError

Secret( ) : array

Description

Returns the stored secret

Return value

Type Description
array

Service( string   $class, string   $name = null, string   $region = null, string   $urltype = null, ) : \OpenCloud\Service

Description

Generic Service factory method
Contains 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 service

Return value

Type Description
\stdClass

ServiceCatalogItem(   $info = array(), ) : n/a

Description

returns a service catalog item
This 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 services
Note 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 service
Once 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( callable   $callback, ) : void

Description

Allows the user to define a function for tracking downloads
This 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 callable

the name of a global callback function, or an array($object, $functionname)

Return value

Type Description
void

SetTimeouts( integer   $t_http, integer   $t_conn = null, integer   $t_overlimit = null, ) : void

Description

Sets the timeouts for the current connection

Arguments

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( callable   $callback, ) : void

Description

Allows the user to define a function for tracking uploads
This 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 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 necessary

Return value

Type Description
string

Tags

Name Description
api

Token( ) : string

Description

Returns the cached token; if it has expired, then it re-authenticates

Return value

Type Description
string

Tags

Name Description
api

Url( string   $subresource = 'tokens', ) : string

Description

Returns the URL of this object

Arguments

Name Type Description Default
$subresource string

specified subresource

'tokens'

Return value

Type Description
string

Tags

Name Description
api

VolumeService( string   $name = null, string   $region = null, string   $urltype = null, ) : n/a

Description

Creates a new VolumeService (cinder) service object
This 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, array   $options = array(), ) : n/a

Description

Creates a new OpenStack object
The 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
  • the authentication endpoint URL
$secret array
  • an associative array of auth information:
  • username
  • password
$options array
  • CURL options to pass to the HttpRequest object
array()

Return value

Type Description
n/a n/a

_read_cb( resource   $ch, resource   $fd, integer   $length, ) : string

Description

Callback function to handle reads for file uploads
Internal 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 downloads
Internal 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

Properties

$_file_descriptors, $_user_read_progress_callback_func, $_user_write_progress_callback_func, $catalog, $connect_timeout, $curl_options, $defaults, $expiration, $export_items, $http_timeout, $overlimit_timeout, $secret, $tenant, $token, $url, $useragent,

  private  $_file_descriptors = array()

Tracks file descriptors used by streaming downloads
This will permit multiple simultaneous streaming downloads; the key is the URL of the object, and the value is its file descriptor. To prevent memory overflows, each array element is deleted when the end of the file is reached.

  private  $_user_read_progress_callback_func =




  private  $_user_write_progress_callback_func =




  protected  $catalog =




  protected  $connect_timeout = RAXSDK_CONNECTTIMEOUT




  private  $curl_options = array()

array of options to pass to the CURL request object


  protected  $defaults = array('Compute' => array('name' => RAXSDK_COMPUTE_NAME, 'region' => RAXSDK_COMPUTE_REGION, 'urltype' => RAXSDK_COMPUTE_URLTYPE), 'ObjectStore' => array('name' => RAXSDK_OBJSTORE_NAME, 'region' => RAXSDK_OBJSTORE_REGION, 'urltype' => RAXSDK_OBJSTORE_URLTYPE), 'Database' => array('name' => RAXSDK_DATABASE_NAME, 'region' => RAXSDK_DATABASE_REGION, 'urltype' => RAXSDK_DATABASE_URLTYPE), 'Volume' => array('name' => RAXSDK_VOLUME_NAME, 'region' => RAXSDK_VOLUME_REGION, 'urltype' => RAXSDK_VOLUME_URLTYPE), 'LoadBalancer' => array('name' => RAXSDK_LBSERVICE_NAME, 'region' => RAXSDK_LBSERVICE_REGION, 'urltype' => RAXSDK_LBSERVICE_URLTYPE), 'DNS' => array('name' => RAXSDK_DNS_NAME, 'region' => RAXSDK_DNS_REGION, 'urltype' => RAXSDK_DNS_URLTYPE), 'Orchestration' => array('name' => RAXSDK_ORCHESTRATION_NAME, 'region' => RAXSDK_ORCHESTRATION_REGION, 'urltype' => RAXSDK_ORCHESTRATION_URLTYPE), 'CloudMonitoring' => array('name' => RAXSDK_MONITORING_NAME, 'region' => RAXSDK_MONITORING_REGION, 'urltype' => RAXSDK_MONITORING_URLTYPE), 'Autoscale' => array('name' => RAXSDK_AUTOSCALE_NAME, 'region' => RAXSDK_AUTOSCALE_REGION, 'urltype' => RAXSDK_AUTOSCALE_URLTYPE))

This associative array holds default values used to identify each service (and to select it from the Service Catalog). Use the Compute::SetDefaults() method to change the default values, or define the global constants (for example, RAXSDK_COMPUTE_NAME) BEFORE loading the OpenCloud library:
<code> define('RAXSDK_COMPUTE_NAME', 'cloudServersOpenStack'); include('openstack.php'); </code>

  protected  $expiration = 0




  private  $export_items = array('token', 'expiration', 'tenant', 'catalog')

list of attributes to export/import


  protected  $http_timeout = RAXSDK_TIMEOUT




  protected  $overlimit_timeout = RAXSDK_OVERLIMIT_TIMEOUT




  protected  $secret = array()




  protected  $tenant =




  protected  $token =




  protected  $url =




  public  $useragent = RAXSDK_USER_AGENT

This holds the HTTP User-Agent: used for all requests to the services. It is public so that, if necessary, it can be entirely overridden by the developer. However, it's strongly recomended that you use the OpenStack::AppendUserAgent() method to APPEND your own User Agent identifier to the end of this string; the user agent information can be very valuable to service providers to track who is using their service.


Documentation was generated by phpDocumentor 2.0.0b6 .

Namespaces

Packages