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