mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-06 06:41:57 +08:00
Similar to connecting, this uses a separate option. Rather than copying the connect route code to disconnect and modify it, since the majority of the route code is the same, this combines the private subnet connect and disconnect routes using a private_subnet_connection_action helper method. In order to tell the difference between postgres and private subnet ids, we need to keep in ubid format so we can check the first two characters. Add ubid typecast param and symbol matcher to support that.
74 lines
2.1 KiB
Ruby
74 lines
2.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Clover
|
|
hash_branch(:project_location_prefix, "private-subnet") do |r|
|
|
r.get api? do
|
|
private_subnet_list
|
|
end
|
|
|
|
r.on PRIVATE_SUBNET_NAME_OR_UBID do |ps_name, ps_id|
|
|
if ps_name
|
|
r.post api? do
|
|
check_visible_location
|
|
private_subnet_post(ps_name)
|
|
end
|
|
|
|
filter = {Sequel[:private_subnet][:name] => ps_name}
|
|
else
|
|
filter = {Sequel[:private_subnet][:id] => UBID.to_uuid(ps_id)}
|
|
end
|
|
|
|
filter[:location_id] = @location.id
|
|
ps = @ps = @project.private_subnets_dataset.first(filter)
|
|
check_found_object(ps)
|
|
|
|
r.post "connect" do
|
|
private_subnet_connection_action("connect", typecast_params.ubid!("connected-subnet-id"))
|
|
end
|
|
|
|
r.post "disconnect", :ubid do |ubid|
|
|
private_subnet_connection_action("disconnect", ubid)
|
|
end
|
|
|
|
r.is do
|
|
r.get do
|
|
authorize("PrivateSubnet:view", ps.id)
|
|
if api?
|
|
Serializers::PrivateSubnet.serialize(ps)
|
|
else
|
|
r.redirect ps, "/overview"
|
|
end
|
|
end
|
|
|
|
r.delete do
|
|
authorize("PrivateSubnet:delete", ps.id)
|
|
|
|
vms_dataset = ps.vms_dataset
|
|
.association_join(:strand)
|
|
.exclude(label: "destroy")
|
|
.exclude(Sequel[:vm][:id] => Semaphore
|
|
.where(
|
|
strand_id: ps.nics_dataset.select(:vm_id),
|
|
name: "destroy"
|
|
)
|
|
.select(:strand_id))
|
|
|
|
unless vms_dataset.empty?
|
|
fail DependencyError.new("Private subnet '#{ps.name}' has VMs attached, first, delete them.")
|
|
end
|
|
|
|
DB.transaction do
|
|
ps.incr_destroy
|
|
audit_log(ps, "destroy")
|
|
end
|
|
|
|
204
|
|
end
|
|
end
|
|
|
|
r.rename ps, perm: "PrivateSubnet:edit", serializer: Serializers::PrivateSubnet, template_prefix: "networking/private_subnet"
|
|
|
|
r.show_object(ps, actions: %w[overview vms networking settings], perm: "PrivateSubnet:view", template: "networking/private_subnet/show")
|
|
end
|
|
end
|
|
end
|