On Thursday 08 December 2011 15:22:08 Tomas Hrcka wrote:
---
src/app/models/instance.rb | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 738da87..279e1a7 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -129,7 +129,7 @@ class Instance < ActiveRecord::Base
validate :pool_and_account_enabled_validation, :on => :create
before_destroy :destroyable?
-
+ before_destroy :destroy_on_provider
# A user should only be able to update certain attributes, but the API
may permit other attributes to be # changed if called from another Aeolus
component, so attr_protected isn't quite what we want: USER_MUTABLE_ATTRS =
['name']
@@ -482,6 +482,18 @@ class Instance < ActiveRecord::Base
{:title => I18n.t("instances.preset_filters.pending"), :id =>
"pending", :query => where("instances.state" =>
"pending")} ]
+ def destroy_on_provider
+ begin
+ @task = self.queue_action(self.owner, 'destroy')
+ unless @task
+ raise ActionError.new("destroy cannot be performed on this
instance.") + end
+ Taskomatic.destroy_instance(@task)
+ rescue Exception => e
+ retry if self.tasks.last.action != 'destroy'
+ end
+ end
+
private
def self.apply_search_filter(search)
ACKed and pushed.