X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDist%2FZilla%2FApp%2FCommand%2Fprovision.pm;h=1c0abfe4134a009bc07a129ae5738145f09f9e6f;hb=739d62d647dd5546c92971027782d7850e09ddfb;hp=1b355a6035bb7a76bdb94d0240f5391ed6d3ab9e;hpb=4aedd3bbc6229c5bcbc927ced6470fea743c520a;p=p5sagit%2FOyster.git diff --git a/lib/Dist/Zilla/App/Command/provision.pm b/lib/Dist/Zilla/App/Command/provision.pm index 1b355a6..1c0abfe 100644 --- a/lib/Dist/Zilla/App/Command/provision.pm +++ b/lib/Dist/Zilla/App/Command/provision.pm @@ -4,15 +4,19 @@ package Dist::Zilla::App::Command::provision; BEGIN { $Dist::Zilla::App::Command::provision::VERSION = '0.1'; } -# ABSTRACT: release your dist to the CPAN +# ABSTRACT: provision a new Oyster VM use Dist::Zilla::App -command; use Moose; use Config::Any; +use Hash::Merge 'merge'; +Hash::Merge::set_behavior( 'RIGHT_PRECEDENT' ); +use Oyster::Provision; sub abstract { 'provision a new Oyster VM' } sub opt_spec { - [ 'name|s' => 'the name of the VM to create' ], + [ 'name=s' => 'the name of the VM to create' ], + [ 'config=s' => 'the name of the config file to use, default ./oyster.conf' ], } sub execute { @@ -21,24 +25,33 @@ sub execute { my $zilla = $self->zilla; my $name = $opt->name - or die "No name provided!"; - my @config_files = ( './oyster.conf' ); # TODO make configurable + or die "No virtual machine name provided!"; + my @config_files = ($opt->name or './oyster.conf'); - my $cfg = Config::Any->load_files({ files => \@config_files }); + my $cfg = Config::Any->load_files({ files => \@config_files, use_ext => 0 }); ($cfg) = values %{ $cfg->[0] }; # FIX with ::JFDI or similar my $Provision = $cfg->{Provision} or die "No section"; - my $target = $Provision->{$name} or die "No section for <$name>"; - my $type = $target->{type} || 'EC2'; + my @hashes = grep $_, $Provision->{Default}, $Provision->{$name} + or die "No section for <$name>, and no "; + + warn Dumper(\@hashes); + + my %hash = @hashes > 1 ? %{ merge( @hashes ) } : %{ $hashes[0] }; + + my $type = delete $hash{type} || 'Oyster::Provision::Rackspace'; + $hash{provision_backend} = $type =~/^Oyster::Provision::/ ? $type : "Oyster::Provision::$type"; + $hash{pub_ssh} ||= "$ENV{HOME}/.ssh/id_rsa.pub"; + $hash{size} ||= 1; # id 1 - ram 256 MiB - disk 10 GiB + $hash{image} ||= 69; # id 69 - Ubuntu 10.10 (meerkat) + + use Data::Dumper; warn "Config hash: ", Dumper(\%hash); - use Oyster::Provision; my $server = Oyster::Provision->new( name => $name, - size => '256', - image => 'Meerkat', - pub_ssh => "$ENV{HOME}/.ssh/id_rsa.pub", - provision_backend => $type, + config => \%hash, + %hash, ); $server->create; print "Instance $name created! ($server)\n";