Sunday, 22 November 2009

CloudServers Perl module - 0.09_10

perl -E'say join " ", reverse world, hello' # :)


I've finally found some time to play again with the Rackspace API manual, and added a couple features to the Net-RackSpace-CloudServers module I hadn't touched since moving home some months ago.


The project is semi-alive on http://github.com/mfontani/Net-RackSpace-CloudServers/, and the latest 0.09_10 development version should be on CPAN soon.


It's basically a one-to-one adaptation of the Rackspace API document available at http://www.rackspacecloud.com/cloud_hosting_products/servers/api.


On the scripts/ directory there are some examples on how to use the module: it's possible to list all images, flavors, and servers you own, as well as delete servers by ID or create new servers in what I think is quite a simple syntax.


As an example, let's delete that pesky server whose ID's 666:

 
use strict; use warnings; use Net::RackSpace::CloudServers;
my $cs = Net::RackSpace::CloudServers->new(
user => $ENV{'CLOUDSERVERS_USER'},
key => $ENV{'CLOUDSERVERS_KEY'},
);
my @servers = $CS->get_server_detail;
my $srv_666 = ( grep { $_->id == 666 } @servers )[0];
die "No such server id 666\n" if ( !defined $srv_666 );
$srv_666->delete_server(); # dies in case of error
print "Server #666 deleted\n";


On a branch not on Github yet, I'm working on an App::Cmd interface to it, as well.


Any comments at all would be truly appreciated, as this is my first module I'm trying to get on CPAN ;)


Till soon,

-marco-

No comments:

Post a Comment

Post a Comment