From: Jan Provaznik <jprovazn(a)redhat.com>
For ec2 and openstack an instance disappears after it's stopped.
So marking such instances as stopped may be better than mark them as vanished.
https://www.aeolusproject.org/redmine/issues/3879
---
src/app/models/instance.rb | 11 +++++++++++
src/app/models/provider_type.rb | 10 ++++++++++
src/dbomatic/dbomatic | 6 ++++++
3 files changed, 27 insertions(+)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb
index 8579379..95f62c7 100644
--- a/src/app/models/instance.rb
+++ b/src/app/models/instance.rb
@@ -594,6 +594,17 @@ class Instance < ActiveRecord::Base
instance_key.destroy if instance_key
end
+ def stop_request_queued?
+ task = tasks.last
+ task && task.action == InstanceTask::ACTION_STOP &&
+ task.state == Task::STATE_FINISHED
+ end
+
+ def disappears_after_stop_request?
+ provider_account &&
+ provider_account.provider.provider_type.stopped_instances_disappear?
+ end
+
private
def self.apply_search_filter(search)
diff --git a/src/app/models/provider_type.rb b/src/app/models/provider_type.rb
index 4557d62..1e44038 100644
--- a/src/app/models/provider_type.rb
+++ b/src/app/models/provider_type.rb
@@ -46,4 +46,14 @@ class ProviderType < ActiveRecord::Base
def goes_to_stop_after_creation?
%w(rhevm vsphere).include?(deltacloud_driver)
end
+
+ # for ec2 a stopped instance automatically disappears after some time
+ # (a few minutes)
+ # for openstack an instance is automatically deleted (by dc-core)
+ # when sending a stop request. So a running instances which was stopped
+ # disappears from provider almost immediately w/o passing through
+ # shutting_down/stopped states
+ def stopped_instances_disappear?
+ %w(openstack ec2).include?(deltacloud_driver)
+ end
end
diff --git a/src/dbomatic/dbomatic b/src/dbomatic/dbomatic
index 7b46d2a..edccac6 100755
--- a/src/dbomatic/dbomatic
+++ b/src/dbomatic/dbomatic
@@ -218,6 +218,12 @@ def check_one_account(account)
end
# Only update the instance / create an event if anything has changed!
instance.save! if instance.changed?
+ elsif instance.stop_request_queued? &&
instance.disappears_after_stop_request?
+ # some providers (openstack, ec2) delete stopped instances
+ # so it probably makes sense to consider vanished instances, which
+ # we sent stop request to, as stopped
+ DBomaticLogger.instance.info("known instance missing from provider but stop
request was sent before, marking #{instance.name} as stopped")
+ instance.update_attribute(:state, Instance::STATE_STOPPED)
else
# We have an instance in our database, but it didn't come back over the API
DBomaticLogger.instance.info("known instance missing from provider:
#{instance.name} #{instance.external_key}")
--
1.7.11.4