OpenCloud/Common/PersistentObject.php

Properties

Description

An abstraction that defines persistent objects associated with a service

Classes

PersistentObject

Properties

 
 
Yes 
No 

Description

represents an object that has the ability to be retrieved, created, updated, and deleted.
This class abstracts much of the common functionality between Nova servers, Swift containers and objects, DBAAS instances, Cinder volumes, and various other objects that (a) have a URL, (b) can be created, updated, deleted, or retrieved, and (c) use a standard JSON format with a top-level element followed by a child object with attributes. In general, you can create a persistent object class by subclassing this class and defining some protected, static variables: - $url_resource - the sub-resource value in the URL of the parent. For example, if the parent URL is `http://something/parent`, then setting this value to `'another'` would result in a URL for the persistent object of `http://something/parent/another`. - $json_name - the top-level JSON object name. For example, if the persistent object is represented by `{"foo": {"attr":value, ...}}`, then set `json_name = 'foo'`. - $json_collection_name - optional; this value is the name of a collection of the persistent objects. If not provided, it defaults to `json_name` with an appended `'s'` (e.g., if `json_name` is `"foo"`, then `json_collection_name` would be `"foos"` by default). Set this value if the collection name doesn't follow this pattern. - $json_collection_element - the common pattern for a collection is: `{"collection": [{"attr":"value",...}, {"attr":"value",...}, ...]}` That is, each element of the array is an anonymous object containing the object's attributes. In (very) rare instances, the objects in the array are named, and `json_collection_element` contains the name of the collection objects. For example, in this: `{"allowedDomain":[{"allowedDomain":{"name":"foo"}}]}`, then `json_collection_element` would be set to `'allowedDomain'`. The PersistentObject class supports the standard `Create()`, `Update()`, and `Delete()` methods; if these are not needed (i.e., not supported by the service, the subclass should redefine these to call the `NoCreate`, `NoUpdate`, or `NoDelete` methods, which will trigger an appropriate exception. For example, if an object cannot be created: function Create($parm=array()) { $this->NoCreate(); } This will cause any call to the `Create()` method to fail with an exception.

Methods

Action, CheckExtension, Create, CreateJson, CreateUrl, Delete, FindLink, Id, JsonCollectionElement, JsonCollectionName, JsonName, Name, NoCreate, NoDelete, NoUpdate, Parent, PrimaryKeyField, Refresh, Region, ResourceName, Service, Status, Update, UpdateJson, Url, WaitFor, __construct, __set, populate, setParent,

Action(   $object, ) : n/a

Description

Sends the json string to the /action resource
This is used for many purposes, such as rebooting the server, setting the root password, creating images, etc. Since it can only be used on a live server, it checks for a valid ID.

Arguments

Name Type Description Default
$object n/a
  • this will be encoded as json, and we handle all the JSON error-checking in one place

Return value

Type Description
n/a n/a

Tags

Name Description
throws if server ID is not defined
throws on other errors
returns boolean; TRUE if successful, FALSE otherwise

CheckExtension(   $alias, ) : n/a

Description

checks for `$alias` in extensions and throws an error if not present

Arguments

Name Type Description Default
$alias n/a

Return value

Type Description
n/a n/a

Tags

Name Description
throws

Create( array   $params = array(), ) : \OpenCloud\Common\HttpResponse

Description

Creates a new object

Arguments

Name Type Description Default
$params array

array of values to set when creating the object

array()

Return value

Type Description
\OpenCloud\Common\HttpResponse

Tags

Name Description
api
throws if HTTP status is not Success

CreateJson( ) : n/a

Description

Returns an object for the Create() method JSON
Must be overridden in a child class.

Return value

Type Description
n/a n/a

Tags

Name Description
throws if not overridden

CreateUrl( ) : string

Description

returns the URL used for Create

Return value

Type Description
string

Delete( ) : \OpenCloud\Common\HttpResponse

Description

Deletes an object

Return value

Type Description
\OpenCloud\Common\HttpResponse

Tags

Name Description
api
throws if HTTP status is not Success

FindLink( string   $type = 'self', ) : string

Description

Since each server can have multiple links, this returns the desired one

Arguments

Name Type Description Default
$type string
  • 'self' is most common; use 'bookmark' for the version-independent one
'self'

Return value

Type Description
string the URL from the links block

Id( ) : string

Description

returns the object's identifier
Can be overridden by a child class if the identifier is not in the `$id` property. Use of this function permits the `$id` attribute to be protected or private to prevent unauthorized overwriting for security.

Return value

Type Description
string

Tags

Name Description
api

JsonCollectionElement( ) : string

Description

returns the JSON name for each element in a collection
Usually, elements in a collection are anonymous; this function, however, provides for an element level name: `{ "collection" : [ { "element" : ... } ] }`

Return value

Type Description
string

JsonCollectionName( ) : string

Description

returns the collection JSON element name
When an object is returned in a collection, it usually has a top-level object that is an array holding child objects of the object types. This static function returns the name of the top-level element. Usually, that top-level element is simply the JSON name of the resource.'s'; however, it can be overridden by specifying the $json_collection_name attribute.

Return value

Type Description
string

JsonName( ) : n/a

Description

Returns the top-level document identifier for the returned response JSON document; must be overridden in child classes
For example, a server document is (JSON) `{"server": ...}` and an Instance document is `{"instance": ...}` - this function must return the top level document name (either "server" or "instance", in these examples).

Return value

Type Description
n/a n/a

Tags

Name Description
throws if not overridden

Name( ) : string

Description

Returns the displayable name of the object
Can be overridden by child objects; *must* be overridden by child objects if the object does not have a `name` attribute defined.

Return value

Type Description
string

Tags

Name Description
api
throws if attribute 'name' is not defined

NoCreate( ) : n/a

Description

throws a CreateError for subclasses that don't support Create

Return value

Type Description
n/a n/a

Tags

Name Description
throws

NoDelete( ) : n/a

Description

throws a DeleteError for subclasses that don't support Delete

Return value

Type Description
n/a n/a

Tags

Name Description
throws

NoUpdate( ) : n/a

Description

throws a UpdateError for subclasses that don't support Update

Return value

Type Description
n/a n/a

Tags

Name Description
throws

Parent( ) : n/a

Description

returns the parent object of this object
This is a synonym for Service(), since the object is usually a service.

Return value

Type Description
n/a n/a

PrimaryKeyField( ) : string

Description

Returns the primary key field for the object
The primary key is usually 'id', but this function is provided so that (in rare cases where it is not 'id'), it can be overridden.

Return value

Type Description
string

Refresh(   $id = null,   $url = null, ) : void

Description

Refreshes the object from the origin (useful when the server is changing states)

Arguments

Name Type Description Default
$id n/a null
$url n/a null

Return value

Type Description
void

Tags

Name Description
throws

Region( ) : n/a

Description

returns the region associated with the object
navigates to the parent service to determine the region.

Return value

Type Description
n/a n/a

Tags

Name Description
api

ResourceName( ) : n/a

Description

Returns the resource name for the URL of the object; must be overridden in child classes
For example, a server is `/servers/`, a database instance is `/instances/`. Must be overridden in child classes.

Return value

Type Description
n/a n/a

Tags

Name Description
throws

Service( ) : n/a

Description

Returns the Service/parent object associated with this object

Return value

Type Description
n/a n/a

Status( ) : string

Description

returns the object's status or `N/A` if not available

Return value

Type Description
string

Tags

Name Description
api

Update( array   $params = array(), ) : \OpenCloud\Common\HttpResponse

Description

Updates an existing object

Arguments

Name Type Description Default
$params array

array of values to set when updating the object

array()

Return value

Type Description
\OpenCloud\Common\HttpResponse

Tags

Name Description
api
throws if HTTP status is not Success

UpdateJson(   $params = array(), ) : n/a

Description

Returns an object for the Update() method JSON
Must be overridden in a child class.

Arguments

Name Type Description Default
$params n/a array()

Return value

Type Description
n/a n/a

Tags

Name Description
throws if not overridden

Url( string   $subresource = NULL,   $queryString = array(), ) : string

Description

Returns the default URL of the object
This may have to be overridden in subclasses.

Arguments

Name Type Description Default
$subresource string

optional sub-resource string

NULL
$queryString n/a array()

Return value

Type Description
string

Tags

Name Description
throws if URL is not defined

WaitFor( string   $terminal = 'ACTIVE', integer   $timeout = RAXSDK_SERVER_MAXTIMEOUT, callable   $callback = NULL,   $sleep = RAXSDK_POLL_INTERVAL, ) : void

Description

Waits for the server/instance status to change
This function repeatedly polls the system for a change in server status. Once the status reaches the `$terminal` value (or 'ERROR'), then the function returns. The polling interval is set by the constant RAXSDK_POLL_INTERVAL. The function will automatically terminate after RAXSDK_SERVER_MAXTIMEOUT seconds elapse.

Arguments

Name Type Description Default
$terminal string

the terminal state to wait for

'ACTIVE'
$timeout integer

the max time (in seconds) to wait

RAXSDK_SERVER_MAXTIMEOUT
$callback callable

a callback function that is invoked with each repetition of the polling sequence. This can be used, for example, to update a status display or to permit other operations to continue

NULL
$sleep n/a RAXSDK_POLL_INTERVAL

Return value

Type Description
void

Tags

Name Description
api

__construct(   $parentObject, mixed   $info = null, ) : n/a

Description

Retrieves the instance from persistent storage

Arguments

Name Type Description Default
$parentObject n/a
$info mixed

the ID or array/object of data

null

Return value

Type Description
n/a n/a

Tags

Name Description
throws if $info has an invalid data type

__set( string   $name, mixed   $value, ) : void

Description

Validates properties that have a namespace: prefix
If the property prefix: appears in the list of supported extension namespaces, then the property is applied to the object. Otherwise, an exception is thrown.

Arguments

Name Type Description Default
$name string

the name of the property

$value mixed

the property's value

Return value

Type Description
void

Tags

Name Description
throws

populate( array|object|string|integer   $info, ) : n/a

Description

Populates the current object based on an unknown data type.

Arguments

Name Type Description Default
$info array|object|string|integer

Return value

Type Description
n/a n/a

Tags

Name Description
throws

setParent(   $parent, ) : n/a

Arguments

Name Type Description Default
$parent n/a

Return value

Type Description
n/a n/a

Properties

$_parent, $id,

  private  $_parent =




  protected  $id =




Documentation was generated by phpDocumentor 2.0.0b6 .

Namespaces

Packages