mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 16:57:18 +00:00
persist: improve readability
Address some comments for code readability, also add some unit tests. Signed-off-by: Wei Zhang <weizhang555.zw@gmail.com>
This commit is contained in:
parent
3bfbbd666d
commit
f3d0978c3f
@ -117,51 +117,22 @@ func (endpoint *BridgedMacvlanEndpoint) HotDetach(h hypervisor, netNsCreated boo
|
|||||||
return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot detach")
|
return fmt.Errorf("BridgedMacvlanEndpoint does not support Hot detach")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *BridgedMacvlanEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *BridgedMacvlanEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
netpair := saveNetIfPair(&endpoint.NetPair)
|
||||||
s.BridgedMacvlan = &persistapi.BridgedMacvlanEndpoint{
|
|
||||||
NetPair: persistapi.NetworkInterfacePair{
|
return persistapi.NetworkEndpoint{
|
||||||
TapInterface: persistapi.TapInterface{
|
Type: string(endpoint.Type()),
|
||||||
ID: endpoint.NetPair.TapInterface.ID,
|
BridgedMacvlan: &persistapi.BridgedMacvlanEndpoint{
|
||||||
Name: endpoint.NetPair.TapInterface.Name,
|
NetPair: *netpair,
|
||||||
TAPIface: persistapi.NetworkInterface{
|
|
||||||
Name: endpoint.NetPair.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: endpoint.NetPair.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: endpoint.NetPair.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VirtIface: persistapi.NetworkInterface{
|
|
||||||
Name: endpoint.NetPair.VirtIface.Name,
|
|
||||||
HardAddr: endpoint.NetPair.VirtIface.HardAddr,
|
|
||||||
Addrs: endpoint.NetPair.VirtIface.Addrs,
|
|
||||||
},
|
|
||||||
NetInterworkingModel: int(endpoint.NetPair.NetInterworkingModel),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *BridgedMacvlanEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *BridgedMacvlanEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = BridgedMacvlanEndpointType
|
endpoint.EndpointType = BridgedMacvlanEndpointType
|
||||||
|
|
||||||
if s.BridgedMacvlan != nil {
|
if s.BridgedMacvlan != nil {
|
||||||
iface := s.BridgedMacvlan
|
netpair := loadNetIfPair(&s.BridgedMacvlan.NetPair)
|
||||||
endpoint.NetPair = NetworkInterfacePair{
|
endpoint.NetPair = *netpair
|
||||||
TapInterface: TapInterface{
|
|
||||||
ID: iface.NetPair.TapInterface.ID,
|
|
||||||
Name: iface.NetPair.TapInterface.Name,
|
|
||||||
TAPIface: NetworkInterface{
|
|
||||||
Name: iface.NetPair.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: iface.NetPair.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: iface.NetPair.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VirtIface: NetworkInterface{
|
|
||||||
Name: iface.NetPair.VirtIface.Name,
|
|
||||||
HardAddr: iface.NetPair.VirtIface.HardAddr,
|
|
||||||
Addrs: iface.NetPair.VirtIface.Addrs,
|
|
||||||
},
|
|
||||||
NetInterworkingModel: NetInterworkingModel(iface.NetPair.NetInterworkingModel),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,3 +107,79 @@ func (endpointType *EndpointType) String() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func saveTapIf(tapif *TapInterface) *persistapi.TapInterface {
|
||||||
|
if tapif == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &persistapi.TapInterface{
|
||||||
|
ID: tapif.ID,
|
||||||
|
Name: tapif.Name,
|
||||||
|
TAPIface: persistapi.NetworkInterface{
|
||||||
|
Name: tapif.TAPIface.Name,
|
||||||
|
HardAddr: tapif.TAPIface.HardAddr,
|
||||||
|
Addrs: tapif.TAPIface.Addrs,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadTapIf(tapif *persistapi.TapInterface) *TapInterface {
|
||||||
|
if tapif == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return &TapInterface{
|
||||||
|
ID: tapif.ID,
|
||||||
|
Name: tapif.Name,
|
||||||
|
TAPIface: NetworkInterface{
|
||||||
|
Name: tapif.TAPIface.Name,
|
||||||
|
HardAddr: tapif.TAPIface.HardAddr,
|
||||||
|
Addrs: tapif.TAPIface.Addrs,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func saveNetIfPair(pair *NetworkInterfacePair) *persistapi.NetworkInterfacePair {
|
||||||
|
if pair == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
epVirtIf := pair.VirtIface
|
||||||
|
|
||||||
|
tapif := saveTapIf(&pair.TapInterface)
|
||||||
|
|
||||||
|
virtif := persistapi.NetworkInterface{
|
||||||
|
Name: epVirtIf.Name,
|
||||||
|
HardAddr: epVirtIf.HardAddr,
|
||||||
|
Addrs: epVirtIf.Addrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &persistapi.NetworkInterfacePair{
|
||||||
|
TapInterface: *tapif,
|
||||||
|
VirtIface: virtif,
|
||||||
|
NetInterworkingModel: int(pair.NetInterworkingModel),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadNetIfPair(pair *persistapi.NetworkInterfacePair) *NetworkInterfacePair {
|
||||||
|
if pair == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
savedVirtIf := pair.VirtIface
|
||||||
|
|
||||||
|
tapif := loadTapIf(&pair.TapInterface)
|
||||||
|
|
||||||
|
virtif := NetworkInterface{
|
||||||
|
Name: savedVirtIf.Name,
|
||||||
|
HardAddr: savedVirtIf.HardAddr,
|
||||||
|
Addrs: savedVirtIf.Addrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
return &NetworkInterfacePair{
|
||||||
|
TapInterface: *tapif,
|
||||||
|
VirtIface: virtif,
|
||||||
|
NetInterworkingModel: NetInterworkingModel(pair.NetInterworkingModel),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
package virtcontainers
|
package virtcontainers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
@ -79,3 +83,41 @@ func TestIncorrectEndpointTypeString(t *testing.T) {
|
|||||||
var endpointType EndpointType
|
var endpointType EndpointType
|
||||||
testEndpointTypeString(t, &endpointType, "")
|
testEndpointTypeString(t, &endpointType, "")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSaveLoadIfPair(t *testing.T) {
|
||||||
|
macAddr := net.HardwareAddr{0x02, 0x00, 0xCA, 0xFE, 0x00, 0x04}
|
||||||
|
|
||||||
|
tmpfile, err := ioutil.TempFile("", "vc-save-load-net-")
|
||||||
|
assert.Nil(t, err)
|
||||||
|
defer os.Remove(tmpfile.Name())
|
||||||
|
|
||||||
|
netPair := &NetworkInterfacePair{
|
||||||
|
TapInterface: TapInterface{
|
||||||
|
ID: "uniqueTestID-4",
|
||||||
|
Name: "br4_kata",
|
||||||
|
TAPIface: NetworkInterface{
|
||||||
|
Name: "tap4_kata",
|
||||||
|
HardAddr: macAddr.String(),
|
||||||
|
},
|
||||||
|
VMFds: []*os.File{tmpfile}, // won't be saved to disk
|
||||||
|
VhostFds: []*os.File{tmpfile}, // won't be saved to disk
|
||||||
|
},
|
||||||
|
VirtIface: NetworkInterface{
|
||||||
|
Name: "eth4",
|
||||||
|
HardAddr: macAddr.String(),
|
||||||
|
},
|
||||||
|
NetInterworkingModel: DefaultNetInterworkingModel,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save to disk then load it back.
|
||||||
|
savedIfPair := saveNetIfPair(netPair)
|
||||||
|
loadedIfPair := loadNetIfPair(savedIfPair)
|
||||||
|
|
||||||
|
// Since VMFds and VhostFds are't saved, netPair and loadedIfPair are not equal.
|
||||||
|
assert.False(t, reflect.DeepEqual(netPair, loadedIfPair))
|
||||||
|
|
||||||
|
netPair.TapInterface.VMFds = nil
|
||||||
|
netPair.TapInterface.VhostFds = nil
|
||||||
|
// They are equal now.
|
||||||
|
assert.True(t, reflect.DeepEqual(netPair, loadedIfPair))
|
||||||
|
}
|
||||||
|
@ -120,51 +120,22 @@ func (endpoint *IPVlanEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNs
|
|||||||
return fmt.Errorf("IPVlanEndpoint does not support Hot detach")
|
return fmt.Errorf("IPVlanEndpoint does not support Hot detach")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *IPVlanEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *IPVlanEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
netpair := saveNetIfPair(&endpoint.NetPair)
|
||||||
s.IPVlan = &persistapi.IPVlanEndpoint{
|
|
||||||
NetPair: persistapi.NetworkInterfacePair{
|
return persistapi.NetworkEndpoint{
|
||||||
TapInterface: persistapi.TapInterface{
|
Type: string(endpoint.Type()),
|
||||||
ID: endpoint.NetPair.TapInterface.ID,
|
IPVlan: &persistapi.IPVlanEndpoint{
|
||||||
Name: endpoint.NetPair.TapInterface.Name,
|
NetPair: *netpair,
|
||||||
TAPIface: persistapi.NetworkInterface{
|
|
||||||
Name: endpoint.NetPair.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: endpoint.NetPair.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: endpoint.NetPair.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VirtIface: persistapi.NetworkInterface{
|
|
||||||
Name: endpoint.NetPair.VirtIface.Name,
|
|
||||||
HardAddr: endpoint.NetPair.VirtIface.HardAddr,
|
|
||||||
Addrs: endpoint.NetPair.VirtIface.Addrs,
|
|
||||||
},
|
|
||||||
NetInterworkingModel: int(endpoint.NetPair.NetInterworkingModel),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *IPVlanEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *IPVlanEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = IPVlanEndpointType
|
endpoint.EndpointType = IPVlanEndpointType
|
||||||
|
|
||||||
if s.IPVlan != nil {
|
if s.IPVlan != nil {
|
||||||
iface := s.IPVlan
|
netpair := loadNetIfPair(&s.IPVlan.NetPair)
|
||||||
endpoint.NetPair = NetworkInterfacePair{
|
endpoint.NetPair = *netpair
|
||||||
TapInterface: TapInterface{
|
|
||||||
ID: iface.NetPair.TapInterface.ID,
|
|
||||||
Name: iface.NetPair.TapInterface.Name,
|
|
||||||
TAPIface: NetworkInterface{
|
|
||||||
Name: iface.NetPair.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: iface.NetPair.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: iface.NetPair.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VirtIface: NetworkInterface{
|
|
||||||
Name: iface.NetPair.VirtIface.Name,
|
|
||||||
HardAddr: iface.NetPair.VirtIface.HardAddr,
|
|
||||||
Addrs: iface.NetPair.VirtIface.Addrs,
|
|
||||||
},
|
|
||||||
NetInterworkingModel: NetInterworkingModel(iface.NetPair.NetInterworkingModel),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2080,10 +2080,11 @@ func (k *kataAgent) cleanup(s *Sandbox) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *kataAgent) save() (s persistapi.AgentState) {
|
func (k *kataAgent) save() persistapi.AgentState {
|
||||||
s.ProxyPid = k.state.ProxyPid
|
return persistapi.AgentState{
|
||||||
s.URL = k.state.URL
|
ProxyPid: k.state.ProxyPid,
|
||||||
return
|
URL: k.state.URL,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (k *kataAgent) load(s persistapi.AgentState) {
|
func (k *kataAgent) load(s persistapi.AgentState) {
|
||||||
|
@ -105,15 +105,18 @@ func (endpoint *MacvtapEndpoint) NetworkPair() *NetworkInterfacePair {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *MacvtapEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *MacvtapEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
return persistapi.NetworkEndpoint{
|
||||||
s.Macvtap = &persistapi.MacvtapEndpoint{
|
Type: string(endpoint.Type()),
|
||||||
PCIAddr: endpoint.PCIAddr,
|
|
||||||
|
Macvtap: &persistapi.MacvtapEndpoint{
|
||||||
|
PCIAddr: endpoint.PCIAddr,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
func (endpoint *MacvtapEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *MacvtapEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = MacvtapEndpointType
|
endpoint.EndpointType = MacvtapEndpointType
|
||||||
|
|
||||||
if s.Macvtap != nil {
|
if s.Macvtap != nil {
|
||||||
endpoint.PCIAddr = s.Macvtap.PCIAddr
|
endpoint.PCIAddr = s.Macvtap.PCIAddr
|
||||||
}
|
}
|
||||||
|
@ -285,6 +285,7 @@ func (s *Sandbox) loadNetwork(netInfo persistapi.NetworkInfo) {
|
|||||||
case IPVlanEndpointType:
|
case IPVlanEndpointType:
|
||||||
ep = &IPVlanEndpoint{}
|
ep = &IPVlanEndpoint{}
|
||||||
default:
|
default:
|
||||||
|
s.Logger().WithField("endpoint-type", e.Type).Error("unknown endpoint type")
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
ep.load(e)
|
ep.load(e)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Copyright (c) 2016 Intel Corporation
|
// Copyright (c) 2019 Huawei Corporation
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
@ -83,7 +83,7 @@ func TestSandboxRestore(t *testing.T) {
|
|||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(sandbox.newStore)
|
assert.NotNil(sandbox.newStore)
|
||||||
|
|
||||||
// if we don't call ToDisk, we can get nothing from disk
|
// if we don't call Save(), we can get nothing from disk
|
||||||
err = sandbox.Restore()
|
err = sandbox.Restore()
|
||||||
assert.NotNil(t, err)
|
assert.NotNil(t, err)
|
||||||
assert.True(os.IsNotExist(err))
|
assert.True(os.IsNotExist(err))
|
||||||
|
@ -202,18 +202,21 @@ func bindNICToHost(endpoint *PhysicalEndpoint) error {
|
|||||||
return drivers.BindDevicetoHost(endpoint.BDF, endpoint.Driver, endpoint.VendorDeviceID)
|
return drivers.BindDevicetoHost(endpoint.BDF, endpoint.Driver, endpoint.VendorDeviceID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *PhysicalEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *PhysicalEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
return persistapi.NetworkEndpoint{
|
||||||
s.Physical = &persistapi.PhysicalEndpoint{
|
Type: string(endpoint.Type()),
|
||||||
BDF: endpoint.BDF,
|
|
||||||
Driver: endpoint.Driver,
|
Physical: &persistapi.PhysicalEndpoint{
|
||||||
VendorDeviceID: endpoint.VendorDeviceID,
|
BDF: endpoint.BDF,
|
||||||
|
Driver: endpoint.Driver,
|
||||||
|
VendorDeviceID: endpoint.VendorDeviceID,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *PhysicalEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *PhysicalEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = PhysicalEndpointType
|
endpoint.EndpointType = PhysicalEndpointType
|
||||||
|
|
||||||
if s.Physical != nil {
|
if s.Physical != nil {
|
||||||
endpoint.BDF = s.Physical.BDF
|
endpoint.BDF = s.Physical.BDF
|
||||||
endpoint.Driver = s.Physical.Driver
|
endpoint.Driver = s.Physical.Driver
|
||||||
|
@ -189,34 +189,21 @@ func unTapNetwork(name string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *TapEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *TapEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
tapif := saveTapIf(&endpoint.TapInterface)
|
||||||
s.Tap = &persistapi.TapEndpoint{
|
|
||||||
TapInterface: persistapi.TapInterface{
|
return persistapi.NetworkEndpoint{
|
||||||
ID: endpoint.TapInterface.ID,
|
Type: string(endpoint.Type()),
|
||||||
Name: endpoint.TapInterface.Name,
|
Tap: &persistapi.TapEndpoint{
|
||||||
TAPIface: persistapi.NetworkInterface{
|
TapInterface: *tapif,
|
||||||
Name: endpoint.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: endpoint.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: endpoint.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
func (endpoint *TapEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *TapEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = TapEndpointType
|
endpoint.EndpointType = TapEndpointType
|
||||||
|
|
||||||
if s.Tap != nil {
|
if s.Tap != nil {
|
||||||
iface := s.Tap
|
tapif := loadTapIf(&s.Tap.TapInterface)
|
||||||
endpoint.TapInterface = TapInterface{
|
endpoint.TapInterface = *tapif
|
||||||
ID: iface.TapInterface.ID,
|
|
||||||
Name: iface.TapInterface.Name,
|
|
||||||
TAPIface: NetworkInterface{
|
|
||||||
Name: iface.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: iface.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: iface.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,51 +143,22 @@ func (endpoint *VethEndpoint) HotDetach(h hypervisor, netNsCreated bool, netNsPa
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *VethEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *VethEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
netpair := saveNetIfPair(&endpoint.NetPair)
|
||||||
s.Veth = &persistapi.VethEndpoint{
|
|
||||||
NetPair: persistapi.NetworkInterfacePair{
|
return persistapi.NetworkEndpoint{
|
||||||
TapInterface: persistapi.TapInterface{
|
Type: string(endpoint.Type()),
|
||||||
ID: endpoint.NetPair.TapInterface.ID,
|
Veth: &persistapi.VethEndpoint{
|
||||||
Name: endpoint.NetPair.TapInterface.Name,
|
NetPair: *netpair,
|
||||||
TAPIface: persistapi.NetworkInterface{
|
|
||||||
Name: endpoint.NetPair.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: endpoint.NetPair.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: endpoint.NetPair.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VirtIface: persistapi.NetworkInterface{
|
|
||||||
Name: endpoint.NetPair.VirtIface.Name,
|
|
||||||
HardAddr: endpoint.NetPair.VirtIface.HardAddr,
|
|
||||||
Addrs: endpoint.NetPair.VirtIface.Addrs,
|
|
||||||
},
|
|
||||||
NetInterworkingModel: int(endpoint.NetPair.NetInterworkingModel),
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *VethEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *VethEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = VethEndpointType
|
endpoint.EndpointType = VethEndpointType
|
||||||
|
|
||||||
if s.Veth != nil {
|
if s.Veth != nil {
|
||||||
iface := s.Veth
|
netpair := loadNetIfPair(&s.Veth.NetPair)
|
||||||
endpoint.NetPair = NetworkInterfacePair{
|
endpoint.NetPair = *netpair
|
||||||
TapInterface: TapInterface{
|
|
||||||
ID: iface.NetPair.TapInterface.ID,
|
|
||||||
Name: iface.NetPair.TapInterface.Name,
|
|
||||||
TAPIface: NetworkInterface{
|
|
||||||
Name: iface.NetPair.TapInterface.TAPIface.Name,
|
|
||||||
HardAddr: iface.NetPair.TapInterface.TAPIface.HardAddr,
|
|
||||||
Addrs: iface.NetPair.TapInterface.TAPIface.Addrs,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
VirtIface: NetworkInterface{
|
|
||||||
Name: iface.NetPair.VirtIface.Name,
|
|
||||||
HardAddr: iface.NetPair.VirtIface.HardAddr,
|
|
||||||
Addrs: iface.NetPair.VirtIface.Addrs,
|
|
||||||
},
|
|
||||||
NetInterworkingModel: NetInterworkingModel(iface.NetPair.NetInterworkingModel),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,17 +151,19 @@ func vhostUserSocketPath(info interface{}) (string, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *VhostUserEndpoint) save() (s persistapi.NetworkEndpoint) {
|
func (endpoint *VhostUserEndpoint) save() persistapi.NetworkEndpoint {
|
||||||
s.Type = string(endpoint.Type())
|
return persistapi.NetworkEndpoint{
|
||||||
s.VhostUser = &persistapi.VhostUserEndpoint{
|
Type: string(endpoint.Type()),
|
||||||
IfaceName: endpoint.IfaceName,
|
VhostUser: &persistapi.VhostUserEndpoint{
|
||||||
PCIAddr: endpoint.PCIAddr,
|
IfaceName: endpoint.IfaceName,
|
||||||
|
PCIAddr: endpoint.PCIAddr,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *VhostUserEndpoint) load(s persistapi.NetworkEndpoint) {
|
func (endpoint *VhostUserEndpoint) load(s persistapi.NetworkEndpoint) {
|
||||||
endpoint.EndpointType = VhostUserEndpointType
|
endpoint.EndpointType = VhostUserEndpointType
|
||||||
|
|
||||||
if s.VhostUser != nil {
|
if s.VhostUser != nil {
|
||||||
endpoint.IfaceName = s.VhostUser.IfaceName
|
endpoint.IfaceName = s.VhostUser.IfaceName
|
||||||
endpoint.PCIAddr = s.VhostUser.PCIAddr
|
endpoint.PCIAddr = s.VhostUser.PCIAddr
|
||||||
|
Loading…
Reference in New Issue
Block a user