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