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' }
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';
$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;
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);
}
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");
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 });
}
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,
sub delete {
my $self = shift;
- $self->config();
}
sub resize {
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 {