3 package Dist::Zilla::App::Command::provision;
5 $Dist::Zilla::App::Command::provision::VERSION = '0.1';
7 # ABSTRACT: provision a new Oyster VM
8 use Dist::Zilla::App -command;
11 use Hash::Merge 'merge';
12 Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' );
13 use Oyster::Provision;
15 sub abstract { 'provision a new Oyster VM' }
18 [ 'name=s' => 'the name of the VM to create' ],
19 [ 'config=s' => 'the name of the config file to use, default ./oyster.conf' ],
23 my ($self, $opt, $arg) = @_;
25 my $zilla = $self->zilla;
28 or die "No virtual machine name provided!";
29 my @config_files = ($opt->name or './oyster.conf');
31 my $cfg = Config::Any->load_files({ files => \@config_files, use_ext => 0 });
32 ($cfg) = values %{ $cfg->[0] }; # FIX with ::JFDI or similar
34 my $Provision = $cfg->{Provision} or die "No <Provision> section";
36 my @hashes = grep $_, $Provision->{Default}, $Provision->{$name}
37 or die "No section for <Provision> <$name>, and no <default>";
39 warn Dumper(\@hashes);
41 my %hash = @hashes > 1 ? %{ merge( @hashes ) } : %{ $hashes[0] };
43 my $type = delete $hash{type} || 'Oyster::Provision::Rackspace';
44 $hash{provision_backend} = $type =~/^Oyster::Provision::/ ? $type : "Oyster::Provision::$type";
45 $hash{pub_ssh} ||= "$ENV{HOME}/.ssh/id_rsa.pub";
46 $hash{size} ||= 1; # id 1 - ram 256 MiB - disk 10 GiB
47 $hash{image} ||= 69; # id 69 - Ubuntu 10.10 (meerkat)
49 use Data::Dumper; warn "Config hash: ", Dumper(\%hash);
51 my $server = Oyster::Provision->new(
57 print "Instance $name created! ($server)\n";
67 Dist::Zilla::App::Command::provision - provision a new Oyster VM
81 =head1 COPYRIGHT AND LICENSE
83 This software is copyright (c) 2010 by CONTRIBUTORS
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.