1 package Oyster::Provision::Rackspace;
4 use Net::RackSpace::CloudServers;
5 use Net::RackSpace::CloudServers::Server;
10 has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1);
11 sub _build_api_username {
12 return $ENV{CLOUDSERVERS_USER} if exists $ENV{CLOUDSERVERS_USER};
13 confess "Need api_username or CLOUDSERVERS_USER in environment";
16 has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1);
17 sub _build_api_password {
18 return $ENV{CLOUDSERVERS_KEY} if exists $ENV{CLOUDSERVERS_KEY};
19 confess "Need api_password or CLOUDSERVERS_KEY in environment";
22 has '_rs' => ( is => 'rw', isa => 'Net::RackSpace::CloudServers', default => sub {
24 my $rs = Net::RackSpace::CloudServers->new(
25 user => $self->api_username,
26 key => $self->api_password,
33 # get api username and key from config?
34 my $config = $self->config;
44 # Do nothing if the server named $self->name already exists
45 return if scalar grep { $_->name eq $self->name } $self->_rs->get_server();
47 # Check the ssh pub key exists and is <10K
48 confess "SSH pubkey needs to exist" if !-f $self->pub_ssh;
51 open my $fh, '<', $self->pub_ssh or die "Cannot open ", $self->pub_ssh, ": $!";
53 close $fh or die "Cannot close ", $self->pub_ssh, ": $!";
56 confess "SSH pubkey needs to be < 10KiB" if length $pub_ssh > 10*1024;
59 my $server = Net::RackSpace::CloudServers::Server->new(
60 cloudservers => $self->_cs,
62 flavor => $self->size,
63 image => $self->image,
66 path => $self->pub_ssh,
67 contents => encode_base64($pub_ssh),
71 $server->create_server;
73 warn "Server public IP is: ", ($server->public_address)[0], "\n";
74 warn "Server root password: ", $server->adminpass, "\n";
76 # Connect to server and execute installation routines?
83 # Die if the server named $self->name already exists
84 my ($server) = grep { $_->name eq $self->name } $self->_rs->get_server();
85 confess "No such server: ", $self->name if !$server;
88 $server->delete_server();
103 Oyster::Provision::Rackspace -- Provision your Oyster on Rackspace
107 Use the Rackspace backend on your Oyster configuration file
109 =head1 REQUIRED PARAMETERS
111 The following are required to instantiate a backend:
117 The rackspace API username, or C<$ENV{RACKSPACE_USER}> will be used if that is
122 This is your rackspace API Key
124 The rackspace API key, or C<$ENV{RACKSPACE_KEY}> will be used if that is not
129 The name of your new/existing rackspace server.
133 The size ID of the rackspace server you want to create.
134 Use the following incantation to see them:
136 perl -MNet::RackSpace::CloudServers -e'
137 $r=Net::RackSpace::CloudServers->new(
138 user=>$ENV{CLOUDSERVERS_USER},
139 key=>$ENV{CLOUDSERVERS_KEY},
142 { "id $_->{id} ram $_->{ram} disk $_->{disk}\n" }
143 $r->get_flavor_detail
147 id 3 ram 1024 disk 40
148 id 4 ram 2048 disk 80
149 id 5 ram 4096 disk 160
150 id 6 ram 8192 disk 320
151 id 7 ram 15872 disk 620
155 The image ID of the rackspace server you want to create.
156 Use the following incantation to see them:
158 perl -MNet::RackSpace::CloudServers -e'
159 $r=Net::RackSpace::CloudServers->new(
160 user=>$ENV{CLOUDSERVERS_USER},
161 key=>$ENV{CLOUDSERVERS_KEY},
164 { "id $_->{id} name $_->{name}\n" }
167 id 29 name Windows Server 2003 R2 SP2 x86
168 id 69 name Ubuntu 10.10 (maverick)
169 id 41 name Oracle EL JeOS Release 5 Update 3
170 id 40 name Oracle EL Server Release 5 Update 4
171 id 187811 name CentOS 5.4
172 id 4 name Debian 5.0 (lenny)
173 id 10 name Ubuntu 8.04.2 LTS (hardy)
174 id 23 name Windows Server 2003 R2 SP2 x64
175 id 24 name Windows Server 2008 SP2 x64
176 id 49 name Ubuntu 10.04 LTS (lucid)
177 id 14362 name Ubuntu 9.10 (karmic)
178 id 62 name Red Hat Enterprise Linux 5.5
182 id 31 name Windows Server 2008 SP2 x86
183 id 51 name CentOS 5.5
184 id 14 name Red Hat Enterprise Linux 5.4
185 id 19 name Gentoo 10.1
186 id 28 name Windows Server 2008 R2 x64
187 id 55 name Arch 2010.05
189 Oyster only supports Linux images, specifically
190 Ubuntu 10.10 (maverick).
194 The public ssh key you would like copied to the
195 new server's C</root/.ssh/authorized_keys> file
196 to allow you to ssh in the box without providing