Files
ubicloud/migrate/20230722_add_nic.rb
Furkan Sahin bebb4925c0 Adds PrivateSubnet, Nic and changes model of private networking
This commit mainly changes the data modelling around the private
networking.
Before this, a VmPrivateSubnet entity was getting created at the
Vm/Nexus assembly and a refresh_mesh was simply allowing access to every
other VM in the mesh. We wouldn't use static mac addresses, or store the
Nic entity. Here, the new data model is as the following;

- PrivateSubnet (e.g. 10.0.0.64/26) one_to_many Nic (10.0.0.72/32).
- Nic many_to_one VM (or any other resource we would provide)
- VMs have public ipv6/4 addresses assigned depending on the setup.
- VMs (resources) that have Nics that exist in the same PrivateSubnet
can communicate with each other via private IPv4/6 addresses internally.
This above 4 marks summarize the private networking in a nutshell.

Below diagram should be easier to digest;
+---------------------+
| PrivateSubnet       |
| IPv4: 10.0.0.64/26  |
| IPv6: fd00::/64     |
+---------------------+
         | 1:N
        / \
+---------------------+  +---------------------+
| Nic1                |  | Nic2                |
| IPv4: 10.0.0.72/32  |  | IPv4: 10.0.0.73/32  |
| IPv6: fd12::8739/80 |  | IPv6: fd12::8740/80 |
+---------------------+  +---------------------+
         | N:1                    | N:1
         v                        v
+-----------------------+ +-----------------------+
| VM1                   | | VM2                   |
| IPv4: 203.0.113.42    | | IPv4: 203.0.113.43    |
| IPv6: 2001::42        | | IPv6: 2001::43        |
|   +----------------+  | |   +----------------+  |
|   | tap dev       |  | |   | tap dev       |  |
|   | IPv4: 10.0.0.72|  | |   | IPv4: 10.0.0.73|  |
|   | IPv6: fd12::8739|  | |   | IPv6: fd12::8740| |
|   +----------------+  | |   +----------------+  |
+-----------------------+ +-----------------------+
              |                          |
              |  IpsecTunnel             |
              \__________________________/
2023-07-26 17:15:59 +03:00

34 lines
1.0 KiB
Ruby

# frozen_string_literal: true
Sequel.migration do
change do
rename_table(:vm_private_subnet, :private_subnet)
alter_table(:private_subnet) do
drop_foreign_key :vm_id
add_column :state, :text, null: false, default: "creating"
add_column :name, :text, null: false
add_column :location, :text, null: false
end
create_table(:nic) do
column :id, :uuid, primary_key: true
foreign_key :private_subnet_id, :private_subnet, type: :uuid, null: false
column :mac, :text, null: false
column :created_at, :timestamptz, null: false, default: Sequel.lit("now()")
column :private_ipv4, :cidr, null: false
column :private_ipv6, :cidr, null: false
foreign_key :vm_id, :vm, type: :uuid
column :encryption_key, :text, null: false
column :name, :text, null: false
end
alter_table(:ipsec_tunnel) do
add_foreign_key :src_nic_id, :nic, type: :uuid
add_foreign_key :dst_nic_id, :nic, type: :uuid
drop_column :src_vm_id
drop_column :dst_vm_id
end
end
end