Skip to content

Commit

Permalink
Expose CloudSubnet creation
Browse files Browse the repository at this point in the history
With this commit we allow user to create CloudSubnet via API.
Example request:

```
POST /api/providers/4/cloud_subnets HTTP/1.1
{
	"action": "create",
	"resource": {
		"router_ref": "aae5c1ff-9860-4a56-bb01-e936a7086f5a",

		"name": "My New Cloud Subnet",
		"address": "130.130.130.0",
		"netmask": "255.255.255.0",
		"gateway": "130.130.130.1"
	}
}
```

Signed-off-by: Miha Pleško <miha.plesko@xlab.si>
  • Loading branch information
miha-plesko committed Jul 31, 2018
1 parent 73b98a3 commit 2efe8b2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions app/controllers/api/subcollections/cloud_subnets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ module CloudSubnets
def cloud_subnets_query_resource(object)
object.respond_to?(:cloud_subnets) ? Array(object.cloud_subnets) : []
end

def cloud_subnets_create_resource(parent, _type, _id, data = {})
data.deep_symbolize_keys!
raise 'Must specify a name for the subnet' unless data[:name]

begin
message = "Creating subnet #{data[:name]}"
task_id = queue_object_action(parent, message, :method_name => "create_cloud_subnet", :args => [data])
action_result(true, message, :task_id => task_id)
rescue StandardError => e
action_result(false, e.to_s)
end
end
end
end
end
3 changes: 3 additions & 0 deletions config/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@
:get:
- :name: read
:identifier: cloud_subnet_show_list
:post:
- :name: create
:identifier: cloud_subnet_new
:subresource_actions:
:get:
- :name: read
Expand Down

0 comments on commit 2efe8b2

Please sign in to comment.