Files
ubicloud/model/vm_pool.rb
Enes Cakir ffbba37b9f Move out the underlying VM and IPv4 from the customer's project
The underlying VM and IPv4 are currently associated with the customer's
project. This means:
-  Customers can view and interact with the VM and private subnet
-  The billing records for the VM and IPv4 are generated within the
   customer's project.

We have decided to disassociate these underlying resources from the
customer's project. As a result:
-  Customers will no longer see these VMs on the "Compute" page; they
   will only see the runners on the "GitHub Runners" page.
-  We will bill them at a separate rate for GitHub runner usage, not for
   the underlying resources.

We source GitHub runner machines in two ways: by provisioning a fresh
VM, and from the VM pool.

1. Currently, new VMs are provisioned in the customer's project. With
   the new patch, new VMs will be provisioned in the GitHub runner
   service project, and the underlying VM and IPv4 will have a billing
   record there. The customer's project will have a billing record
   solely for the GitHub runners. We can monitor the cost of underlying
   resources at the GitHub runner service project.

2. Currently, if a VM is selected from the pool, we disassociate the VM
   from the VM pool service project and associate it with the customer's
   project. We then finalize active billing records and create new ones.
   With the new patch, we will not transfer the VM from the VM pool
   service project to the customer's project. The underlying resources
   will remain in the service project for their entire lifecycle. We
   will create a new billing record for the GitHub runner in the
   customer's project. I didn't not transfer the VM from the VM pool
   service project to the GitHub runner service project as it adds +20
   lines and I see no value in doing so.
2023-11-14 14:43:18 +03:00

26 lines
671 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class VmPool < Sequel::Model
one_to_one :strand, key: :id
one_to_many :vms, key: :pool_id
include ResourceMethods
include SemaphoreMethods
semaphore :destroy
def pick_vm
DB.transaction do
# first lock the whole pool in the join table so that no other thread can
# pick a vm from this pool
vms_dataset.for_update.all
pick_vm_id_q = vms_dataset.left_join(:github_runner, vm_id: :id)
.where(Sequel[:github_runner][:vm_id] => nil, Sequel[:vm][:display_state] => "running")
.select(Sequel[:vm][:id])
Vm.where(id: pick_vm_id_q).first
end
end
end