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