RackspaceCloudSDKforPHP Getting Started Guide _ PHP Tutorial

Source: Internet
Author: User
RackspaceCloudSDKforPHP Getting Started Guide. RackspaceCloudSDKforPHP Getting Started Guide RackspaceCloudSDKforPHP is an easy-to-use guide for PHP developers to develop Rackspace Cloud SDK for PHP applications based on OpenStack and Rackspace Cloud (including public and private clouds ).

Rackspace Cloud SDK for PHP is an SDK that helps PHP developers develop applications based on OpenStack and Rackspace Cloud (including public and private clouds) more conveniently.

The SDK includes the following components:

1. php-opencloud language binding (under the "lib" directory)

2. documentation (under the "docs/" directory)

3. Sample Code (in the "samples/" directory)

How to install SDK

This SDK can be obtained through the Rackspace GitHub source. Http://github.com/rackspace/php-opencloud

Obtain the code for the most easily available release version (stable version:

1. click the Tags link.

2. select the latest version, and click the next step.

3. find the file you just downloaded in your download directory. Remember the directory location and you will use it later.

Create some ECS instances

In this example, you will write code to create two 1 gb ecs instances running Ubuntu13.04. You need a text editor to edit the following code. The complete code is as follows:

Require ('/path/to/lib/php-opencloud.php ');

Define ('image _ UBUNTU ', '9922a7c7-5a42-4a56-bc6a-93f857ae2346 ');

Define ('Flavor _ 1gb', '3 ');

// Create a certificate

$ Connection = new \ OpenCloud \ Rackspace (

RACKSPACE_US,

Array ('username' => 'username ',

'Password' => 'password '));

// Connect to the compute service

$ Compute = $ connection-> Compute ('cloudserversopenstack', 'ord ');

// Find the image

$ Image = $ compute-> Image (IMAGE_UBUNTU );

// Obtain flavor object

$ Flavor = $ compute-> Flavor (FLAVOR_1GB );

// Create a server

For ($ I = 0; $ I <2; $ I ++ ){

$ Server = $ compute-> Server (); // get a blank server

$ Resp = $ server-> Create (array (

'Name' => sprintf ('server-% d', $ I ),

'Image' => $ image,

'Flavor' => $ flavor ));

// Check for errors

If ($ resp-> HttpStatus ()> 204)

Die ("Errorbuilding server. Response is". $ resp-> HttpBody ());

// Display the root password

Printf ("Server [% s] is building. Root password is [% s] \ n ",

$ Server-> Name (), $ server-> adminPass );

}

Understand this program

Require ('/path/to/lib/php-opencloud.php ');

The Require () statement contains the ** php-opencloud ** Library. You need to edit this field to specify the exact path of the php-opencloud.php File (under the lib/folder of the directory you just downloaded ).

Define ('image _ UBUNTU ', '9922a7c7-5a42-4a56-bc6a-93f857ae2346 ');

Define ('Flavor _ 1gb', '3 ');

The two constants define the image ID of the Ubuntu13.04 image, and 1 GB flavor. To use different flavor or images, use novaclient CLI to query available values in Rackspace Control Panle.

// Establish our credentials

$ Connection = new \ OpenCloud \ Rackspace (

RACKSPACE_US,

Array ('username' => 'username ',

'Password' => 'password '));

In this way, a '$ connection' object is created using' \ OpenCloud \ Rackspace 'connector. This object requires two parameters:

1. authentication endpoint URL ('rackspace _ us' is a very useful constant provided by ** php-opencloud ).

2. an array containing your username and password. Edit the value of ''username''' to map your USERNAME and PASSWORD.

// Now, connect to the compute service

$ Compute = $ connection-> Compute ('cloudserversopenstack', 'ord ');

Create a "Compute" class to connect to the specified service strength in ORD region (in this case, the service is named "cloudServersOpenStack "),

The Compute () method returns a new connection to the service during each call.

// First, find the image

$ Image = $ compute-> Image (IMAGE_UBUNTU );

// Get a flavor object

$ Flavor = $ compute-> Flavor (FLAVOR_1GB );

This is the other two factory methods that return an "Image" object and a "Flavor" object respectively.

// Create the server

For ($ I = 0; $ I <2; $ I ++ ){

$ Server = $ compute-> Server (); // get a blank server

$ Resp = $ server-> Create (array (

'Name' => sprintf ('server-% d', $ I ),

'Image' => $ image,

'Flavor' => $ flavor ));

// Check for errors

If ($ resp-> HttpStatus ()> 204)

Die ("Errorbuilding server. Response is". $ resp-> HttpBody ());

// Display the root password

Printf ("Server [% s] is building. Root password is [% s] \ n ",

$ Server-> Name (), $ server-> adminPass );

}

This actually creates a server. A new empty Server object is created from the "$ compute" service using the "Server ()" method.

Finally, the "Server" object calls the "Create" method and must pass an attribute array as the parameter. 'Name', 'Image', and 'flavor' are required to create a new server.

Http://www.bkjia.com/PHPjc/477125.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/477125.htmlTechArticleRackspace Cloud SDK for PHP Getting Started Guide Rackspace Cloud SDK for PHP is a tool to help PHP developers more easily develop applications based on OpenStack and Rackspace Cloud (including public and private clouds...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.