Permalink
Browse files

attempting to fix ::Provision

  • Loading branch information...
1 parent 3f4fb54 commit a9e65ceef2ae9d568156215f278436c53fd2a80d hakim committed Nov 20, 2010
@@ -9,6 +9,7 @@ use Dist::Zilla::App -command;
use Moose;
use Config::Any;
use Hash::Merge 'merge';
+Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );
use Oyster::Provision;
sub abstract { 'provision a new Oyster VM' }
@@ -34,6 +35,8 @@ sub execute {
my @hashes = grep $_, $Provision->{Default}, $Provision->{$name}
or die "No section for <Provision> <$name>, and no <default>";
+ warn Dumper(\@hashes);
+
my %hash = @hashes > 1 ? %{ merge( @hashes ) } : %{ $hashes[0] };
my $type = delete $hash{type} || 'Oyster::Provision::Rackspace';
@@ -42,9 +45,10 @@ sub execute {
$hash{size} ||= 1; # id 1 - ram 256 MiB - disk 10 GiB
$hash{image} ||= 69; # id 69 - Ubuntu 10.10 (meerkat)
+ warn Dumper(\%hash); use Data::Dumper;
+
my $server = Oyster::Provision->new(
name => $name,
- config => \%hash,
%hash,
);
$server->create;
View
@@ -2,23 +2,20 @@ package Oyster::Provision;
use Moose;
-has 'name' => ( is => 'ro', isa => 'Str', required => 1 );
-has 'size' => ( is => 'ro', isa => 'Str', required => 1 );
-has 'image' => ( is => 'ro', isa => 'Str', required => 1 );
-has 'pub_ssh' => ( is => 'ro', isa => 'Str', required => 1 );
-
-has 'config' => (is => 'rw', isa => 'HashRef', required => 1 );
+has 'api_username' => ( is => 'ro', isa => 'Str');
+has 'api_password' => ( is => 'ro', isa => 'Str');
+has 'name' => ( is => 'ro', isa => 'Str');
+has 'size' => ( is => 'ro', isa => 'Str');
+has 'image' => ( is => 'ro', isa => 'Str');
+has 'pub_ssh' => ( is => 'ro', isa => 'Str');
+has 'provision_backend' => (is => 'rw', isa => 'Str', required => 1, default => 'Oyster::Provision::Rackspace' );
sub BUILD {
my $self = shift;
- if(!exists($self->config()->{provision_backend})) {
- $self->config()->{provision_backend} = 'Oyster::Provision::Rackspace';
- }
+ my $role = $self->provision_backend;
- my $role = $self->config()->{provision_backend};
-
eval "use $role";
"$role"->meta->apply($self);
}
@@ -3,14 +3,19 @@ use Carp;
use Moose::Role;
use Net::Amazon::EC2;
-requires 'config';
+has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1);
+sub _build_api_username {
+ my $self = shift;
+ return $ENV{CLOUDSERVERS_USER} if exists $ENV{CLOUDSERVERS_USER};
+ die "Need api_username or CLOUDSERVERS_USER in environment";
+}
-has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
- die "Need api_username";
-});
-has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
- die "Need api_password";
-});
+has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1);
+sub _build_api_password {
+ my $self = shift;
+ return $ENV{CLOUDSERVERS_KEY} if exists $ENV{CLOUDSERVERS_KEY};
+ die "Need api_password or CLOUDSERVERS_KEY in environment";
+}
has ec2_oyster_key => (is => 'rw', isa => 'Str', default => "OysterDefault");
@@ -26,7 +31,7 @@ sub ec2 {
unless(defined($key_pairs)) {
- print("Creating $self->ec2_oyster_key key pair\n");
+ printf("Creating %s pair\n", $self->ec2_oyster_key);
$ec2->create_key_pair({ KeyName => $self->ec2_oyster_key });
}
@@ -37,11 +42,9 @@ sub ec2 {
sub create {
my $self = shift;
- $self->config();
-
# Start 1 new instance from AMI: ami-XXXXXXXX
my $instance = $self->ec2->run_instances(
- ImageId => $self->image() or "ami-be6e99d7",
+ ImageId => $self->image() || "ami-be6e99d7",
KeyName => $self->ec2_oyster_key,
MinCount => 1,
MaxCount => 1,
@@ -52,7 +55,6 @@ sub create {
sub delete {
my $self = shift;
- $self->config();
}
sub resize {
@@ -9,13 +9,15 @@ requires 'config';
has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1);
sub _build_api_username {
return $ENV{CLOUDSERVERS_USER} if exists $ENV{CLOUDSERVERS_USER};
- die "Need api_username or CLOUDSERVERS_USER in environment";
+ return $self->config->{api_username}
+ or die "Need api_username or CLOUDSERVERS_USER in environment";
}
has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1);
sub _build_api_password {
return $ENV{CLOUDSERVERS_KEY} if exists $ENV{CLOUDSERVERS_KEY};
- die "Need api_password or CLOUDSERVERS_KEY in environment";
+ return $self->config->{api_password}
+ or die "Need api_password or CLOUDSERVERS_KEY in environment";
}
has '_rs' => ( is => 'rw', isa => 'Net::RackSpace::CloudServers', default => sub {

0 comments on commit a9e65ce

Please sign in to comment.