Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEMO] Notifications for ansible operations #450

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions app/controllers/api/instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,32 @@ def terminate_resource(type, id = nil, _data = nil)
end
end

def special_stop_resource(type, id = nil, _data = nil)
raise BadRequestError, "Must specify an id for stopping a #{type} resource" unless id

api_action(type, id) do |klass|
instance = resource_search(id, type, klass)
api_log_info("Stopping #{instance_ident(instance)}")

result = validate_instance_for_action(instance, "stop")
result = stop_instance(instance) if result[:success]
result
end
end

def special_start_resource(type, id = nil, _data = nil)
raise BadRequestError, "Must specify an id for starting a #{type} resource" unless id

api_action(type, id) do |klass|
instance = resource_search(id, type, klass)
api_log_info("Starting #{instance_ident(instance)}")

result = validate_instance_for_action(instance, "start")
result = start_instance(instance) if result[:success]
result
end
end

def stop_resource(type, id = nil, _data = nil)
raise BadRequestError, "Must specify an id for stopping a #{type} resource" unless id

Expand Down
14 changes: 14 additions & 0 deletions app/controllers/api/subcollections/security_groups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ def security_groups_query_resource(object)
object.respond_to?(:security_groups) ? Array(object.security_groups) : []
end

def security_groups_create_resource(parent, _type, _id, data)
security_group = data["name"]

begin
raise "Cannot add #{security_group} to #{parent.name}" unless parent.supports_create_security_group?
message = "Adding security group #{security_group} to #{parent.name}"
user_id = User.current_user.id
task_id = queue_object_action(parent, message, :method_name => "create_security_group", :args => [data, user_id])
action_result(true, message, :task_id => task_id)
rescue => e
action_result(false, e.to_s)
end
end

def security_groups_add_resource(parent, _type, _id, data)
security_group = data["name"]

Expand Down
10 changes: 10 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,10 @@
:identifier: instance_show_list
- :name: terminate
:identifier: instance_terminate
- :name: special_stop
:identifier: instance_stop
- :name: special_start
:identifier: instance_start
- :name: stop
:identifier: instance_stop
- :name: start
Expand All @@ -1510,6 +1514,10 @@
:post:
- :name: terminate
:identifier: instance_terminate
- :name: special_stop
:identifier: instance_stop
- :name: special_start
:identifier: instance_start
- :name: stop
:identifier: instance_stop
- :name: start
Expand Down Expand Up @@ -2537,6 +2545,8 @@
:identifier: instance_add_security_group
- :name: remove
:identifier: instance_remove_security_group
- :name: create
:identifier: security_group_new
:subresource_actions:
:get:
- :name: read
Expand Down