Skip to content

Commit

Permalink
[Controller] vinterface add vtap id
Browse files Browse the repository at this point in the history
  • Loading branch information
askyrie committed Jul 11, 2023
1 parent 0b09d16 commit 4de2643
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions server/controller/cloud/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ func GetHostNics(hosts []model.Host, domainName, uuidGenerate, portNameRegex str
retVInterfaces = append(retVInterfaces, model.VInterface{
Lcuuid: vinterfaceLcuuid,
NetnsID: vinterface.NetnsID,
VTapID: vinterface.VtapID,
Type: common.VIF_TYPE_LAN,
Mac: vinterface.Mac,
DeviceType: common.VIF_DEVICE_TYPE_HOST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ func (k *KubernetesGather) getVInterfacesAndIPs() (nodeSubnets, podSubnets []mod
Mac: vMAC,
TapMac: vTAPMAC,
NetnsID: vItem.NetnsID,
VTapID: vItem.VtapID,
DeviceType: common.VIF_DEVICE_TYPE_POD,
DeviceLcuuid: podLcuuid,
NetworkLcuuid: k.podNetworkLcuuidCIDRs.networkLcuuid,
Expand Down
1 change: 1 addition & 0 deletions server/controller/cloud/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ type VInterface struct {
VPCLcuuid string `json:"vpc_lcuuid"` // TODO not used
RegionLcuuid string `json:"region_lcuuid" binding:"required"`
NetnsID uint32 `json:"netns_id"`
VTapID uint32 `json:"vtap_id" binding:"required"`
SubDomainLcuuid string `json:"sub_domain_lcuuid"`
}

Expand Down
1 change: 1 addition & 0 deletions server/controller/db/mysql/migration/rawsql/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ CREATE TABLE IF NOT EXISTS vinterface (
devicetype INTEGER COMMENT 'Type 0.unknown 1.vm 2.vgw 3.third-party-device 4.vmwaf 5.NSP-vgateway 6.host-device 7.network-device 9.DHCP-port 10.pod 11.pod_service 12. redis_instance 13. rds_instance 14. pod_node 15. load_balance 16. nat_gateway',
deviceid INTEGER COMMENT 'unknown: Senseless ID, vm: vm ID, vgw/NSP-vgateway: vnet ID, third-party-device: third_party_device ID, vmwaf: vmwaf ID, host-device: host_device ID, network-device: network_device ID',
netns_id INTEGER UNSIGNED DEFAULT 0,
vtap_id INTEGER,
sub_domain CHAR(64) DEFAULT '',
domain CHAR(64) DEFAULT '',
region CHAR(64) DEFAULT '',
Expand Down
3 changes: 3 additions & 0 deletions server/controller/db/mysql/migration/rawsql/issu/6.3.1.23.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE vinterface ADD COLUMN vtap_id INTEGER AFTER netns_id;

UPDATE db_version SET version='6.3.1.23';
2 changes: 1 addition & 1 deletion server/controller/db/mysql/migration/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ package migration

const (
DB_VERSION_TABLE = "db_version"
DB_VERSION_EXPECTED = "6.3.1.22"
DB_VERSION_EXPECTED = "6.3.1.23"
)
1 change: 1 addition & 0 deletions server/controller/db/mysql/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ type VInterface struct {
DeviceType int `gorm:"column:devicetype;type:int;default:null" json:"DEVICETYPE"` // Type 0.unknown 1.vm 2.vgw 3.third-party-device 4.vmwaf 5.NSP-vgateway 6.host-device 7.network-device 9.DHCP-port 10.pod 11.pod_service 12. redis_instance 13. rds_instance 14. pod_node 15. load_balance 16. nat_gateway
DeviceID int `gorm:"column:deviceid;type:int;default:null" json:"DEVICEID"` // unknown: Senseless ID, vm: vm ID, vgw/NSP-vgateway: vnet ID, third-party-device: third_party_device ID, vmwaf: vmwaf ID, host-device: host_device ID, network-device: network_device ID
NetnsID uint32 `gorm:"column:netns_id;type:int unsigned;default:0" json:"NETNS_ID"` // used to associate processes with cloud and container resources
VtapID uint32 `gorm:"column:vtap_id;type:int" json:"VTAP_ID"`
SubDomain string `gorm:"column:sub_domain;type:char(64);default:''" json:"SUB_DOMAIN"`
Domain string `gorm:"column:domain;type:char(64);not null" json:"DOMAIN"`
Region string `gorm:"column:region;type:char(64);default:''" json:"REGION"`
Expand Down
4 changes: 4 additions & 0 deletions server/controller/recorder/cache/vinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ type VInterface struct {
Name string `json:"name"`
Type int `json:"type"`
TapMac string `json:"tap_mac"`
NetnsID uint32 `json:"netns_id"`
VtapID uint32 `json:"vtap_id"`
NetworkLcuuid string `json:"network_lcuuid"`
RegionLcuuid string `json:"region_lcuuid"`
SubDomainLcuuid string `json:"sub_domain_lcuuid"`
Expand All @@ -61,6 +63,8 @@ func (v *VInterface) Update(cloudItem *cloudmodel.VInterface) {
v.Name = cloudItem.Name
v.Type = cloudItem.Type
v.TapMac = cloudItem.TapMac
v.NetnsID = cloudItem.NetnsID
v.VtapID = cloudItem.VTapID
v.NetworkLcuuid = cloudItem.NetworkLcuuid
v.RegionLcuuid = cloudItem.RegionLcuuid
v.SubDomainLcuuid = cloudItem.SubDomainLcuuid
Expand Down
7 changes: 7 additions & 0 deletions server/controller/recorder/updater/vinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (i *VInterface) generateDBItemToAdd(cloudItem *cloudmodel.VInterface) (*mys
Domain: i.cache.DomainLcuuid,
Region: cloudItem.RegionLcuuid,
NetnsID: cloudItem.NetnsID,
VtapID: cloudItem.VTapID,
}
dbItem.Lcuuid = cloudItem.Lcuuid
return dbItem, true
Expand Down Expand Up @@ -131,6 +132,12 @@ func (i *VInterface) generateUpdateInfo(diffBase *cache.VInterface, cloudItem *c
if diffBase.Type != cloudItem.Type {
updateInfo["iftype"] = cloudItem.Type
}
if diffBase.NetnsID != cloudItem.NetnsID {
updateInfo["netns_id"] = cloudItem.NetnsID
}
if diffBase.VtapID != cloudItem.VTapID {
updateInfo["vtap_id"] = cloudItem.VTapID
}
return updateInfo, len(updateInfo) > 0
}

Expand Down

0 comments on commit 4de2643

Please sign in to comment.