virtcontainers: Define a Network interface

And move the Linux implementation into a GOOS specific file.

Fixes #3005

Signed-off-by: Samuel Ortiz <s.ortiz@apple.com>
This commit is contained in:
Samuel Ortiz 2021-11-08 22:13:07 +00:00 committed by Samuel Ortiz
parent 5e119e90e8
commit e0b264430d
10 changed files with 1525 additions and 1524 deletions

View File

@ -356,7 +356,7 @@ func (a *Acrn) setConfig(config *HypervisorConfig) error {
}
// CreateVM is the VM creation
func (a *Acrn) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
func (a *Acrn) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
// Save the tracing context
a.ctx = ctx

View File

@ -200,7 +200,7 @@ func (clh *cloudHypervisor) setConfig(config *HypervisorConfig) error {
// For cloudHypervisor this call only sets the internal structure up.
// The VM will be created and started through StartVM().
func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
func (clh *cloudHypervisor) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
clh.ctx = ctx
span, newCtx := katatrace.Trace(clh.ctx, clh.Logger(), "CreateVM", clhTracingTags, map[string]string{"sandbox_id": clh.id})

View File

@ -199,7 +199,7 @@ func (fc *firecracker) setConfig(config *HypervisorConfig) error {
// CreateVM For firecracker this call only sets the internal structure up.
// The sandbox will be created and started through startSandbox().
func (fc *firecracker) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
func (fc *firecracker) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
fc.ctx = ctx
span, _ := katatrace.Trace(ctx, fc.Logger(), "CreateVM", fcTracingTags, map[string]string{"sandbox_id": fc.id})

View File

@ -910,7 +910,7 @@ func generateVMSocket(id string, vmStogarePath string) (interface{}, error) {
// hypervisor is the virtcontainers hypervisor interface.
// The default hypervisor implementation is Qemu.
type Hypervisor interface {
CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error
CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error
StartVM(ctx context.Context, timeout int) error
// If wait is set, don't actively stop the sandbox:

View File

@ -38,7 +38,7 @@ func (m *mockHypervisor) setConfig(config *HypervisorConfig) error {
return nil
}
func (m *mockHypervisor) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
func (m *mockHypervisor) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
if err := m.setConfig(hypervisorConfig); err != nil {
return err
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -75,7 +75,7 @@ func TestGenerateInterfacesAndRoutes(t *testing.T) {
nns, err := NewNetwork(&NetworkConfig{NetworkID: "foobar", NetworkCreated: true})
assert.Nil(t, err)
nns.eps = endpoints
nns.SetEndpoints(endpoints)
resInterfaces, resRoutes, resNeighs, err := generateVCNetworkStructures(context.Background(), nns)

View File

@ -468,7 +468,7 @@ func (q *qemu) setConfig(config *HypervisorConfig) error {
}
// CreateVM is the Hypervisor VM creation implementation for govmmQemu.
func (q *qemu) CreateVM(ctx context.Context, id string, network *Network, hypervisorConfig *HypervisorConfig) error {
func (q *qemu) CreateVM(ctx context.Context, id string, network Network, hypervisorConfig *HypervisorConfig) error {
// Save the tracing context
q.ctx = ctx

View File

@ -207,7 +207,7 @@ type Sandbox struct {
id string
network *Network
network Network
state types.SandboxState
@ -873,14 +873,14 @@ func (s *Sandbox) AddInterface(ctx context.Context, inf *pbTypes.Interface) (*pb
return nil, err
}
endpoint, err := s.network.attachEndpoint(ctx, s, netInfo, nil, true)
endpoint, err := s.network.AddEndpoint(ctx, s, netInfo, nil, true)
if err != nil {
return nil, err
}
defer func() {
if err != nil {
if errDetach := s.network.detachEndpoint(ctx, s, len(s.network.Endpoints())-1, true); err != nil {
if errDetach := s.network.RemoveEndpoint(ctx, s, len(s.network.Endpoints())-1, true); err != nil {
s.Logger().WithField("endpoint-type", endpoint.Type()).WithError(errDetach).Error("rollback hot attaching endpoint failed")
}
}
@ -906,7 +906,7 @@ func (s *Sandbox) RemoveInterface(ctx context.Context, inf *pbTypes.Interface) (
for i, endpoint := range s.network.Endpoints() {
if endpoint.HardwareAddr() == inf.HwAddr {
s.Logger().WithField("endpoint-type", endpoint.Type()).Info("Hot detaching endpoint")
if err := s.network.detachEndpoint(ctx, s, i, true); err != nil {
if err := s.network.RemoveEndpoint(ctx, s, i, true); err != nil {
return inf, err
}