has 'image' => ( is => 'ro', isa => 'Str', required => 1 );
has 'pub_ssh' => ( is => 'ro', isa => 'Str', required => 1 );
-
-sub config {
- return {provision_backend => 'Oyster::Provision::Rackspace'};
-}
+has 'config' => (is => 'rw', isa => 'HashRef', required => 1 );
sub BUILD {
my $self = shift;
+ if(!exists($self->config()->{provision_backend})) {
+ $self->config()->{provision_backend} = 'Oyster::Provision::Rackspace';
+ }
+
my $role = $self->config()->{provision_backend};
eval "use $role";
requires 'config';
-my $ec2_image_id = "ami-1a837773";
-my $ec2_username = "AKIAJXSD25MPWFYTQWIQ";
-my $ec2_password = "m76s9DyoXrHdpVy8HkhjgD0RAjy14bhkQ5Zts/gg";
-
-my $ec2 = Net::Amazon::EC2->new(
- AWSAccessKeyId => $ec2_username,
- SecretAccessKey => $ec2_password,
-);
-
-my $ec2_oyster_key = "OysterDefault";
-my $key_pairs = $ec2->describe_key_pairs({ KeyName => $ec2_oyster_key });
-
-unless(defined($key_pairs)) {
-
- print("Creating $ec2_oyster_key key pair\n");
- $ec2->create_key_pair({ KeyName => $ec2_oyster_key });
-
+has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
+ return "AKIAJXSD25MPWFYTQWIQ";
+ confess "Need api_username";
+});
+has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
+ return "m76s9DyoXrHdpVy8HkhjgD0RAjy14bhkQ5Zts/gg";
+ confess "Need api_password";
+});
+
+has ec2_oyster_key => (is => 'rw', isa => 'Str', default => "OysterDefault");
+
+sub ec2 {
+ my $self = shift;
+
+ my $ec2 = Net::Amazon::EC2->new(
+ AWSAccessKeyId => $self->api_username,
+ SecretAccessKey => $self->api_password,
+ );
+
+ my $key_pairs = $ec2->describe_key_pairs({ KeyName => $self->ec2_oyster_key });
+
+ unless(defined($key_pairs)) {
+
+ print("Creating $ec2_oyster_key key pair\n");
+ $ec2->create_key_pair({ KeyName => $self->ec2_oyster_key });
+
+ }
+
+ return $ec2;
}
-
sub create {
my $self = shift;
- $self->config();
-
+ $self->config();
# Start 1 new instance from AMI: ami-XXXXXXXX
my $instance = $ec2->run_instances(
- ImageId => $ec2_image_id,
- KeyName => $ec2_oyster_key,
+ ImageId => $self->image() or "ami-1a837773",
+ KeyName => $self->ec2_oyster_key,
MinCount => 1,
MaxCount => 1,
);
The name of your new/existing rackspace server.
+pub_ssh
+
+This is a key name to pass to EC2
+
=item size
The size ID of the rackspace server you want to create.
return $ENV{CLOUDSERVERS_USER} if exists $ENV{CLOUDSERVERS_USER};
confess "Need api_username or CLOUDSERVERS_USER in environment";
});
-has 'api_key' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
+
+has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
return $ENV{CLOUDSERVERS_KEY} if exists $ENV{CLOUDSERVERS_KEY};
- confess "Need api_key or RACKSPACE_KEY in environment";
+ confess "Need api_password or CLOUDSERVERS_KEY in environment";
});
has '_rs' => ( is => 'rw', isa => 'Net::RackSpace::CloudServers', default => sub {
my $self = shift;
my $rs = Net::RackSpace::CloudServers->new(
user => $self->api_username,
- key => $self->api_key,
+ key => $self->api_password,
);
$rs;
});
-sub BUILD {
+after BUILD => sub {
my $self = shift;
# get api username and key from config?
my $config = $self->config;
+
+
+
# ...
}
The rackspace API username, or C<$ENV{RACKSPACE_USER}> will be used if that is
not given
-=item api_key
+=item password
+
+This is your rackspace API Key
The rackspace API key, or C<$ENV{RACKSPACE_KEY}> will be used if that is not
given