Signed-off-by: Scott Seago sseago@redhat.com --- src/app/models/instance.rb | 5 +++-- src/app/models/instance_task.rb | 34 ++++++++++++++++++---------------- 2 files changed, 21 insertions(+), 18 deletions(-)
diff --git a/src/app/models/instance.rb b/src/app/models/instance.rb index bc2acb7..cd1dd1c 100644 --- a/src/app/models/instance.rb +++ b/src/app/models/instance.rb @@ -19,9 +19,10 @@ class Instance < ActiveRecord::Base validates_presence_of :flavor_id validates_presence_of :image_id
+ STATE_NEW = "new" STATE_PENDING = "pending" STATE_RUNNING = "running" - STATE_TERMINATED = "terminated" - STATE_FIXME = "tbd" + STATE_SHUTTING_DOWN = "shutting_down" + STATE_STOPPED = "stopped" # what about newly created instances? end diff --git a/src/app/models/instance_task.rb b/src/app/models/instance_task.rb index 99b164b..d13c902 100644 --- a/src/app/models/instance_task.rb +++ b/src/app/models/instance_task.rb @@ -78,27 +78,28 @@ class InstanceTask < Task end end
- def self.valid_actions_for_instance_state(state, instance=nil, user=nil) + # FIXME: sort out pending_state issue w/ instance here including + # automatic transitions from transient states. + def self.valid_actions_for_instance_state(state, instance, user=nil) actions = [] - ACTIONS.each do |action, hash| - if hash[:start] == state + transitions = c.instance_state(state).transitions + transitions. + tra + 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 + # FIXME: check permissions here if we filter actions by permission end - actions << action if add_action + actions << transition.action if add_action end end actions end
- def self.action_privilege(action) - return ACTIONS[action].nil? ? nil : ACTIONS[action][:privilege][0] - end - # FIXME: this may not be needed if all action privileges are based on the pool - def self.action_privilege_object(action, obj) - return ACTIONS[action].nil? ? nil : obj.portal_pool - end def self.action_label(action) return ACTIONS[action][:label] end @@ -109,11 +110,12 @@ class InstanceTask < Task return [action_label(action), action, action_icon(action)] end
+ # FIXME: need to pass in provider to filter start and destroy out for ec2 def self.get_instance_actions - return [label_and_action(InstanceTask::ACTION_START), - label_and_action(InstanceTask::ACTION_STOP), - label_and_action(InstanceTask::ACTION_REBOOT_VM), - label_and_action(InstanceTask::ACTION_DESTROY)] + return [["Start", InstanceTask::ACTION_START], + ["Stop", InstanceTask::ACTION_STOP], + ["Reboot", InstanceTask::ACTION_REBOOT_VM], + ["Destroy", InstanceTask::ACTION_DESTROY]] end
# FIXME: most of these go away when ovirt model leaves
deltacloud-devel@lists.fedorahosted.org