bindings: network uses entities/types

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2024-01-25 15:28:06 +01:00
parent c736a8e20a
commit aee733c581
3 changed files with 40 additions and 25 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -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
}