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