0c1aaa6f8101642b9c656880c5399b0b4c6218fe
[p5sagit/Oyster.git] / lib / Oyster / Provision.pm
1 package Oyster::Provision;
2
3 use Moose;
4
5 has 'name'    => ( is => 'ro', isa => 'Str', required => 1 );
6 has 'size'    => ( is => 'ro', isa => 'Str', required => 1 );
7 has 'image'   => ( is => 'ro', isa => 'Str', required => 1 );
8 has 'pub_ssh' => ( is => 'ro', isa => 'Str', required => 1 );
9
10 has 'config'  => (is => 'rw', isa => 'HashRef', required => 1 );
11
12 sub BUILD {
13
14     my $self = shift;
15
16     if(!exists($self->config()->{provision_backend})) {
17         $self->config()->{provision_backend} = 'Oyster::Provision::Rackspace';
18     }
19     
20     my $role = $self->config()->{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