From aee733c581945ad1667dc0c9e21a03977dfb7957 Mon Sep 17 00:00:00 2001
From: Giuseppe Scrivano <gscrivan@redhat.com>
Date: Thu, 25 Jan 2024 15:28:06 +0100
Subject: [PATCH] bindings: network uses entities/types

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
---
 pkg/bindings/network/network.go      | 12 ++++++------
 pkg/domain/entities/network.go       | 25 ++++++-------------------
 pkg/domain/entities/types/network.go | 28 ++++++++++++++++++++++++++++
 3 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go
index 79d26cbfa8..f95fadb1f2 100644
--- a/pkg/bindings/network/network.go
+++ b/pkg/bindings/network/network.go
@@ -8,7 +8,7 @@ import (
 
 	"github.com/containers/common/libnetwork/types"
 	"github.com/containers/podman/v4/pkg/bindings"
-	"github.com/containers/podman/v4/pkg/domain/entities"
+	entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types"
 	jsoniter "github.com/json-iterator/go"
 )
 
@@ -88,8 +88,8 @@ func Inspect(ctx context.Context, nameOrID string, _ *InspectOptions) (types.Net
 // Remove deletes a defined network configuration by name.  The optional force boolean
 // will remove all containers associated with the network when set to true.  A slice
 // of NetworkRemoveReports are returned.
-func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*entities.NetworkRmReport, error) {
-	var reports []*entities.NetworkRmReport
+func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*entitiesTypes.NetworkRmReport, error) {
+	var reports []*entitiesTypes.NetworkRmReport
 	if options == nil {
 		options = new(RemoveOptions)
 	}
@@ -177,7 +177,7 @@ func Connect(ctx context.Context, networkName string, containerNameOrID string,
 		return err
 	}
 	// Connect sends everything in body
-	connect := entities.NetworkConnectOptions{
+	connect := entitiesTypes.NetworkConnectOptions{
 		Container:         containerNameOrID,
 		PerNetworkOptions: *options,
 	}
@@ -212,7 +212,7 @@ func Exists(ctx context.Context, nameOrID string, options *ExistsOptions) (bool,
 }
 
 // Prune removes unused networks
-func Prune(ctx context.Context, options *PruneOptions) ([]*entities.NetworkPruneReport, error) {
+func Prune(ctx context.Context, options *PruneOptions) ([]*entitiesTypes.NetworkPruneReport, error) {
 	if options == nil {
 		options = new(PruneOptions)
 	}
@@ -221,7 +221,7 @@ func Prune(ctx context.Context, options *PruneOptions) ([]*entities.NetworkPrune
 		return nil, err
 	}
 	var (
-		prunedNetworks []*entities.NetworkPruneReport
+		prunedNetworks []*entitiesTypes.NetworkPruneReport
 	)
 	conn, err := bindings.GetClient(ctx)
 	if err != nil {
diff --git a/pkg/domain/entities/network.go b/pkg/domain/entities/network.go
index 5a30362c51..d5774ba972 100644
--- a/pkg/domain/entities/network.go
+++ b/pkg/domain/entities/network.go
@@ -3,8 +3,7 @@ package entities
 import (
 	"net"
 
-	commonTypes "github.com/containers/common/libnetwork/types"
-	"github.com/containers/podman/v4/pkg/domain/entities/types"
+	entitiesTypes "github.com/containers/podman/v4/pkg/domain/entities/types"
 )
 
 // NetworkListOptions describes options for listing networks in cli
@@ -22,11 +21,7 @@ type NetworkReloadOptions struct {
 }
 
 // NetworkReloadReport describes the results of reloading a container network.
-type NetworkReloadReport struct {
-	//nolint:stylecheck,revive
-	Id  string
-	Err error
-}
+type NetworkReloadReport = entitiesTypes.NetworkReloadReport
 
 // NetworkRmOptions describes options for removing networks
 type NetworkRmOptions struct {
@@ -35,10 +30,7 @@ type NetworkRmOptions struct {
 }
 
 // NetworkRmReport describes the results of network removal
-type NetworkRmReport struct {
-	Name string
-	Err  error
-}
+type NetworkRmReport = entitiesTypes.NetworkRmReport
 
 // NetworkCreateOptions describes options to create a network
 type NetworkCreateOptions struct {
@@ -68,9 +60,7 @@ type NetworkUpdateOptions struct {
 }
 
 // NetworkCreateReport describes a created network for the cli
-type NetworkCreateReport struct {
-	Name string
-}
+type NetworkCreateReport = entitiesTypes.NetworkCreateReport
 
 // NetworkDisconnectOptions describes options for disconnecting
 // containers from networks
@@ -81,15 +71,12 @@ type NetworkDisconnectOptions struct {
 
 // NetworkConnectOptions describes options for connecting
 // a container to a network
-type NetworkConnectOptions struct {
-	Container string `json:"container"`
-	commonTypes.PerNetworkOptions
-}
+type NetworkConnectOptions = entitiesTypes.NetworkConnectOptions
 
 // NetworkPruneReport containers the name of network and an error
 // associated in its pruning (removal)
 // swagger:model NetworkPruneReport
-type NetworkPruneReport = types.NetworkPruneReport
+type NetworkPruneReport = entitiesTypes.NetworkPruneReport
 
 // NetworkPruneOptions describes options for pruning unused networks
 type NetworkPruneOptions struct {
diff --git a/pkg/domain/entities/types/network.go b/pkg/domain/entities/types/network.go
index 0ca2f3df1e..8c547ee94d 100644
--- a/pkg/domain/entities/types/network.go
+++ b/pkg/domain/entities/types/network.go
@@ -1,5 +1,9 @@
 package types
 
+import (
+	commonTypes "github.com/containers/common/libnetwork/types"
+)
+
 // NetworkPruneReport containers the name of network and an error
 // associated in its pruning (removal)
 // swagger:model NetworkPruneReport
@@ -7,3 +11,27 @@ type NetworkPruneReport struct {
 	Name  string
 	Error error
 }
+
+// NetworkReloadReport describes the results of reloading a container network.
+type NetworkReloadReport struct {
+	//nolint:stylecheck,revive
+	Id  string
+	Err error
+}
+
+// NetworkConnectOptions describes options for connecting
+// a container to a network
+type NetworkConnectOptions struct {
+	Container string `json:"container"`
+	commonTypes.PerNetworkOptions
+}
+
+// NetworkRmReport describes the results of network removal
+type NetworkRmReport struct {
+	Name string
+	Err  error
+}
+
+type NetworkCreateReport struct {
+	Name string
+}