mirror of
https://github.com/ubicloud/ubicloud.git
synced 2025-10-05 22:31:57 +08:00
Previously, project_id and subject_id needed to be a uuid, and object_id could be a uuid or ubid. This allows accepting an object for all three. This simplifies almost all callers of these methods. It also doesn't require either parsing a ubid or generating a ubid. Previously, even if a uuid was given, it would turn it into a ubid in order to extract the class, and guess ApiKey if it was an et ubid.
67 lines
1.5 KiB
Ruby
67 lines
1.5 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 = @vm = @project.vms_dataset.first(filter)
|
|
check_found_object(vm)
|
|
|
|
r.get true do
|
|
authorize("Vm:view", vm)
|
|
|
|
if api?
|
|
Serializers::Vm.serialize(vm, {detailed: true})
|
|
else
|
|
r.redirect vm, "/overview"
|
|
end
|
|
end
|
|
|
|
r.delete true do
|
|
authorize("Vm:delete", vm)
|
|
|
|
DB.transaction do
|
|
vm.incr_destroy
|
|
audit_log(vm, "destroy")
|
|
end
|
|
|
|
204
|
|
end
|
|
|
|
r.rename vm, perm: "Vm:edit", serializer: Serializers::Vm, template_prefix: "vm"
|
|
|
|
r.show_object(vm, actions: %w[overview networking settings], perm: "Vm:view", template: "vm/show")
|
|
|
|
r.post "restart" do
|
|
authorize("Vm:edit", vm)
|
|
|
|
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 vm, "/settings"
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|