As expected by backend
[p5sagit/Oyster.git] / lib / Dist / Zilla / App / Command / provision.pm
CommitLineData
4aedd3bb 1use strict;
2use warnings;
3package Dist::Zilla::App::Command::provision;
4BEGIN {
5 $Dist::Zilla::App::Command::provision::VERSION = '0.1';
6}
7# ABSTRACT: release your dist to the CPAN
8use Dist::Zilla::App -command;
9use Moose;
10use Config::Any;
45bec386 11use Hash::Merge 'merge';
4aedd3bb 12
13sub abstract { 'provision a new Oyster VM' }
14
15sub opt_spec {
919b8f96 16 [ 'name=s' => 'the name of the VM to create' ],
4aedd3bb 17}
18
19sub execute {
20 my ($self, $opt, $arg) = @_;
21
22 my $zilla = $self->zilla;
23
24 my $name = $opt->name
25 or die "No name provided!";
26 my @config_files = ( './oyster.conf' ); # TODO make configurable
27
45bec386 28 my $cfg = Config::Any->load_files({ files => \@config_files, use_ext => 0 });
4aedd3bb 29 ($cfg) = values %{ $cfg->[0] }; # FIX with ::JFDI or similar
30
31 my $Provision = $cfg->{Provision} or die "No <Provision> section";
4aedd3bb 32
45bec386 33 my @hashes = grep $_, $Provision->{Default}, $Provision->{$name}
34 or die "No section for <Provision> <$name>, and no <default>";
35
36 my %hash = @hashes > 1 ? %{ merge( @hashes ) } : $hashes[0];
37
cb52ec3a 38 $hash{provision_backend} = delete $hash{type} || 'Oyster::Provision::Rackspace';
45bec386 39 $hash{pub_ssh} ||= "$ENV{HOME}/.ssh/id_rsa.pub";
a1486321 40 $hash{size} ||= 1; # id 1 - ram 256 MiB - disk 10 GiB
41 $hash{image} ||= 69; # id 69 - Ubuntu 10.10 (meerkat)
4aedd3bb 42
43 use Oyster::Provision;
44 my $server = Oyster::Provision->new(
45 name => $name,
cb52ec3a 46 config => \%hash,
45bec386 47 %hash,
4aedd3bb 48 );
49 $server->create;
50 print "Instance $name created! ($server)\n";
51}
52
531;
54
55__END__
56=pod
57
58=head1 NAME
59
60Dist::Zilla::App::Command::provision - provision a new Oyster VM
61
62=head1 VERSION
63
64version 0.1
65
66=head1 SYNOPSIS
67
68 TODO
69
70=head1 AUTHOR
71
72CONTRIBUTORS
73
74=head1 COPYRIGHT AND LICENSE
75
76This software is copyright (c) 2010 by CONTRIBUTORS
77
78This is free software; you can redistribute it and/or modify it under
79the same terms as the Perl 5 programming language system itself.
80
81=cut
82