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