Rackspace Cloud SDK for PHP Getting Started Guide Rackspace Cloud SDK for PHP is an SDK to help PHP developers develop apps based on OpenStack and Rackspace Cloud (including public and private clouds) more easily. The SDK includes the following components: 1. Php-opencloud language binding (in the "Lib" directory) 2. Document (In the "docs/" directory) 3. Sample code (under the "samples/" directory) How to install the SDK the SDK can be obtained from the Rackspace GitHub source. Http://github.com/rackspace/php-opencloud gets the most easily available release version (stable version) of the code: 1. Click on the tags Link 2. Select the latest version and click on the "Zip" or ". tar.gz" button below 3. Find the file you just downloaded in your download directory. Remember the directory location and you'll use it later. Create some cloud servers in this example, you will write code to create two 1GB cloud servers running the Ubuntu13.04 system. You need a text editor to edit the following code. The following is the complete code: ' USERNAME ', ' password ' = ' password '); Connect the COMPUTE service $compute = $connection->compute (' Cloudserversopenstack ', ' ORD '); Looking for mirror $image = $compute->image (image_ubuntu); Gets the Flavor object $flavor = $compute->flavor (FLAVOR_1GB); Create 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 ()); Displays the root password printf ("server[%s" is building. Root password is [%s]\n], $server->name (), $server->adminpass); } Understand this program ' USERNAME ', ' password ' = ' password '); This creates a ' $connection ' object using ' \opencloud\rackspace ' connector. The object requires two parameters: 1. The URL of the authentication endpoint (' Rackspace_us ' is a useful constant provided by **php-opencloud**). 2. An array that contains your user name and password. Edit the value of ' USERNAME ' ' PASSWORD ' to map your own user name and password. Now, connect the COMPUTE service $compute = $connection->compute (' Cloudserversopenstack ', ' ORD '); Create a "Compute" class, in the Ord region to specify the service strength of the connection (in this case, the service is named "Cloudserversopenstack"), each time the call Compute () method returns a new connection to the service. First, find the image $image = $compute->image (image_ubuntu); Get a Flavor object $flavor = $compute->flavor (FLAVOR_1GB); This is another two factory methods that return an "Image" object and an "Flavor" object, respectively. Create the server for ($i =0; $i <2; $i + +) {$server = $compute->server ();//get a blank server $resp = $server->c reate (' 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 the server. A new, empty server object was created from the $compute service, using the "Server ()" method. Finally, the "Server" object calls the "Create" method and needs to pass an array of attributes as a parameter. ' Name ', ' image ', ' flavor ' is the property required to create a new server.
http://www.bkjia.com/PHPjc/477125.html www.bkjia.com true http://www.bkjia.com/PHPjc/477125.html techarticle Rackspace Cloud SDK for PHP Getting Started Guide Rackspace Cloud SDK for PHP is a convenient development for PHP developers based on OpenStack and Rackspace Cloud (including public and private cloud) applications ...