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