We were using vm's allocated_at field to progress NicNexus to the next label. This is problemmatic because VM can get allocated and subnet can be triggered to rekey before nic strand switches states because of nap 5. Semaphores on the other hand, wakes the strand up the moment it is incremented. Therefore, the new way simply switches the state before subnet gets the signal.
60 lines
1.9 KiB
Ruby
60 lines
1.9 KiB
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, :vm_allocated
|
|
|
|
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
|
|
|
|
# Table: nic
|
|
# Columns:
|
|
# id | uuid | PRIMARY KEY
|
|
# private_subnet_id | uuid | NOT NULL
|
|
# mac | macaddr | NOT NULL
|
|
# created_at | timestamp with time zone | NOT NULL DEFAULT now()
|
|
# private_ipv4 | cidr | NOT NULL
|
|
# private_ipv6 | cidr | NOT NULL
|
|
# vm_id | uuid |
|
|
# encryption_key | text |
|
|
# name | text | NOT NULL
|
|
# rekey_payload | jsonb |
|
|
# Indexes:
|
|
# nic_pkey | PRIMARY KEY btree (id)
|
|
# Foreign key constraints:
|
|
# nic_private_subnet_id_fkey | (private_subnet_id) REFERENCES private_subnet(id)
|
|
# nic_vm_id_fkey | (vm_id) REFERENCES vm(id)
|
|
# Referenced By:
|
|
# ipsec_tunnel | ipsec_tunnel_dst_nic_id_fkey | (dst_nic_id) REFERENCES nic(id)
|
|
# ipsec_tunnel | ipsec_tunnel_src_nic_id_fkey | (src_nic_id) REFERENCES nic(id)
|