The Require() statement includes the **php-opencloud** library. You will need to edit this field to specify the exact path to the php-opencloud.php file (in the lib/ folder of the directory you just downloaded).
define('IMAGE_UBUNTU', '9922a7c7-5a42-4a56-bc6a-93f857ae2346');
define('FLAVOR_1GB','3');
These two constants define the image ID of the Ubuntu13.04 image and the flavor of 1GB. To use a different flavor or image, use the novaclient CLI to query the Rackspace Control Panle for available values.
// establish our credentials
$connection = new OpenCloudRackspace(
RACKSPACE_US,
array( 'username' => 'USERNAME',
'password' => 'PASSWORD'));
This creates a '$connection' object using the 'OpenCloudRackspace' connector. This object requires two parameters:
1. The URL of the authentication endpoint (`RACKSPACE_US` is a very useful constant provided by **php-opencloud**).
2. An array containing your username and password. Edit the value of 'USERNAME' and 'PASSWORD' to map your own username and password.
// Now, connect to compute service
$compute = $connection->Compute('cloudServersOpenStack', 'ORD');
Create a "Compute" class that connects to the specified service capability in the ORD region (in this case, the service is named "cloudServersOpenStack"),
The Compute() method returns a new connection to the service on each call.
// first, find the image
$image = $compute->Image(IMAGE_UBUNTU);
// get a flavor object
$flavor = $compute->Flavor(FLAVOR_1GB);
These are two other factory methods, returning an "Image" object and a "Flavor" object respectively.
// create the server
for ($i=0; $i<2; $i++) {
$resp= $server->Create(array(
//check for errors
>
die("Errorbuilding server. Response is ".$resp->HttpBody());
printf("Server[%s] is building. Root password is [%s]n",
}
This actually creates the server. Creates a new, empty server object from the "$compute" service, using the "Server()" method.
Finally, the "Server" object calls the "Create" method and needs to pass an attribute array as a parameter. 'name', 'image', 'flavor' are the properties required to create a new server.
http://www.bkjia.com/PHPjc/477125.html
www.bkjia.com
true
http: //www.bkjia.com/PHPjc/477125.html
TechArticleRackspace Cloud SDK for PHP Getting Started Guide Rackspace Cloud SDK for PHP is a development tool used to help PHP developers more conveniently Based on OpenStack and Rackspace cloud (including public and private cloud) applications...