Browse files

Clearer error messages

  • Loading branch information...
1 parent a01d7fd commit 075becae1afaa87661b7caa0ef54bd3a43a412dd @mfontani mfontani committed Jan 31, 2011
Showing with 23 additions and 0 deletions.
  1. +23 −0 lib/Oyster/Provision/Backend/Rackspace.pm
View
23 lib/Oyster/Provision/Backend/Rackspace.pm
@@ -26,9 +26,32 @@ sub _build_rs {
sub create {
my $self = shift;
+ die "Rackspace Provisioning backend requires a server name\n" if !defined $self->name;
+
# Do nothing if the server named $self->name already exists
return if scalar grep { $_->name eq $self->name } $self->_rs->get_server();
+ # Validate size and image
+ {
+ die "Rackspace Provisioning backend requires a server image\n" if !defined $self->image;
+ my @allowed_images = $self->_rs->get_image();
+ my $image_id = $self->image;
+ if ( !scalar grep { $_->{id} eq $image_id } @allowed_images ) {
+ die "Rackspace Provisioning backend requires a valid image id\nValid images:\n",
+ (map { sprintf("id %-10s -- %s\n", $_->{id}, $_->{name}) } @allowed_images),
+ "\n";
+ }
+
+ die "Rackspace Provisioning backend requires a server size\n" if !defined $self->size;
+ my @allowed_flavors = $self->_rs->get_flavor();
+ my $flavor_id = $self->size;
+ if ( !scalar grep { $_->{id} eq $flavor_id } @allowed_flavors ) {
+ die "Rackspace Provisioning backend requires a valid size id\nValid flavors:\n",
+ (map { sprintf("id %-10s -- %s\n", $_->{id}, $_->{name}) } @allowed_flavors),
+ "\n";
+ }
+ }
+
# Check the ssh pub key exists and is <10K
die "SSH pubkey needs to exist" if !-f $self->pub_ssh;
my $pub_ssh = do {

0 comments on commit 075beca

Please sign in to comment.