From daf0b6bc840c3e3550276fd788af90f0404706ec Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Fri, 15 Jun 2018 10:23:16 +0200 Subject: [PATCH 1/3] Expose security_group_create ansible action --- .../api/subcollections/security_groups.rb | 13 +++++++++++++ config/api.yml | 2 ++ 2 files changed, 15 insertions(+) diff --git a/app/controllers/api/subcollections/security_groups.rb b/app/controllers/api/subcollections/security_groups.rb index 07ab60f097..15c1f97de0 100644 --- a/app/controllers/api/subcollections/security_groups.rb +++ b/app/controllers/api/subcollections/security_groups.rb @@ -5,6 +5,19 @@ 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}" + task_id = queue_object_action(parent, message, :method_name => "create_security_group", :args => [data]) + 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"] diff --git a/config/api.yml b/config/api.yml index 6c07c3dd8d..c808b2373f 100644 --- a/config/api.yml +++ b/config/api.yml @@ -2537,6 +2537,8 @@ :identifier: instance_add_security_group - :name: remove :identifier: instance_remove_security_group + - :name: create + :identifier: security_group_new :subresource_actions: :get: - :name: read From 2167ee1f3dc36f85e50c1971a9216e9bb0d31197 Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Fri, 15 Jun 2018 11:06:08 +0200 Subject: [PATCH 2/3] Add special start and special stop actions --- app/controllers/api/instances_controller.rb | 26 +++++++++++++++++++++ config/api.yml | 8 +++++++ 2 files changed, 34 insertions(+) diff --git a/app/controllers/api/instances_controller.rb b/app/controllers/api/instances_controller.rb index d2f94f3df9..016e5753a0 100644 --- a/app/controllers/api/instances_controller.rb +++ b/app/controllers/api/instances_controller.rb @@ -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 diff --git a/config/api.yml b/config/api.yml index c808b2373f..f9d0812b4a 100644 --- a/config/api.yml +++ b/config/api.yml @@ -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 @@ -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 From 10176dd7e82a9f5e618b38a93acd07a4847d222b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?D=C3=A1vid=20Hal=C3=A1sz?= Date: Wed, 15 Aug 2018 10:54:56 +0200 Subject: [PATCH 3/3] Pass user_id to the security_group_create task as a 2nd argument --- app/controllers/api/subcollections/security_groups.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/subcollections/security_groups.rb b/app/controllers/api/subcollections/security_groups.rb index 15c1f97de0..7cd3f49505 100644 --- a/app/controllers/api/subcollections/security_groups.rb +++ b/app/controllers/api/subcollections/security_groups.rb @@ -11,7 +11,8 @@ def security_groups_create_resource(parent, _type, _id, data) begin raise "Cannot add #{security_group} to #{parent.name}" unless parent.supports_create_security_group? message = "Adding security group #{security_group} to #{parent.name}" - task_id = queue_object_action(parent, message, :method_name => "create_security_group", :args => [data]) + 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)