Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Nubilus Perl

822 views

Published on

Una panoramica su Net::Amazon::EC2 e Net::RackSpace::Servers. Potete trovare la presentazione con le note qui: http://polettix.s3.amazonaws.com/IPW2011/nubilus-perl-1.1-note.pdf

Published in: Technology
  • Be the first to like this

Nubilus Perl

  1. 1. Nubilus PerlLibrerie Perl in the cloud
  2. 2. IaaS - PaaS - SaaS 2
  3. 3. IaaS - PaaS - SaaS 2
  4. 4. Amazon
  5. 5. require Net::Amazon::EC2;my $ec2 = Net::Amazon::EC2->new( AWSAccessKeyId => YOUR-AWS-KEY, SecretAccessKey => YOUR-AWS-SECRET,);
  6. 6. require Net::Amazon::EC2;my $ec2 = Net::Amazon::EC2->new( AWSAccessKeyId => YOUR-AWS-KEY, SecretAccessKey => YOUR-AWS-SECRET,);
  7. 7. my $res = $ec2->run_instances( ImageId => ami-8c1fece5, MinCount => 1, MaxCount => 1, SecurityGroup => quick-start-1, InstanceType => m1.small,);
  8. 8. Instance
  9. 9. my $res = $ec2->run_instances( ImageId => ami-8c1fece5, MinCount => 1, MaxCount => 1, SecurityGroup => quick-start-1, InstanceType => m1.small,);
  10. 10. Instance
  11. 11. Image Instance
  12. 12. Image Instance#!/usr/bin/env perl 10715 gnome-terminaluse strict; 10719 _ gnome-pty-helperuse warnings; 10720 _ bashuse 5.012; 24910 _ bash 32549 _ bashmy $message = shift 27438 | _ perl prg.pl || whatever!; 27444 _ bashwhile (necessary) { 27462 | _ perl prg.pl hey you! say $message; 27463 _ bash sleep 1; 27480 | _ perl prg.pl another}
  13. 13. my $res = $ec2->run_instances( ImageId => ami-8c1fece5, MinCount => 1, MaxCount => 1, SecurityGroup => quick-start-1, InstanceType => m1.small,);
  14. 14. Image Instance#!/usr/bin/env perl 10715 gnome-terminaluse strict; 10719 _ gnome-pty-helperuse warnings; 10720 _ bashuse 5.012; 24910 _ bash 32549 _ bashmy $message = shift 27438 | _ perl prg.pl || whatever!; 27444 _ bashwhile (necessary) { 27462 | _ perl prg.pl hey you! say $message; 27463 _ bash sleep 1; 27480 | _ perl prg.pl another}
  15. 15. Image Instance Type
  16. 16. my $res = $ec2->run_instances( ImageId => ami-8c1fece5, MinCount => 1, MaxCount => 1, SecurityGroup => quick-start-1, InstanceType => m1.small,);
  17. 17. RUNNING_CHECK:while (necessary) { my $reservations = $ec2->describe_instances() || []; foreach my $res (@$reservations) { foreach my $instance ($res->instances_set()) { if ($instance->{instance_state}{name} eq running) { say active, IP: , $instance->{ip_address}; last RUNNING_CHECK; } } } sleep 1;}
  18. 18. RUNNING_CHECK:while (necessary) { my $reservations = $ec2->describe_instances() || []; foreach my $res (@$reservations) { foreach my $instance ($res->instances_set()) { if ($instance->{instance_state}{name} eq running) { say active, IP: , $instance->{ip_address}; last RUNNING_CHECK; } } } sleep 1;}
  19. 19. Ora?
  20. 20. Beh... PRIMA...
  21. 21. Sì, SSH
  22. 22. my $res = $ec2->run_instances( RUNNING_CHECK: ImageId => ami-8c1fece5, while (necessary) { MinCount => 1, my $reservations MaxCount => 1, = $ec2->describe_instances() || []; SecurityGroup => quick-start-1, InstanceType => m1.small, foreach my $res (@$reservations) {); #... my $instance_id = $res->instance_id(); $ec2->terminate_instances( InstanceId => $instance_id, );
  23. 23. my $reservations = $ec2->describe_instances() || [];foreach my $res (@$reservations) { foreach my $instance ($res->instances_set()) { my $state = $instance->{instance_state}{name}; # ... utilizzare $state... }}
  24. 24. RackSpace
  25. 25. require Net::RackSpace::CloudServers;my $cs = Net::RackSpace::CloudServers->new( user => myusername, key => mysecretkey, location => UK,);
  26. 26. require Net::RackSpace::CloudServers;my $cs = Net::RackSpace::CloudServers->new( user => YOUR-CS-USERNAME, key => YOUR-CS-SECRETKEY, location => UK,);
  27. 27. require Net::RackSpace::CloudServers;my $cs = Net::RackSpace::CloudServers->new( user => YOUR-CS-USERNAME, key => YOUR-CS-SECRETKEY, location => UK,);
  28. 28. my $server = Net::RackSpace::CloudServers::Server->new( cloudservers => $cs, # N::R::CloudServers instance name => my-instance, imageid => 4, # Debian 5.0 (lenny) flavorid => 1, # basic server, 256 MB RAM);
  29. 29. Image Instance Type
  30. 30. Image Server Flavor
  31. 31. Ancora niente
  32. 32. my $real_server = $server->create_server();my $root_pass = $real_server->adminpass();
  33. 33. Ora sì
  34. 34. my $id = $real_server->id();RUNNING_CHECK:while (necessary) { my $instance = $cs->get_server($id); say completion status: , $server->progress(); if ($server->status eq ACTIVE) { say active, IP: , $instance->public_address()->[0]; last RUNNING_CHECK; } sleep 1;}
  35. 35. my $id = $real_server->id();RUNNING_CHECK:while (necessary) { my $instance = $cs->get_server($id); say completion status: , $server->progress(); if ($server->status eq ACTIVE) { say active, IP: , $instance->public_address()->[0]; last RUNNING_CHECK; } sleep 1;}
  36. 36. Ora?SSH con $root_pass
  37. 37. O anche...
  38. 38. Sì... root password via email
  39. 39. my $server = Net::RackSpace::CloudServers::Server->new( cloudservers => $cs, # N::R::CloudServers instance name => my-instance, imageid => 4, # Debian 5.0 (lenny) flavorid => 1, # basic server, 256 MB RAM personality => [ { path => /root/.ssh/authorized_keys2, contents => <<END_OF_BASE64SUlKckNyZWIxcU5NcGxuS1BIaFBBdFIxL2RMUVJ6SnNzSnNxTWUwRENlbXp5NlVMZ0g3Uy9seWZU...anExQWhSaE1zK0FHaDZDL01aV1N4QStZNmhqd2wwMFozSVl1R3AgaW1wb3J0ZWQtb3BlbnNzaC1rZXkKEND_OF_BASE64 }, ],);
  40. 40. Chiave SSH
  41. 41. $real_server->delete();
  42. 42. Adieu
  43. 43. 46

×