SlideShare a Scribd company logo
Enrico Zimuel
Zend Technologies

Manage Cloud
Infrastructures in PHP using
Zend Framework 2 (and ZF1)
About me
           • Software Engineer since 1996
             – Assembly x86, C/C++, Java, Perl, PHP
           • Enjoying PHP since 1999
           • PHP Engineer at Zend since 2008
           • ZF Core Team from April 2011
           • B.Sc. Computer Science and
               Economics from University of
               Pescara (Italy)
           • Email: enrico@zend.com
Summary
•   Cloud computing in PHP
•   ZendServiceRackspace
•   Examples
•   Simple Cloud API
•   ZendCloudInfrastructure for ZF2 and ZF1
•   Adapters: Amazon Ec2, Rackspace
•   Examples
Cloud computing

“Cloud computing is the delivery of computing as a
   service rather than a product, whereby shared
 resources, software, and information are provided
 to computers and other devices as a utility over a
             network (tipically internet)”
                      Wikipedia
Cloud computing


   What does it means?
  Actually, nothing useful.
Cloud computing


    Do not try to define it,
         just use it!
How to use it?
• API (Application Programming Interface), to
  interact with cloud services
• Typically use REST-based APIs
• Each vendors uses a property API:
   – Different API for each vendor
   – Use of specific PHP libraries (coming from
     community or vendors)
Some PHP libraries for Cloud
• Amazon Web Services
  – AWS SDK for PHP, http://aws.amazon.com/sdkforphp/
• Windows Azure
  – PHPAzure, http://phpazure.codeplex.com/
• Rackspace
  – php-cloudfiles, http://bit.ly/ptJa1Y
• GoGrid
  – GoGridClient, http://bit.ly/o7MeLA
ZF service classes for Cloud
•   ZendServiceAmazon
•   ZendServiceGoGrid (under development)
•   ZendServiceNirvanix
•   ZendServiceRackspace
•   ZendServiceWindowsAzure
ZendService
 Rackspace
ZendServiceRackspace

• Manage the following cloud services of
  Rackspace:
  – Servers
  – Files
• Provide a full OO interface for the API of
  Rackspace (ver 1.0)
• Release: ZF1 1.12+, ZF2 dev3+
Example: authentication
$user = 'username';
$key = 'secret key';

$rackspace = new ZendServiceRackspaceFiles($user,$key);

if ($rackspace->authenticate()) {
   echo "Authentication successfully";
} else {
   printf("ERROR: %s",$rackspace->getErrorMsg());
}
Example: store an image in a container
…
$container = $rackspace->createContainer('test');
if (!$rackspace->isSuccessful()) {
    die('ERROR: '.$rackspace->getErrorMsg());
}
$name = 'example.jpg';
$file = file_get_contents($name);
$metadata = array (
    'foo' => 'bar'
);
$rackspace->storeObject('test',$name,$file,$metadata);
if ($rackspace->isSuccessful()) {
    echo 'Object stored successfully';
} else {
    printf("ERROR: %s",$rackspace->getErrorMsg());
}
Example: create a new instance (server)
$user = 'username';
$key = 'secret key';

$rackspace = new ZendServiceRackspaceServers($user,$key);

$data = array (
    'name'     => 'test',
    'imageId' => '49',
    'flavorId' => '1',
);
$server = $rackspace->createServer($data);

if (!$rackspace->isSuccessful()) {
    die('ERROR: '.$rackspace->getErrorMsg());
}

printf("Server name    : %sn",$server->getName());
printf("Server Id      : %sn",$server->getId());
printf("Admin password : %sn",$server->getAdminPass());
Simple Cloud API
Simple Cloud API
• The Simple Cloud API is a common API for
  accessing cloud application services offered by
  multiple vendors
• Starting from November 2010 the Simple Cloud
  API is part of Zend Framework under the
  classname:
   – Zend_Cloud (ZF1)
   – ZendCloud (ZF2)
Why we need it?
• Vendor lock-in
  – In economics, vendor lock-in makes a
    customer dependent on a vendor for products
    and services, unable to use another vendor
    without substantial switching costs
• Portability
  – reuse the existing code instead of creating
    new code when moving software from an
    environment to another
The architecture




             ZendCloud


             ZendService
The architecture (2)



                ZendCloud
 Document   Queue       Storage   Infrastructure



               ZendService
ZendCloud as abstraction
• ZendCloud is an abstraction of the main
  features of some cloud vendors
• Vendor specific functions may not be included in
  ZendCloud (for portability reason)
  – For instance, Amazon S3 has a cleanBucket
    operation that is not implemented in ZendCloud
• You can access the concrete adapters to use
  specific functions (getAdapter)
ZendCloudDocumentService
• Abstracts the interfaces to all major document
  databases - both in the cloud and locally
  deployed
• Adapters:
   – Amazon SimpleDB
   – Windows Azure
ZendCloudQueueService
• The QueueService implements access to
  message queues available as local or remote
  services.
• Adapters:
   – Amazon Sqs
   – Windows Azure
   – ZendQueue
ZendCloudStorageService
• The storage service in the Simple Cloud API
  implements a basic interface for file storage on
  the cloud
• Adapters:
   – Amazon S3
   – Windows Azure
   – Nirvanix
   – Filesystem
   – Rackspace (under development)
ZendCloud
Infrastructure
ZendCloudInfrastructure
• Manage instances (servers) of a cloud
  computing infrastructure
• Release ZF1: 1.12+, ZF2: dev3+
• Adapters:
   – Amazon Ec2
   – Rackspace Cloud Servers
   – GoGrid (under development)
   – Windows Azure (under development)
Basic operations
•   Create a new instance
•   Delete an instance
•   Start/stop/reboot an instance
•   List available instances
•   Get the status of an instance (running, stop, etc)
•   Monitor an instance (CPU, RAM, Network, etc)
•   Deploy an instance
     – Execute remote shell command (using SSH2)
Image of an instance
• An image of an instance is the collection of the
  following information:
   – Operating system (OS)
   – Memory available (RAM)
   – CPU type
Example: Ec2 Adapter
use ZendCloudInfrastructureAdapterEc2 as Ec2Adapter,
    ZendCloudInfrastructureFactory;

$key    = 'key';
$secret = 'secret';
$region = 'region';

$infrastructure = Factory::getAdapter(array(
    Factory::INFRASTRUCTURE_ADAPTER_KEY =>
'ZendCloudInfrastructureAdapterEc2',
    Ec2Adapter::AWS_ACCESS_KEY => $key,
    Ec2Adapter::AWS_SECRET_KEY => $secret,
    Ec2Adapter::AWS_REGION     => $region,
));
Example: create an instance
$param= array (
    'imageId'      => 'your-image-id',
    'instanceType' => 'your-instance-type',
);

$instance= $infrastructure->createInstance('name', $param);

if ($instance===false) {
   die ('Error');
}

printf ("Name of the instance: %sn", $instance->getName());
printf ("ID of the instance : %sn", $instance->getId());
Example: reboot and wait for status

if (!$infrastructure->rebootInstance('instance-id')) {
    die ('Error in the execution of the reboot command');
}
echo 'Reboot command executed successfully';

if ($infrastructure->waitStatusInstance('instance-id',
Instance::STATUS_RUNNING)) {
    echo 'The instance is ready';
} else {
    echo 'The instance is not ready yet';
}
Wait for status change
waitStatusInstance (string $id, string $status,integer
$timeout=30)
• Wait the status change of an instance for a
  maximum time of n seconds (30 by default).
• Return true if the status changes as expected,
  false otherwise.
Example: monitor an instance
use ZendCloudInfrastructureInstance;

$cpuUsage= $infrastructure->monitorInstance(
            'instance-id',Instance::MONITOR_CPU);

var_dump($cpuUsage);


array(2) {                                   [2] => array(2) {
 ["series"] => array(3) {                      ["timestamp"] => int(1318348920)
   [0]=> array(2) {                            ["value"] => int(60)
     ["timestamp"] => int(1318348800)        }
     ["value"]=> int(80)                    }
   }                                        ["average"] => string(3) "70%"
   [1]=> array(2) {                     }
     ["timestamp"] => int(1318348860)
     ["value"] => int(70)
   }
Example: deploy an instance

$nodeId= 'id-instance';

$param= array (
    Instance::SSH_USERNAME => 'username',
    Instance::SSH_PASSWORD => 'password'
);

$cmd= 'ls -la /var/www';

$output= $infrastructure->deployInstance($nodeId,$param,$cmd);

echo "The files in the DocumentRoot of the $nodeId instance
are:n";
print_r ($output);


Note: require the SSH2 extension
Thank you!
• Vote this talk:
  – http://joind.in/3880

• Comments and feedbacks:
  – enrico@zend.com

More Related Content

What's hot (20)

PPT
9 password security
drewz lin
 
PPTX
Passwords presentation
Greg MacPherson
 
PPT
Java Symmetric
phanleson
 
PDF
Bring your infrastructure under control with Infrastructor
Stanislav Tiurikov
 
PDF
Strong cryptography in PHP
Enrico Zimuel
 
KEY
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Howard Lewis Ship
 
PDF
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Fwdays
 
PDF
Gr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
Stanislav Tiurikov
 
PDF
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
ConFoo
 
PDF
One Step Ahead of Cheaters -- Instrumenting Android Emulators
Priyanka Aash
 
PDF
Building DSLs with Xtext - Eclipse Modeling Day 2009
Heiko Behrens
 
PDF
NodeJS
LinkMe Srl
 
PDF
Effective Doctrine2: Performance Tips for Symfony2 Developers
Marcin Chwedziak
 
PDF
Security 202 - Are you sure your site is secure?
ConFoo
 
PDF
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
PDF
Getting started with developing Nodejs
Phil Hawksworth
 
PDF
Testing NodeJS Security
Jose Manuel Ortega Candel
 
PDF
Hacking NodeJS applications for fun and profit
Jose Manuel Ortega Candel
 
PDF
Groovy Domain Specific Languages - SpringOne2GX 2012
Guillaume Laforge
 
PPT
Symfony2 Service Container: Inject me, my friend
Kirill Chebunin
 
9 password security
drewz lin
 
Passwords presentation
Greg MacPherson
 
Java Symmetric
phanleson
 
Bring your infrastructure under control with Infrastructor
Stanislav Tiurikov
 
Strong cryptography in PHP
Enrico Zimuel
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Howard Lewis Ship
 
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Fwdays
 
Gr8conf EU 2018 - Bring you infrastructure under control with Infrastructor
Stanislav Tiurikov
 
Marrow: A Meta-Framework for Python 2.6+ and 3.1+
ConFoo
 
One Step Ahead of Cheaters -- Instrumenting Android Emulators
Priyanka Aash
 
Building DSLs with Xtext - Eclipse Modeling Day 2009
Heiko Behrens
 
NodeJS
LinkMe Srl
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Marcin Chwedziak
 
Security 202 - Are you sure your site is secure?
ConFoo
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
Getting started with developing Nodejs
Phil Hawksworth
 
Testing NodeJS Security
Jose Manuel Ortega Candel
 
Hacking NodeJS applications for fun and profit
Jose Manuel Ortega Candel
 
Groovy Domain Specific Languages - SpringOne2GX 2012
Guillaume Laforge
 
Symfony2 Service Container: Inject me, my friend
Kirill Chebunin
 

Viewers also liked (14)

PDF
Cryptography in PHP: use cases
Enrico Zimuel
 
PDF
Foundation vs Bootstrap - CC FE & UX
JWORKS powered by Ordina
 
PDF
Follow the White Rabbit - Message Queues with PHP
Eric Rodriguez (Hiring in Lex)
 
PDF
Open a window, see the clouds - php|tek 2011
Rafael Dohms
 
PPTX
Responsive Web Design
Dhruva Krishnan
 
PPT
Realtime Communication Techniques with PHP
WaterSpout
 
KEY
Getting started with CSS frameworks using Zurb foundation
Melanie Archer
 
PPTX
Web socket with php v2
Leonardo Rifeli
 
PPTX
Socket programming with php
Elizabeth Smith
 
PDF
Phone calls and sms from php
David Stockton
 
PDF
Mobile Push Notifications
Mike Willbanks
 
PDF
MOM - Message Oriented Middleware
Peter R. Egli
 
PPT
Basic concepts of object oriented programming
Sachin Sharma
 
PDF
Angular workflow with gulp.js
Cihad Horuzoğlu
 
Cryptography in PHP: use cases
Enrico Zimuel
 
Foundation vs Bootstrap - CC FE & UX
JWORKS powered by Ordina
 
Follow the White Rabbit - Message Queues with PHP
Eric Rodriguez (Hiring in Lex)
 
Open a window, see the clouds - php|tek 2011
Rafael Dohms
 
Responsive Web Design
Dhruva Krishnan
 
Realtime Communication Techniques with PHP
WaterSpout
 
Getting started with CSS frameworks using Zurb foundation
Melanie Archer
 
Web socket with php v2
Leonardo Rifeli
 
Socket programming with php
Elizabeth Smith
 
Phone calls and sms from php
David Stockton
 
Mobile Push Notifications
Mike Willbanks
 
MOM - Message Oriented Middleware
Peter R. Egli
 
Basic concepts of object oriented programming
Sachin Sharma
 
Angular workflow with gulp.js
Cihad Horuzoğlu
 
Ad

Similar to Manage cloud infrastructures using Zend Framework 2 (and ZF1) (20)

PDF
How to Manage Cloud Infrastructures using Zend Framework
Zend by Rogue Wave Software
 
PDF
Dev & Prod - PHP Applications in the Cloud
Zend by Rogue Wave Software
 
PDF
Amazon Cloud Services and Zend Framework
Shahar Evron
 
PDF
Hybrid Cloud PHPUK2012
Combell NV
 
PDF
Develop and deploy using Hybrid Cloud Strategies confoo2012
Combell NV
 
PDF
Cloud APIs Overview Tucker
Infrastructure 2.0
 
PPT
High Availability PHP Clusters in the Cloud
RightScale
 
KEY
Defluffing Cloud Computing
Iwein Fuld
 
KEY
Developing Social Games in the Cloud
Jurriaan Persyn
 
PDF
Scalable High-Availability Session Storage with ZSCM
Zend by Rogue Wave Software
 
PPT
Cloud ppt
SamreenAkhtar8
 
PDF
Php Development In The Cloud
Ivo Jansch
 
PDF
Hopping in clouds - phpuk 17
Michele Orselli
 
PDF
A shop goes shopping - running Magento on Amazon EC2
Zend by Rogue Wave Software
 
PPT
Cloud Computing With AWS
Munish Gupta
 
PDF
The IoT Academy_awstraining_part2_aws_ec2_iaas
The IOT Academy
 
PDF
PHP and the Cloud: The view from the bazaar
vitoc
 
PDF
Hybrid cloud wiskyweb2012
Combell NV
 
PDF
PHP Architect Virtual Cloud summit
Kirsten Hunter
 
PPTX
Amazon Web Services OverView
Ariel K
 
How to Manage Cloud Infrastructures using Zend Framework
Zend by Rogue Wave Software
 
Dev & Prod - PHP Applications in the Cloud
Zend by Rogue Wave Software
 
Amazon Cloud Services and Zend Framework
Shahar Evron
 
Hybrid Cloud PHPUK2012
Combell NV
 
Develop and deploy using Hybrid Cloud Strategies confoo2012
Combell NV
 
Cloud APIs Overview Tucker
Infrastructure 2.0
 
High Availability PHP Clusters in the Cloud
RightScale
 
Defluffing Cloud Computing
Iwein Fuld
 
Developing Social Games in the Cloud
Jurriaan Persyn
 
Scalable High-Availability Session Storage with ZSCM
Zend by Rogue Wave Software
 
Cloud ppt
SamreenAkhtar8
 
Php Development In The Cloud
Ivo Jansch
 
Hopping in clouds - phpuk 17
Michele Orselli
 
A shop goes shopping - running Magento on Amazon EC2
Zend by Rogue Wave Software
 
Cloud Computing With AWS
Munish Gupta
 
The IoT Academy_awstraining_part2_aws_ec2_iaas
The IOT Academy
 
PHP and the Cloud: The view from the bazaar
vitoc
 
Hybrid cloud wiskyweb2012
Combell NV
 
PHP Architect Virtual Cloud summit
Kirsten Hunter
 
Amazon Web Services OverView
Ariel K
 
Ad

More from Enrico Zimuel (20)

PDF
Password (in)security
Enrico Zimuel
 
PDF
Integrare Zend Framework in Wordpress
Enrico Zimuel
 
PDF
Quick start on Zend Framework 2
Enrico Zimuel
 
PDF
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Enrico Zimuel
 
PDF
PHP goes mobile
Enrico Zimuel
 
PDF
Zend Framework 2
Enrico Zimuel
 
PDF
Framework software e Zend Framework
Enrico Zimuel
 
PDF
How to scale PHP applications
Enrico Zimuel
 
PDF
Velocizzare Joomla! con Zend Server Community Edition
Enrico Zimuel
 
PDF
Zend_Cache: how to improve the performance of PHP applications
Enrico Zimuel
 
PDF
XCheck a benchmark checker for XML query processors
Enrico Zimuel
 
PDF
Introduzione alle tabelle hash
Enrico Zimuel
 
PDF
Crittografia quantistica: fantascienza o realtà?
Enrico Zimuel
 
PDF
Introduzione alla crittografia
Enrico Zimuel
 
PDF
Crittografia è sinonimo di sicurezza?
Enrico Zimuel
 
PDF
Sviluppo di applicazioni sicure
Enrico Zimuel
 
PDF
Misure minime di sicurezza informatica
Enrico Zimuel
 
PDF
PHP e crittografia
Enrico Zimuel
 
PDF
La sicurezza delle applicazioni in PHP
Enrico Zimuel
 
PDF
Firma digitale
Enrico Zimuel
 
Password (in)security
Enrico Zimuel
 
Integrare Zend Framework in Wordpress
Enrico Zimuel
 
Quick start on Zend Framework 2
Enrico Zimuel
 
Introduzione alla Posta Elettronica Certificata (PEC): le regole tecniche
Enrico Zimuel
 
PHP goes mobile
Enrico Zimuel
 
Zend Framework 2
Enrico Zimuel
 
Framework software e Zend Framework
Enrico Zimuel
 
How to scale PHP applications
Enrico Zimuel
 
Velocizzare Joomla! con Zend Server Community Edition
Enrico Zimuel
 
Zend_Cache: how to improve the performance of PHP applications
Enrico Zimuel
 
XCheck a benchmark checker for XML query processors
Enrico Zimuel
 
Introduzione alle tabelle hash
Enrico Zimuel
 
Crittografia quantistica: fantascienza o realtà?
Enrico Zimuel
 
Introduzione alla crittografia
Enrico Zimuel
 
Crittografia è sinonimo di sicurezza?
Enrico Zimuel
 
Sviluppo di applicazioni sicure
Enrico Zimuel
 
Misure minime di sicurezza informatica
Enrico Zimuel
 
PHP e crittografia
Enrico Zimuel
 
La sicurezza delle applicazioni in PHP
Enrico Zimuel
 
Firma digitale
Enrico Zimuel
 

Recently uploaded (20)

PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
MuleSoft MCP Support (Model Context Protocol) and Use Case Demo
shyamraj55
 
Digital Circuits, important subject in CS
contactparinay1
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
POV_ Why Enterprises Need to Find Value in ZERO.pdf
darshakparmar
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 

Manage cloud infrastructures using Zend Framework 2 (and ZF1)

  • 1. Enrico Zimuel Zend Technologies Manage Cloud Infrastructures in PHP using Zend Framework 2 (and ZF1)
  • 2. About me • Software Engineer since 1996 – Assembly x86, C/C++, Java, Perl, PHP • Enjoying PHP since 1999 • PHP Engineer at Zend since 2008 • ZF Core Team from April 2011 • B.Sc. Computer Science and Economics from University of Pescara (Italy) • Email: [email protected]
  • 3. Summary • Cloud computing in PHP • ZendServiceRackspace • Examples • Simple Cloud API • ZendCloudInfrastructure for ZF2 and ZF1 • Adapters: Amazon Ec2, Rackspace • Examples
  • 4. Cloud computing “Cloud computing is the delivery of computing as a service rather than a product, whereby shared resources, software, and information are provided to computers and other devices as a utility over a network (tipically internet)” Wikipedia
  • 5. Cloud computing What does it means? Actually, nothing useful.
  • 6. Cloud computing Do not try to define it, just use it!
  • 7. How to use it? • API (Application Programming Interface), to interact with cloud services • Typically use REST-based APIs • Each vendors uses a property API: – Different API for each vendor – Use of specific PHP libraries (coming from community or vendors)
  • 8. Some PHP libraries for Cloud • Amazon Web Services – AWS SDK for PHP, http://aws.amazon.com/sdkforphp/ • Windows Azure – PHPAzure, http://phpazure.codeplex.com/ • Rackspace – php-cloudfiles, http://bit.ly/ptJa1Y • GoGrid – GoGridClient, http://bit.ly/o7MeLA
  • 9. ZF service classes for Cloud • ZendServiceAmazon • ZendServiceGoGrid (under development) • ZendServiceNirvanix • ZendServiceRackspace • ZendServiceWindowsAzure
  • 11. ZendServiceRackspace • Manage the following cloud services of Rackspace: – Servers – Files • Provide a full OO interface for the API of Rackspace (ver 1.0) • Release: ZF1 1.12+, ZF2 dev3+
  • 12. Example: authentication $user = 'username'; $key = 'secret key'; $rackspace = new ZendServiceRackspaceFiles($user,$key); if ($rackspace->authenticate()) { echo "Authentication successfully"; } else { printf("ERROR: %s",$rackspace->getErrorMsg()); }
  • 13. Example: store an image in a container … $container = $rackspace->createContainer('test'); if (!$rackspace->isSuccessful()) { die('ERROR: '.$rackspace->getErrorMsg()); } $name = 'example.jpg'; $file = file_get_contents($name); $metadata = array ( 'foo' => 'bar' ); $rackspace->storeObject('test',$name,$file,$metadata); if ($rackspace->isSuccessful()) { echo 'Object stored successfully'; } else { printf("ERROR: %s",$rackspace->getErrorMsg()); }
  • 14. Example: create a new instance (server) $user = 'username'; $key = 'secret key'; $rackspace = new ZendServiceRackspaceServers($user,$key); $data = array ( 'name' => 'test', 'imageId' => '49', 'flavorId' => '1', ); $server = $rackspace->createServer($data); if (!$rackspace->isSuccessful()) { die('ERROR: '.$rackspace->getErrorMsg()); } printf("Server name : %sn",$server->getName()); printf("Server Id : %sn",$server->getId()); printf("Admin password : %sn",$server->getAdminPass());
  • 16. Simple Cloud API • The Simple Cloud API is a common API for accessing cloud application services offered by multiple vendors • Starting from November 2010 the Simple Cloud API is part of Zend Framework under the classname: – Zend_Cloud (ZF1) – ZendCloud (ZF2)
  • 17. Why we need it? • Vendor lock-in – In economics, vendor lock-in makes a customer dependent on a vendor for products and services, unable to use another vendor without substantial switching costs • Portability – reuse the existing code instead of creating new code when moving software from an environment to another
  • 18. The architecture ZendCloud ZendService
  • 19. The architecture (2) ZendCloud Document Queue Storage Infrastructure ZendService
  • 20. ZendCloud as abstraction • ZendCloud is an abstraction of the main features of some cloud vendors • Vendor specific functions may not be included in ZendCloud (for portability reason) – For instance, Amazon S3 has a cleanBucket operation that is not implemented in ZendCloud • You can access the concrete adapters to use specific functions (getAdapter)
  • 21. ZendCloudDocumentService • Abstracts the interfaces to all major document databases - both in the cloud and locally deployed • Adapters: – Amazon SimpleDB – Windows Azure
  • 22. ZendCloudQueueService • The QueueService implements access to message queues available as local or remote services. • Adapters: – Amazon Sqs – Windows Azure – ZendQueue
  • 23. ZendCloudStorageService • The storage service in the Simple Cloud API implements a basic interface for file storage on the cloud • Adapters: – Amazon S3 – Windows Azure – Nirvanix – Filesystem – Rackspace (under development)
  • 25. ZendCloudInfrastructure • Manage instances (servers) of a cloud computing infrastructure • Release ZF1: 1.12+, ZF2: dev3+ • Adapters: – Amazon Ec2 – Rackspace Cloud Servers – GoGrid (under development) – Windows Azure (under development)
  • 26. Basic operations • Create a new instance • Delete an instance • Start/stop/reboot an instance • List available instances • Get the status of an instance (running, stop, etc) • Monitor an instance (CPU, RAM, Network, etc) • Deploy an instance – Execute remote shell command (using SSH2)
  • 27. Image of an instance • An image of an instance is the collection of the following information: – Operating system (OS) – Memory available (RAM) – CPU type
  • 28. Example: Ec2 Adapter use ZendCloudInfrastructureAdapterEc2 as Ec2Adapter, ZendCloudInfrastructureFactory; $key = 'key'; $secret = 'secret'; $region = 'region'; $infrastructure = Factory::getAdapter(array( Factory::INFRASTRUCTURE_ADAPTER_KEY => 'ZendCloudInfrastructureAdapterEc2', Ec2Adapter::AWS_ACCESS_KEY => $key, Ec2Adapter::AWS_SECRET_KEY => $secret, Ec2Adapter::AWS_REGION => $region, ));
  • 29. Example: create an instance $param= array ( 'imageId' => 'your-image-id', 'instanceType' => 'your-instance-type', ); $instance= $infrastructure->createInstance('name', $param); if ($instance===false) { die ('Error'); } printf ("Name of the instance: %sn", $instance->getName()); printf ("ID of the instance : %sn", $instance->getId());
  • 30. Example: reboot and wait for status if (!$infrastructure->rebootInstance('instance-id')) { die ('Error in the execution of the reboot command'); } echo 'Reboot command executed successfully'; if ($infrastructure->waitStatusInstance('instance-id', Instance::STATUS_RUNNING)) { echo 'The instance is ready'; } else { echo 'The instance is not ready yet'; }
  • 31. Wait for status change waitStatusInstance (string $id, string $status,integer $timeout=30) • Wait the status change of an instance for a maximum time of n seconds (30 by default). • Return true if the status changes as expected, false otherwise.
  • 32. Example: monitor an instance use ZendCloudInfrastructureInstance; $cpuUsage= $infrastructure->monitorInstance( 'instance-id',Instance::MONITOR_CPU); var_dump($cpuUsage); array(2) { [2] => array(2) { ["series"] => array(3) { ["timestamp"] => int(1318348920) [0]=> array(2) { ["value"] => int(60) ["timestamp"] => int(1318348800) } ["value"]=> int(80) } } ["average"] => string(3) "70%" [1]=> array(2) { } ["timestamp"] => int(1318348860) ["value"] => int(70) }
  • 33. Example: deploy an instance $nodeId= 'id-instance'; $param= array ( Instance::SSH_USERNAME => 'username', Instance::SSH_PASSWORD => 'password' ); $cmd= 'ls -la /var/www'; $output= $infrastructure->deployInstance($nodeId,$param,$cmd); echo "The files in the DocumentRoot of the $nodeId instance are:n"; print_r ($output); Note: require the SSH2 extension
  • 34. Thank you! • Vote this talk: – http://joind.in/3880 • Comments and feedbacks: – [email protected]