mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-07 15:21:58 +08:00
This uses a shared route for all 6 objects, as well as shared cli and sdk code. Unfortunately, there is not a way to share such code in openapi.yml, so that part ends up quite verbose. Eventually, we should add a web interface for this, but it's best to wait until we refactor the web interfaces for the objects to consistently use the current postgres web interface.
61 lines
1.4 KiB
Ruby
61 lines
1.4 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Clover
|
|
hash_branch(:project_location_prefix, "vm") do |r|
|
|
r.get api? do
|
|
vm_list_api_response(vm_list_dataset)
|
|
end
|
|
|
|
r.on VM_NAME_OR_UBID do |vm_name, vm_ubid|
|
|
if vm_name
|
|
r.post api? do
|
|
check_visible_location
|
|
vm_post(vm_name)
|
|
end
|
|
|
|
filter = {Sequel[:vm][:name] => vm_name}
|
|
else
|
|
filter = {Sequel[:vm][:id] => UBID.to_uuid(vm_ubid)}
|
|
end
|
|
|
|
filter[:location_id] = @location.id
|
|
vm = @project.vms_dataset.first(filter)
|
|
check_found_object(vm)
|
|
|
|
r.get true do
|
|
authorize("Vm:view", vm.id)
|
|
@vm = vm
|
|
api? ? Serializers::Vm.serialize(vm, {detailed: true}) : view("vm/show")
|
|
end
|
|
|
|
r.delete true do
|
|
authorize("Vm:delete", vm.id)
|
|
|
|
DB.transaction do
|
|
vm.incr_destroy
|
|
audit_log(vm, "destroy")
|
|
end
|
|
|
|
204
|
|
end
|
|
|
|
r.rename vm, perm: "Vm:edit", serializer: Serializers::Vm
|
|
|
|
r.post "restart" do
|
|
authorize("Vm:edit", vm.id)
|
|
|
|
DB.transaction do
|
|
vm.incr_restart
|
|
audit_log(vm, "restart")
|
|
end
|
|
|
|
if api?
|
|
Serializers::Vm.serialize(vm, {detailed: true})
|
|
else
|
|
flash["notice"] = "'#{vm.name}' will be restarted in a few seconds"
|
|
r.redirect path(vm)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|