Files
ubicloud/model/nic.rb
Furkan Sahin f7c6ca7c03 Move nic gateway setting to vm_setup rhizome changes
Nic gateway setup is the most crucial piece in ipv4 networking setup.
Most of that work already is happenning in vm_setup. Keeping this piece
in controlplane doesn't make sense. Therefore, I am moving it to the
proper place.

This will require migration of prep.json files, which is fine and will
be handled at the time of deployment for existing VMs.

This commit essentially adds the rhizome part, the deployment will
require to first deploy this, wait and continue the removal of gateway
setup from the control plane, which is the next commit.
2024-11-07 09:24:29 +01:00

39 lines
966 B
Ruby

# frozen_string_literal: true
require_relative "../model"
class Nic < Sequel::Model
many_to_one :private_subnet
many_to_one :vm
one_to_many :src_ipsec_tunnels, key: :src_nic_id, class: :IpsecTunnel
one_to_many :dst_ipsec_tunnels, key: :dst_nic_id, class: :IpsecTunnel
one_to_one :strand, key: :id
plugin :association_dependencies, src_ipsec_tunnels: :destroy, dst_ipsec_tunnels: :destroy
include ResourceMethods
include SemaphoreMethods
semaphore :destroy, :start_rekey, :trigger_outbound_update,
:old_state_drop_trigger, :setup_nic, :repopulate, :lock
plugin :column_encryption do |enc|
enc.column :encryption_key
end
def self.ubid_to_name(ubid)
ubid.to_s[0..7]
end
def ubid_to_tap_name
ubid.to_s[0..9]
end
def private_ipv4_gateway
private_subnet.net4.nth(1).to_s + private_subnet.net4.netmask.to_s
end
def unlock
Semaphore.where(strand_id: strand.id, name: "lock").delete(force: true)
end
end