X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FOyster%2FProvision%2FAmazonEC2.pm;h=2b597c83a5f70de83596f535f685019a2caa9081;hb=3c00220f6b9513159e7e5675093bcc75631658e8;hp=0c589261d34aaca0742e71af31a4941b172c80d6;hpb=5a3ac32d32eb9312d8e6eb677c226795f53ef9f6;p=p5sagit%2FOyster.git diff --git a/lib/Oyster/Provision/AmazonEC2.pm b/lib/Oyster/Provision/AmazonEC2.pm index 0c58926..2b597c8 100644 --- a/lib/Oyster/Provision/AmazonEC2.pm +++ b/lib/Oyster/Provision/AmazonEC2.pm @@ -1,39 +1,48 @@ package Oyster::Provision::AmazonEC2; +use Carp; use Moose::Role; use Net::Amazon::EC2; 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 { + die "Need api_username"; +}); +has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, default => sub { + die "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, + my $instance = $self->ec2->run_instances( + ImageId => $self->image() or "ami-be6e99d7", + KeyName => $self->ec2_oyster_key, MinCount => 1, MaxCount => 1, ); @@ -62,7 +71,7 @@ Oyster::Provision::AmazonEC2 -- Provision your Oyster on Amazon EC2 =head1 SYNOPSIS -Use the Rackspace backend on your Oyster configuration file +Use the Amazon backend on your Oyster configuration file =head1 REQUIRED PARAMETERS @@ -74,6 +83,10 @@ The following are required to instantiate a backend: 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.