Files
ubicloud/rhizome/host/bin/setup-vm
Maciek Sarnowicz 82ce73988c Rhizome part - Retaining bursting limits after VM restart
Vm restart was simply calling systemctl directly and that was wiping out the cpu burst limit from a cgroup settings. Those settings are not persisted anywhere and have to be re-set every time the service restarts. This was handled for the host restart, but not for the VM restart.

To fix, I added a new method in the vm_setup and call it from setup-vm master script. The nexus will call that script.
2025-02-19 09:20:28 -08:00

111 lines
3.2 KiB
Ruby
Executable File

#!/bin/env ruby
# frozen_string_literal: true
require "json"
require_relative "../lib/vm_setup"
unless (action = ARGV.shift)
puts "expected action as argument"
exit 1
end
unless (vm_name = ARGV.shift)
puts "expected path to vm_name as argument"
exit 1
end
vm_setup = VmSetup.new(vm_name)
if action == "delete"
vm_setup.purge
exit 0
end
if action == "delete_keep_net"
vm_setup.purge_without_network
exit 0
end
if action == "delete_net"
vm_setup.purge_network
vm_setup.purge_user
exit 0
end
params = JSON.parse(File.read(VmPath.new(vm_name).prep_json))
begin
# "Global Unicast" subnet, i.e. a subnet for exchanging packets with
# the internet.
gua = params.fetch("public_ipv6")
ip4 = params.fetch("public_ipv4")
local_ip4 = params.fetch("local_ipv4")
unix_user = params.fetch("unix_user")
ssh_public_keys = params.fetch("ssh_public_keys")
nics = params.fetch("nics").map { |args| VmSetup::Nic.new(*args) }.freeze
max_vcpus = params.fetch("max_vcpus")
cpu_topology = params.fetch("cpu_topology")
mem_gib = params.fetch("mem_gib")
ndp_needed = params.fetch("ndp_needed", false)
storage_volumes = params.fetch("storage_volumes")
swap_size_bytes = params["swap_size_bytes"]
pci_devices = params.fetch("pci_devices", [])
boot_image = params.fetch("boot_image")
dns_ipv4 = params.fetch("dns_ipv4")
slice_name = params.fetch("slice_name", "system.slice")
cpu_percent_limit = params.fetch("cpu_percent_limit", 0)
cpu_burst_percent_limit = params.fetch("cpu_burst_percent_limit", 0)
rescue KeyError => e
puts "Needed #{e.key} in parameters json"
exit 1
end
case action
when "prep"
secrets = JSON.parse($stdin.read)
unless (storage_secrets = secrets["storage"])
puts "need storage secrets in secrets json"
exit 1
end
vm_setup.prep(unix_user, ssh_public_keys, nics, gua, ip4,
local_ip4, max_vcpus, cpu_topology, mem_gib,
ndp_needed, storage_volumes, storage_secrets, swap_size_bytes,
pci_devices, boot_image, dns_ipv4,
slice_name, cpu_percent_limit, cpu_burst_percent_limit)
when "recreate-unpersisted"
secrets = JSON.parse($stdin.read)
unless (storage_secrets = secrets["storage"])
puts "need storage secrets in secrets json"
exit 1
end
vm_setup.recreate_unpersisted(
gua, ip4, local_ip4, nics, mem_gib,
ndp_needed, storage_volumes, storage_secrets, dns_ipv4,
pci_devices, slice_name, cpu_burst_percent_limit,
multiqueue: max_vcpus > 1
)
when "reinstall-systemd-units"
vm_setup.install_systemd_unit(
max_vcpus, cpu_topology, mem_gib, storage_volumes, nics,
pci_devices, slice_name, cpu_percent_limit, cpu_burst_percent_limit
)
when "reassign-ip6"
secrets = JSON.parse($stdin.read)
unless (storage_secrets = secrets["storage"])
puts "need storage secrets in secrets json"
exit 1
end
vm_setup.reassign_ip6(unix_user, ssh_public_keys, nics, gua, ip4,
local_ip4, max_vcpus, cpu_topology, mem_gib,
ndp_needed, storage_volumes, storage_secrets,
swap_size_bytes, pci_devices, boot_image, dns_ipv4,
slice_name, cpu_percent_limit, cpu_burst_percent_limit)
when "restart"
vm_setup.restart(slice_name, cpu_burst_percent_limit)
else
puts "Invalid action #{action}"
exit 1
end