vmc-ng/lib/vmc/cli/service.rb in vmc-0.4.0.beta.91 vs vmc-ng/lib/vmc/cli/service.rb in vmc-0.4.0.beta.92

- old
+ new

@@ -25,11 +25,11 @@ "Getting services" end instances = with_progress(msg) do - client.service_instances(2) + client.service_instances(:depth => 2) end line unless quiet? if instances.empty? and !quiet? @@ -127,10 +127,12 @@ services.reject! { |s| s.provider != input[:provider] } end if input[:version] services.reject! { |s| s.version != input[:version] } + elsif !v2? + services.reject!(&:deprecated?) end if v2? && plan = input.given(:plan) services.reject! do |s| if plan.is_a?(String) @@ -191,11 +193,11 @@ :display => proc(&:name) } input(:app, :argument => true, :from_given => by_name("app"), :desc => "Application to bind to") { - ask "Which application?", :choices => client.apps(2), + ask "Which application?", :choices => client.apps(:depth => 2), :display => proc(&:name) } def bind_service app = input[:app] instance = input[:instance, app] @@ -215,23 +217,23 @@ desc "Unbind a service from an application" group :services, :manage input(:instance, :argument => true, :from_given => find_by_name("service instance"), - :desc => "Service to bind") { |app| - ask "Which service instance?", :choices => app.services, + :desc => "Service to bind") { |services| + ask "Which service instance?", :choices => services, :display => proc(&:name) } input(:app, :argument => true, - :from_given => find_by_name("app"), + :from_given => by_name("app"), :desc => "Application to bind to") { - ask "Which application?", :choices => client.apps(2), + ask "Which application?", :choices => client.apps(:depth => 2), :display => proc(&:name) } def unbind_service app = input[:app] - instance = input[:instance, app] + instance = input[:instance, app.services] with_progress( "Unbinding #{c(instance.name, :name)} from #{c(app.name, :name)}") do app.unbind(instance) end @@ -251,10 +253,16 @@ } input(:really, :type => :boolean, :forget => true, :default => proc { force? || interact }) { |name, color| ask("Really delete #{c(name, color)}?", :default => false) } + input(:unbind, :type => :boolean, :forget => true, + :default => proc { force? || interact }) { |apps| + names = human_list(apps.collect { |a| c(a.name, :name) }) + + ask("Unbind from #{names} before deleting?", :default => true) + } input :all, :type => :boolean, :default => false, :desc => "Delete all services" def delete_service if input[:all] return unless input[:really, "ALL SERVICES", :bad] @@ -268,12 +276,24 @@ instance = input[:instance] return unless input[:really, instance.name, :name] - with_progress("Deleting #{c(instance.name, :name)}") do |s| - bindings = v2? ? instance.service_bindings : [] + bindings = [] + if v2? + bindings = instance.service_bindings + + unless bindings.empty? || !input[:unbind, bindings.collect(&:app)] + bindings.each do |b| + invoke :unbind_service, :instance => instance, :app => b.app + end + + bindings = [] + end + end + + with_progress("Deleting #{c(instance.name, :name)}") do |s| if bindings.empty? instance.delete! else s.skip do apps = bindings.collect(&:app).collect { |a| b(a.name) }