fix(region): guest restart network task params

Signed-off-by: wanyaoqi <d3lx.yq@gmail.com>
This commit is contained in:
wanyaoqi
2023-05-16 15:00:20 +08:00
parent a3aa26b8e2
commit a8fb862eb9
6 changed files with 58 additions and 44 deletions
+36 -30
View File
@@ -76,30 +76,27 @@ type GuestnetworkUpdateInput struct {
Index *int8 `json:"index"`
}
type GuestnetworkJsonDesc struct {
Net string `json:"net"`
NetId string `json:"net_id"`
Mac string `json:"mac"`
Virtual bool `json:"virtual"`
Ip string `json:"ip"`
Gateway string `json:"gateway"`
Dns string `json:"dns"`
Domain string `json:"domain"`
Ntp string `json:"ntp"`
Routes jsonutils.JSONObject `json:"routes"`
Ifname string `json:"ifname"`
Masklen int8 `json:"masklen"`
Driver string `json:"driver"`
NumQueues int `json:"num_queues"`
Vectors *int `json:"vectors"`
Vlan int `json:"vlan"`
Bw int `json:"bw"`
Mtu int `json:"mtu"`
Index int8 `json:"index"`
VirtualIps []string `json:"virtual_ips"`
ExternalId string `json:"external_id"`
TeamWith string `json:"team_with"`
Manual *bool `json:"manual"`
type GuestnetworkBaseDesc struct {
Net string `json:"net"`
NetId string `json:"net_id"`
Mac string `json:"mac"`
Virtual bool `json:"virtual"`
Ip string `json:"ip"`
Gateway string `json:"gateway"`
Dns string `json:"dns"`
Domain string `json:"domain"`
Ntp string `json:"ntp"`
Routes jsonutils.JSONObject `json:"routes"`
Ifname string `json:"ifname"`
Masklen int8 `json:"masklen"`
Vlan int `json:"vlan"`
Bw int `json:"bw"`
Mtu int `json:"mtu"`
Index int8 `json:"index"`
Bridge string `json:"bridge"`
WireId string `json:"wire_id"`
Interface string `json:"interface"`
Vpc struct {
Id string `json:"id"`
@@ -107,15 +104,24 @@ type GuestnetworkJsonDesc struct {
MappedIpAddr string `json:"mapped_ip_addr"`
} `json:"vpc"`
Networkaddresses jsonutils.JSONObject `json:"networkaddresses"`
}
type GuestnetworkJsonDesc struct {
GuestnetworkBaseDesc
Driver string `json:"driver"`
NumQueues int `json:"num_queues"`
Vectors *int `json:"vectors"`
VirtualIps []string `json:"virtual_ips"`
ExternalId string `json:"external_id"`
TeamWith string `json:"team_with"`
Manual *bool `json:"manual"`
UpscriptPath string `json:"upscript_path"`
DownscriptPath string `json:"downscript_path"`
Networkaddresses jsonutils.JSONObject `json:"networkaddresses"`
Bridge string `json:"bridge"`
WireId string `json:"wire_id"`
Interface string `json:"interface"`
// baremetal
Rate int `json:"rate"`
BaremetalId string `json:"baremetal_id"`
+6 -4
View File
@@ -539,10 +539,12 @@ func (self *SGuestnetwork) getJsonDescOneCloudVpc(network *SNetwork) *api.Guestn
func (self *SGuestnetwork) getJsonDesc() *api.GuestnetworkJsonDesc {
net := self.GetNetwork()
desc := &api.GuestnetworkJsonDesc{
Net: net.Name,
NetId: self.NetworkId,
Mac: self.MacAddr,
Virtual: self.Virtual,
GuestnetworkBaseDesc: api.GuestnetworkBaseDesc{
Net: net.Name,
NetId: self.NetworkId,
Mac: self.MacAddr,
Virtual: self.Virtual,
},
}
if self.Virtual {
+7 -5
View File
@@ -77,13 +77,15 @@ func (g *SGuest) getTapNicJsonDesc(ctx context.Context, p *api.GuestnetworkJsonD
index = p.Index + 1
}
desc := &api.GuestnetworkJsonDesc{
Mac: srv.MacAddr,
Virtual: true,
Ifname: srv.Ifname,
GuestnetworkBaseDesc: api.GuestnetworkBaseDesc{
Mac: srv.MacAddr,
Virtual: true,
Index: index,
Bridge: api.HostTapBridge,
Ifname: srv.Ifname,
},
Driver: driver,
NumQueues: 1,
Index: index,
Bridge: api.HostTapBridge,
}
return desc
}
@@ -167,17 +167,17 @@ Loop:
return
}
self.SetStage("OnResumeIpMacSrcCheckComplete", nil)
err = guest.StartSyncTask(ctx, self.GetUserCred(), true, self.Id)
err = guest.StartSyncTask(ctx, self.GetUserCred(), false, self.Id)
if err != nil {
self.taskFailed(ctx, guest, nil, err)
}
}
func (self *GuestRestartNetworkTask) OnResumeIpMacSrcCheckComplete(ctx context.Context, obj db.IScopedResourceManager, data jsonutils.JSONObject) {
func (self *GuestRestartNetworkTask) OnResumeIpMacSrcCheckComplete(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStageComplete(ctx, nil)
}
func (self *GuestRestartNetworkTask) OnResumeIpMacSrcCheckCompleteFailed(ctx context.Context, obj db.IScopedResourceManager, data jsonutils.JSONObject) {
func (self *GuestRestartNetworkTask) OnResumeIpMacSrcCheckCompleteFailed(ctx context.Context, obj db.IStandaloneModel, data jsonutils.JSONObject) {
self.SetStageFailed(ctx, data)
}
@@ -205,7 +205,7 @@ func (self *GuestRestartNetworkTask) OnInit(ctx context.Context, obj db.IStandal
return
}
self.SetStage("OnCloseIpMacSrcCheckComplete", data)
err = guest.StartSyncTask(ctx, self.GetUserCred(), true, self.Id)
err = guest.StartSyncTask(ctx, self.GetUserCred(), false, self.Id)
if err != nil {
self.taskFailed(ctx, guest, nil, err)
return
+1 -1
View File
@@ -42,7 +42,7 @@ func (self *GuestSyncConfTask) OnInit(ctx context.Context, obj db.IStandaloneMod
self.SetStageFailed(ctx, jsonutils.NewString("No host for sync"))
return
} else {
self.SetStage("on_sync_complete", nil)
self.SetStage("OnSyncComplete", nil)
if err := guest.GetDriver().RequestSyncConfigOnHost(ctx, guest, host, self); err != nil {
self.SetStageFailed(ctx, jsonutils.NewString(err.Error()))
log.Errorf("SyncConfTask faled %v", err)
+4
View File
@@ -1977,6 +1977,9 @@ func getNicBridge(nic *desc.SGuestNetwork) string {
}
func onNicChange(oldNic, newNic *desc.SGuestNetwork) error {
// override network base desc
oldNic.GuestnetworkBaseDesc = newNic.GuestnetworkBaseDesc
oldbr := getNicBridge(oldNic)
oldifname := oldNic.Ifname
newbr := getNicBridge(newNic)
@@ -2068,6 +2071,7 @@ func (s *SKVMGuestInstance) SyncConfig(
s.Desc.SGuestProjectDesc = guestDesc.SGuestProjectDesc
s.Desc.SGuestRegionDesc = guestDesc.SGuestRegionDesc
s.Desc.SGuestMetaDesc = guestDesc.SGuestMetaDesc
s.SaveLiveDesc(s.Desc)
if fwOnly {