removing amazon keys (these have now been revoked ;-)
[p5sagit/Oyster.git] / lib / Oyster / Provision / AmazonEC2.pm
CommitLineData
5a3ac32d 1package Oyster::Provision::AmazonEC2;
2use Moose::Role;
3use Net::Amazon::EC2;
4
5requires 'config';
6
8a0402ec 7has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
58d9da66 8 die "Need api_username";
8a0402ec 9});
10has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, default => sub {
58d9da66 11 die "Need api_password";
8a0402ec 12});
13
14has ec2_oyster_key => (is => 'rw', isa => 'Str', default => "OysterDefault");
15
16sub ec2 {
17 my $self = shift;
18
19 my $ec2 = Net::Amazon::EC2->new(
20 AWSAccessKeyId => $self->api_username,
21 SecretAccessKey => $self->api_password,
22 );
23
24 my $key_pairs = $ec2->describe_key_pairs({ KeyName => $self->ec2_oyster_key });
25
26 unless(defined($key_pairs)) {
27
28 print("Creating $ec2_oyster_key key pair\n");
29 $ec2->create_key_pair({ KeyName => $self->ec2_oyster_key });
30
31 }
32
33 return $ec2;
5a3ac32d 34}
35
5a3ac32d 36sub create {
37 my $self = shift;
38
8a0402ec 39 $self->config();
5a3ac32d 40
41 # Start 1 new instance from AMI: ami-XXXXXXXX
42 my $instance = $ec2->run_instances(
8a0402ec 43 ImageId => $self->image() or "ami-1a837773",
44 KeyName => $self->ec2_oyster_key,
5a3ac32d 45 MinCount => 1,
46 MaxCount => 1,
47 );
48
49}
50
51sub delete {
52 my $self = shift;
53
54 $self->config();
55}
56
57sub resize {
58 my $self = shift;
59
60 $self->config();
61}
62
631;
64
65__END__
66
67=head1 NAME
68
69Oyster::Provision::AmazonEC2 -- Provision your Oyster on Amazon EC2
70
71=head1 SYNOPSIS
72
73Use the Rackspace backend on your Oyster configuration file
74
75=head1 REQUIRED PARAMETERS
76
77The following are required to instantiate a backend:
78
79=over
80
81=item name
82
83The name of your new/existing rackspace server.
84
8a0402ec 85pub_ssh
86
87This is a key name to pass to EC2
88
5a3ac32d 89=item size
90
91The size ID of the rackspace server you want to create.
92Use the following incantation to see them:
93
94 perl -MNet::RackSpace::CloudServers -e'
95 $r=Net::RackSpace::CloudServers->new(
96 user=>$ENV{CLOUDSERVERS_USER},
97 key=>$ENV{CLOUDSERVERS_KEY},
98 );
99 print map
100 { "id $_->{id} ram $_->{ram} disk $_->{disk}\n" }
101 $r->get_flavor_detail
102 '
103 id 1 ram 256 disk 10
104 id 2 ram 512 disk 20
105 id 3 ram 1024 disk 40
106 id 4 ram 2048 disk 80
107 id 5 ram 4096 disk 160
108 id 6 ram 8192 disk 320
109 id 7 ram 15872 disk 620
110
111=item image
112
113The image ID of the rackspace server you want to create.
114Use the following incantation to see them:
115
116 perl -MNet::RackSpace::CloudServers -e'
117 $r=Net::RackSpace::CloudServers->new(
118 user=>$ENV{CLOUDSERVERS_USER},
119 key=>$ENV{CLOUDSERVERS_KEY},
120 );
121 print map
122 { "id $_->{id} name $_->{name}\n" }
123 $r->get_image_detail
124 '
125 id 29 name Windows Server 2003 R2 SP2 x86
126 id 69 name Ubuntu 10.10 (maverick)
127 id 41 name Oracle EL JeOS Release 5 Update 3
128 id 40 name Oracle EL Server Release 5 Update 4
129 id 187811 name CentOS 5.4
130 id 4 name Debian 5.0 (lenny)
131 id 10 name Ubuntu 8.04.2 LTS (hardy)
132 id 23 name Windows Server 2003 R2 SP2 x64
133 id 24 name Windows Server 2008 SP2 x64
134 id 49 name Ubuntu 10.04 LTS (lucid)
135 id 14362 name Ubuntu 9.10 (karmic)
136 id 62 name Red Hat Enterprise Linux 5.5
137 id 53 name Fedora 13
138 id 17 name Fedora 12
139 id 71 name Fedora 14
140 id 31 name Windows Server 2008 SP2 x86
141 id 51 name CentOS 5.5
142 id 14 name Red Hat Enterprise Linux 5.4
143 id 19 name Gentoo 10.1
144 id 28 name Windows Server 2008 R2 x64
145 id 55 name Arch 2010.05
146
147Oyster only supports Linux images, specifically
148Ubuntu 10.10 (maverick).
149
150=item pub_ssh
151
152The public ssh key you would like copied to the
153new server's C</root/.ssh/authorized_keys> file
154to allow you to ssh in the box without providing
155a root password.
156
157=back
158
159=cut