Tuesday, 8 December 2009

Cloud laziness part 1: creating a CloudServers server instance

The following is ongoing on my private branch of the CPAN dist Net::RackSpace::CloudServers, in which I'm creating an App::Cmd interface to the module:

okram@bluedesk: (with_app_cmd)
~/GIT/Net-RackSpace-CloudServers$ perl cloudservers.pl create \
--name=mfapitest --imagename karmic --flavorname 256 --verbose
Server name: mfapitest
Image id 14362 named Ubuntu 9.10 (karmic)
Flavor id 1 named 256 server
Creating new server...
Created server ID 124999
root password: mfapitestXXXXXXX
Public IP:
Private IP:
Server status: ACTIVE progress: 100..
Server now available!

The same is indeed doable with the sample scripts/newserver.pl in the dist -- and I also need to use scripts/deleteserver.pl to destroy the test instance -- but I assume that a command-line interface may be useful in the longer term to scale up/down specific instances, create N new servers in a shared IP group, or destroy no longer needed instances.

The command was pretty painless to write, and most of it was the validate_args routine...

As usual, comments would be much appreciated!

Till soon,


Sunday, 29 November 2009

Git - inhibit commit if modules don't compile

Sometimes I forget to run Perl base tests for my modules, before committing changes. As to what happens, I end up committing something that doesn't quite compile ;)

Luckily Git has a pre-commit hook one can use to run at least the "compile" tests.

The following aborts the commit if the t/00*.t tests (usually the "do all modules compile?" tests) in the repository don't run correctly:

~$ cat .git/hooks/pre-commit
# Runs modules' "compiles" tests before committing
# Dies (halting commit) if they don't compile
print "pre-commit => testing..\n";
do {qx{
prove -Ilib t/00*.t
}} or die <<'DIEMSG';
pre-commit => ERRORS:
print "pre-commit => test OK\n";

This is an example of a 00-load.t file, that can literally be dropped-in the t/ directory:

use strict;
use warnings;
use Test::More;
use File::Find::Rule;

my @files = File::Find::Rule->name('*.pm')->in('lib');
plan tests => ~ ~ @files;

for (@files) {

eval "require $_; 1",
"loaded $_ with no problems",

File::Find::Rule is one of the golden gems found on CPAN, rclamp++!

Till soon,

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(
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,