I've tested create, start, reboot, and stop with the mock driver. Destroy currently fails. rhevm and ec2 testing to come later.
Signed-off-by: Scott Seago sseago@redhat.com --- src/app/controllers/instance_controller.rb | 17 ++++++++++++++++ src/app/models/instance.rb | 29 ++++++++++++++++++++++++++++ src/app/models/instance_task.rb | 23 ++++++++++++--------- src/app/models/portal_pool.rb | 4 ++- src/app/views/instance/show.html.erb | 12 +++++++++- src/app/views/portal_pool/show.html.erb | 10 ++++++++- src/task-omatic/taskomatic_instance.rb | 10 +++++--- 7 files changed, 87 insertions(+), 18 deletions(-)
diff --git a/src/app/controllers/instance_controller.rb b/src/app/controllers/instance_controller.rb index 32d5e3f..42b1cb8 100644 --- a/src/app/controllers/instance_controller.rb +++ b/src/app/controllers/instance_controller.rb @@ -37,6 +37,23 @@ class InstanceController < ApplicationController end end
+ def instance_action + action = params[:instance_action] + action_args = params[:action_data] + @instance = Instance.find(params[:id]) + unless @instance.valid_action?(action) + raise ActionError.new("#{action} is an invalid action.") + end + #permissons check here + @task = @instance.queue_action(get_login_user, action, action_args) + unless @task + raise ActionError.new("#{action} cannot be performed on this instance.") + end + alert = "#{@instance.name}: #{action} was successfully queued." + flash[:notice] = alert + redirect_to :action => 'show', :id => @instance.portal_pool_id + end + def delete end
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index 6234b91..4ce0459 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -29,4 +29,33 @@ class Instance < ActiveRecord::Base :in => [STATE_NEW, STATE_PENDING, STATE_RUNNING, STATE_SHUTTING_DOWN, STATE_STOPPED]
+ def get_action_list(user=nil) + # return empty list rather than nil + # FIXME: not handling pending state now -- only current state + return_val = InstanceTask.valid_actions_for_instance_state(state, + self, + user) || [] + # filter actions based on quota + # FIXME: not doing quota filtering now + return_val + end + + # Provide method to check if requested action exists, so caller can decide + # if they want to throw an error of some sort before continuing + # (ie in service api) + def valid_action?(action) + return get_action_list.include?(action) ? true : false + end + + def queue_action(user, action, data = nil) + return false unless get_action_list.include?(action) + task = InstanceTask.new({ :user => user, + :task_target => self, + :action => action, + :args => data}) + task.save! + return task + end + + end diff --git a/src/app/models/instance_task.rb b/src/app/models/instance_task.rb index 9f32217..cd55d91 100644 --- a/src/app/models/instance_task.rb +++ b/src/app/models/instance_task.rb @@ -42,17 +42,20 @@ class InstanceTask < Task # automatic transitions from transient states. def self.valid_actions_for_instance_state(state, instance, user=nil) actions = [] - transitions = c.instance_state(state).transitions - transitions.each do |transition| - # FIXME if we allow actions based on the expected state after - # automatic transitions, we need to call this method again with - # the state from transition.to passed in. - unless transition.action.nil? - add_action = true - if (instance and user) - # FIXME: check permissions here if we filter actions by permission + c_state = instance.portal_pool.cloud_account.connect.instance_state(state) + if c_state + transitions = c_state.transitions + transitions.each do |transition| + # FIXME if we allow actions based on the expected state after + # automatic transitions, we need to call this method again with + # the state from transition.to passed in. + unless transition.action.nil? + add_action = true + if (instance and user) + # FIXME: check permissions here if we filter actions by permission + end + actions << transition.action if add_action end - actions << transition.action if add_action end end actions diff --git a/src/app/models/portal_pool.rb b/src/app/models/portal_pool.rb index 675a5ce..206d88e 100644 --- a/src/app/models/portal_pool.rb +++ b/src/app/models/portal_pool.rb @@ -34,7 +34,9 @@ class PortalPool < ActiveRecord::Base unless Image.find_by_external_key_and_provider_id(image.id, cloud_account.provider.id) ar_image = Image.new(:external_key => image.id, - :name => image.description ? image.description : image.id, + :name => image.name ? image.name : + (image.description ? image.description : + image.id), :architecture => image.architecture, :provider_id => cloud_account.provider.id) ar_image.save! diff --git a/src/app/views/instance/show.html.erb b/src/app/views/instance/show.html.erb index 1327ef5..2a550d8 100644 --- a/src/app/views/instance/show.html.erb +++ b/src/app/views/instance/show.html.erb @@ -11,11 +11,19 @@ <tbody> <%@instances.each {|instance| %> <tr> - <td></td> + <td> + <%instance.get_action_list.each {|action|%> + <%= link_to action, :controller => "instance", + :action => "instance_action", + :id => instance, + :instance_action => action %> + <br/> + <% } %> + </td> <td><div><%= instance.name %></div></td> </tr> <% } %> </tbody> </table> <% end %> -<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%> \ No newline at end of file +<%= link_to "Add a new instance", :controller => "instance", :action => "new", :id => @pool, :provider => @provider%> diff --git a/src/app/views/portal_pool/show.html.erb b/src/app/views/portal_pool/show.html.erb index 8dd06f5..2a550d8 100644 --- a/src/app/views/portal_pool/show.html.erb +++ b/src/app/views/portal_pool/show.html.erb @@ -11,7 +11,15 @@ <tbody> <%@instances.each {|instance| %> <tr> - <td></td> + <td> + <%instance.get_action_list.each {|action|%> + <%= link_to action, :controller => "instance", + :action => "instance_action", + :id => instance, + :instance_action => action %> + <br/> + <% } %> + </td> <td><div><%= instance.name %></div></td> </tr> <% } %> diff --git a/src/task-omatic/taskomatic_instance.rb b/src/task-omatic/taskomatic_instance.rb index 05186e3..0dfe903 100644 --- a/src/task-omatic/taskomatic_instance.rb +++ b/src/task-omatic/taskomatic_instance.rb @@ -21,13 +21,15 @@ require 'taskomatic_task' def dcloud_to_instance_state(state_str) case state_str when 'PENDING' - return InstanceTask::STATE_PENDING + return Instance::STATE_PENDING when 'RUNNING' - return InstanceTask::STATE_RUNNING + return Instance::STATE_RUNNING when 'STOPPED' - return InstanceTask::STATE_STOPPED + return Instance::STATE_STOPPED + when 'SHUTTING_DOWN' + return Instance::STATE_SHUTTING_DOWN else - return InstanceTask::STATE_PENDING + return Instance::STATE_PENDING end end
deltacloud-devel@lists.fedorahosted.org