You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltacloud.apache.org by ma...@apache.org on 2013/06/28 11:06:33 UTC

[4/9] git commit: EC2 driver - Fix for determining instance_actions on ebs/root_store instances

EC2 driver - Fix for determining instance_actions on ebs/root_store instances

https://github.com/deltacloud/deltacloud-core/pull/47


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/fd92d39d
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/fd92d39d
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/fd92d39d

Branch: refs/heads/master
Commit: fd92d39d4efd9491322697a54950fc0685518015
Parents: 6307f26
Author: marios <ma...@redhat.com>
Authored: Tue Jun 18 12:31:59 2013 +0300
Committer: marios <ma...@redhat.com>
Committed: Fri Jun 28 12:05:50 2013 +0300

----------------------------------------------------------------------
 server/lib/deltacloud/drivers/base_driver.rb       |  2 +-
 server/lib/deltacloud/drivers/ec2/ec2_driver.rb    | 16 ++++++++++++----
 server/lib/deltacloud/helpers/deltacloud_helper.rb |  2 +-
 3 files changed, 14 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fd92d39d/server/lib/deltacloud/drivers/base_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/base_driver.rb b/server/lib/deltacloud/drivers/base_driver.rb
index 439f099..8fa58b2 100644
--- a/server/lib/deltacloud/drivers/base_driver.rb
+++ b/server/lib/deltacloud/drivers/base_driver.rb
@@ -135,7 +135,7 @@ module Deltacloud
       self.class.instance_state_machine
     end
 
-    def instance_actions_for(state, instance = nil)
+    def instance_actions_for(state, params={})
       actions = []
       states = instance_state_machine.states()
       current_state = states.find{|e| e.name == state.underscore.to_sym }

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fd92d39d/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
index fdc282b..cc3878a 100644
--- a/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
+++ b/server/lib/deltacloud/drivers/ec2/ec2_driver.rb
@@ -137,9 +137,9 @@ module Deltacloud
 
         end
 
-        def instance_actions_for(state, instance = nil)
-          if instance
-            ebs = (instance[:root_device_type] == "ebs") ? true : false
+        def instance_actions_for(state, params={})
+          unless params.empty?
+            ebs = is_ebs_instance?(params)
           end
           actions = []
           states = instance_state_machine.states()
@@ -1084,6 +1084,14 @@ module Deltacloud
           type == 'ebs' ? 'persistent' : 'transient'
         end
 
+        #params: {:image_id => 123, :persistent_image=>true, :credentials => creds}
+        def is_ebs_instance?(params)
+          return params[:persistent_image] unless params[:persistent_image].nil?
+          (image(params[:credentials], {:id=>params[:image_id]}).root_type == "persistent") ? true : false
+        end
+
+
+
         def convert_instance(instance)
           can_create_image = 'ebs'.eql?(instance[:root_device_type]) and 'RUNNING'.eql?(convert_state(instance[:aws_state]))
           inst_profile_opts={}
@@ -1100,7 +1108,7 @@ module Deltacloud
             :state => convert_state(instance[:aws_state]),
             :image_id => instance[:aws_image_id],
             :owner_id => instance[:aws_owner],
-            :actions => instance_actions_for(convert_state(instance[:aws_state]), instance),
+            :actions => instance_actions_for(convert_state(instance[:aws_state]), {:persistent_image => (instance[:root_device_type] == "ebs")}),
             :keyname => instance[:ssh_key_name],
             :launch_time => instance[:aws_launch_time],
             :instance_profile => InstanceProfile.new(instance[:aws_instance_type], inst_profile_opts),

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/fd92d39d/server/lib/deltacloud/helpers/deltacloud_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/deltacloud/helpers/deltacloud_helper.rb b/server/lib/deltacloud/helpers/deltacloud_helper.rb
index 2b5d347..64f68f8 100644
--- a/server/lib/deltacloud/helpers/deltacloud_helper.rb
+++ b/server/lib/deltacloud/helpers/deltacloud_helper.rb
@@ -150,7 +150,7 @@ module Deltacloud::Helpers
 
       # If original instance doesn't include called action
       # return with 405 error (Method is not Allowed)
-      unless driver.instance_actions_for(original_instance.state).include?(name.to_sym)
+      unless driver.instance_actions_for(original_instance.state, {:image_id=>original_instance.image_id, :credentials=>credentials}).include?(name.to_sym)
         return report_error(405)
       end