From: hakim Date: Sat, 20 Nov 2010 19:10:51 +0000 (+0000) Subject: provision defaults X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=45bec3869f4bbacc7d522b8a683bbd52d837ff3d;p=p5sagit%2FOyster.git provision defaults --- diff --git a/lib/Dist/Zilla/App/Command/provision.pm b/lib/Dist/Zilla/App/Command/provision.pm index e5a8837..001edad 100644 --- a/lib/Dist/Zilla/App/Command/provision.pm +++ b/lib/Dist/Zilla/App/Command/provision.pm @@ -8,6 +8,7 @@ BEGIN { use Dist::Zilla::App -command; use Moose; use Config::Any; +use Hash::Merge 'merge'; sub abstract { 'provision a new Oyster VM' } @@ -24,21 +25,25 @@ sub execute { or die "No name provided!"; my @config_files = ( './oyster.conf' ); # TODO make configurable - 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 "; + + my %hash = @hashes > 1 ? %{ merge( @hashes ) } : $hashes[0]; + + $hash{provision_backend} = delete $hash{type} || 'Rackspace'; + $hash{pub_ssh} ||= "$ENV{HOME}/.ssh/id_rsa.pub"; + $hash{size} ||= 128; + $hash{image} ||= 'meerkat'; # TODO, should this be determined on backend? 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, + %hash, ); $server->create; print "Instance $name created! ($server)\n"; diff --git a/oyster.conf b/oyster.conf index 98f1bc7..d20abd1 100644 --- a/oyster.conf +++ b/oyster.conf @@ -1,7 +1,20 @@ + + type Rackspace + username foo + password baz + size 256 + + type Rackspace username foo password baz + + type Rackspace + username foo + password baz + size 512 +