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