api_{username,password} belong in the roles
[p5sagit/Oyster.git] / lib / Oyster / Provision.pm
1 package Oyster::Provision;
2
3 use Moose;
4
5 has 'name'    => ( is => 'ro', isa => 'Str');
6 has 'size'    => ( is => 'ro', isa => 'Str');
7 has 'image'   => ( is => 'ro', isa => 'Str');
8 has 'pub_ssh' => ( is => 'ro', isa => 'Str');
9 has 'config'  => ( is => 'rw', isa => 'HashRef', required => 1 );
10 has 'provision_backend'  => (is => 'rw', isa => 'Str', required => 1, default => 'Oyster::Provision::Rackspace' );
11
12 # TODO after provision, add the server's name with "oyster-" prefixed to the
13 # user's ~/.ssh/ssh_config file so any part of Oyster can ssh there
14 # passwordlessly for deploying or whatnot
15
16 sub BUILD {
17
18     my $self = shift;
19
20     my $role = $self->provision_backend;
21
22     eval "use $role";
23     "$role"->meta->apply($self);
24 }
25
26 1;
27
28 __END__
29
30 =head1 NAME
31
32 Oyster::Provision - Provision an Oyster
33
34 =head1 SYNOPSIS
35
36     my $server = Oyster::Provision->new(
37         name => 'Ostrica',
38         size => '256',
39         image => 'Meerkat',
40         pub_ssh => "$ENV{HOME}/.ssh/id_rsa.pub",
41     );
42     $server->create;
43
44 =head1 BACKENDS
45
46 By default, the L<Oyster::Provision::Rackspace> backend
47 will be used.
48
49 Each backend needs to accept at least the C<name>,
50 C<size>, C<image> and C<pub_ssh> parameters. The meaning
51 of these parameters may differ from one backend to another.
52
53 =head1 METHOS
54
55 Each backend usually implements the following C<required>
56 methods:
57
58 =over
59
60 =item create
61
62 Creates a new server by given name, if such server does
63 not exist.
64
65 Installs the required packages for the distribution
66
67 =item delete
68
69 Gets rid of the server instance
70
71 =item resize
72
73 Hopefully scales the server
74
75 =back
76
77 =cut