summaryrefslogtreecommitdiff
path: root/pkg/bindings
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-08-16 16:11:26 +0200
committerPaul Holzinger <pholzing@redhat.com>2021-09-15 20:00:20 +0200
commit85e8fbf7f33717ef6a0d6cf9e2143b52c874c2de (patch)
tree82b0c29102d2779c18ea8a6f10df5dc1139e3817 /pkg/bindings
parent218f132fdf4939d9e0374ef860d534f19e71df54 (diff)
downloadpodman-85e8fbf7f33717ef6a0d6cf9e2143b52c874c2de.tar.gz
podman-85e8fbf7f33717ef6a0d6cf9e2143b52c874c2de.tar.bz2
podman-85e8fbf7f33717ef6a0d6cf9e2143b52c874c2de.zip
Wire network interface into libpod
Make use of the new network interface in libpod. This commit contains several breaking changes: - podman network create only outputs the new network name and not file path. - podman network ls shows the network driver instead of the cni version and plugins. - podman network inspect outputs the new network struct and not the cni conflist. - The bindings and libpod api endpoints have been changed to use the new network structure. The container network status is stored in a new field in the state. The status should be received with the new `c.getNetworkStatus`. This will migrate the old status to the new format. Therefore old containers should contine to work correctly in all cases even when network connect/ disconnect is used. New features: - podman network reload keeps the ip and mac for more than one network. - podman container restore keeps the ip and mac for more than one network. - The network create compat endpoint can now use more than one ipam config. The man pages and the swagger doc are updated to reflect the latest changes. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/bindings')
-rw-r--r--pkg/bindings/network/network.go49
-rw-r--r--pkg/bindings/test/networks_test.go45
2 files changed, 43 insertions, 51 deletions
diff --git a/pkg/bindings/network/network.go b/pkg/bindings/network/network.go
index 59207aa8d..5a0a34f56 100644
--- a/pkg/bindings/network/network.go
+++ b/pkg/bindings/network/network.go
@@ -6,58 +6,51 @@ import (
"net/url"
"strings"
+ "github.com/containers/podman/v3/libpod/network/types"
"github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/domain/entities"
jsoniter "github.com/json-iterator/go"
)
// Create makes a new CNI network configuration
-func Create(ctx context.Context, options *CreateOptions) (*entities.NetworkCreateReport, error) {
- var report entities.NetworkCreateReport
- if options == nil {
- options = new(CreateOptions)
- }
+func Create(ctx context.Context, network *types.Network) (types.Network, error) {
+ var report types.Network
conn, err := bindings.GetClient(ctx)
if err != nil {
- return nil, err
+ return report, err
}
- params := url.Values{}
- if options.Name != nil {
- params.Set("name", options.GetName())
+ // create empty network if the caller did not provide one
+ if network == nil {
+ network = &types.Network{}
}
- networkConfig, err := jsoniter.MarshalToString(options)
+ networkConfig, err := jsoniter.MarshalToString(*network)
if err != nil {
- return nil, err
+ return report, err
}
- stringReader := strings.NewReader(networkConfig)
- response, err := conn.DoRequest(stringReader, http.MethodPost, "/networks/create", params, nil)
+ reader := strings.NewReader(networkConfig)
+ response, err := conn.DoRequest(reader, http.MethodPost, "/networks/create", nil, nil)
if err != nil {
- return nil, err
+ return report, err
}
defer response.Body.Close()
- return &report, response.Process(&report)
+ return report, response.Process(&report)
}
// Inspect returns low level information about a CNI network configuration
-func Inspect(ctx context.Context, nameOrID string, options *InspectOptions) ([]entities.NetworkInspectReport, error) {
- var reports []entities.NetworkInspectReport
- reports = append(reports, entities.NetworkInspectReport{})
- if options == nil {
- options = new(InspectOptions)
- }
- _ = options
+func Inspect(ctx context.Context, nameOrID string, _ *InspectOptions) (types.Network, error) {
+ var net types.Network
conn, err := bindings.GetClient(ctx)
if err != nil {
- return nil, err
+ return net, err
}
response, err := conn.DoRequest(nil, http.MethodGet, "/networks/%s/json", nil, nil, nameOrID)
if err != nil {
- return nil, err
+ return net, err
}
defer response.Body.Close()
- return reports, response.Process(&reports[0])
+ return net, response.Process(&net)
}
// Remove deletes a defined CNI network configuration by name. The optional force boolean
@@ -86,10 +79,8 @@ func Remove(ctx context.Context, nameOrID string, options *RemoveOptions) ([]*en
}
// List returns a summary of all CNI network configurations
-func List(ctx context.Context, options *ListOptions) ([]*entities.NetworkListReport, error) {
- var (
- netList []*entities.NetworkListReport
- )
+func List(ctx context.Context, options *ListOptions) ([]types.Network, error) {
+ var netList []types.Network
if options == nil {
options = new(ListOptions)
}
diff --git a/pkg/bindings/test/networks_test.go b/pkg/bindings/test/networks_test.go
index b53fc4bd3..85ceeb998 100644
--- a/pkg/bindings/test/networks_test.go
+++ b/pkg/bindings/test/networks_test.go
@@ -6,6 +6,7 @@ import (
"net/http"
"time"
+ "github.com/containers/podman/v3/libpod/network/types"
"github.com/containers/podman/v3/pkg/bindings"
"github.com/containers/podman/v3/pkg/bindings/containers"
"github.com/containers/podman/v3/pkg/bindings/network"
@@ -41,10 +42,10 @@ var _ = Describe("Podman networks", func() {
It("podman prune unused networks with filters", func() {
name := "foobar"
- opts := network.CreateOptions{
- Name: &name,
+ net := types.Network{
+ Name: name,
}
- _, err = network.Create(connText, &opts)
+ _, err = network.Create(connText, &net)
Expect(err).To(BeNil())
// Invalid filters should return error
@@ -88,20 +89,20 @@ var _ = Describe("Podman networks", func() {
It("create network", func() {
// create a network with blank config should work
- _, err = network.Create(connText, &network.CreateOptions{})
+ _, err = network.Create(connText, nil)
Expect(err).To(BeNil())
name := "foobar"
- opts := network.CreateOptions{
- Name: &name,
+ net := types.Network{
+ Name: name,
}
- report, err := network.Create(connText, &opts)
+ report, err := network.Create(connText, &net)
Expect(err).To(BeNil())
- Expect(report.Filename).To(ContainSubstring(name))
+ Expect(report.Name).To(Equal(name))
// create network with same name should 500
- _, err = network.Create(connText, &opts)
+ _, err = network.Create(connText, &net)
Expect(err).ToNot(BeNil())
code, _ := bindings.CheckResponseCode(err)
Expect(code).To(BeNumerically("==", http.StatusInternalServerError))
@@ -109,24 +110,24 @@ var _ = Describe("Podman networks", func() {
It("inspect network", func() {
name := "foobar"
- opts := network.CreateOptions{
- Name: &name,
+ net := types.Network{
+ Name: name,
}
- _, err = network.Create(connText, &opts)
+ _, err = network.Create(connText, &net)
Expect(err).To(BeNil())
data, err := network.Inspect(connText, name, nil)
Expect(err).To(BeNil())
- Expect(data[0]["name"]).To(Equal(name))
+ Expect(data.Name).To(Equal(name))
})
It("list networks", func() {
// create a bunch of named networks and make verify with list
netNames := []string{"homer", "bart", "lisa", "maggie", "marge"}
for i := 0; i < 5; i++ {
- opts := network.CreateOptions{
- Name: &netNames[i],
+ net := types.Network{
+ Name: netNames[i],
}
- _, err = network.Create(connText, &opts)
+ _, err = network.Create(connText, &net)
Expect(err).To(BeNil())
}
list, err := network.List(connText, nil)
@@ -166,10 +167,10 @@ var _ = Describe("Podman networks", func() {
// Removing an unused network should work
name := "unused"
- opts := network.CreateOptions{
- Name: &name,
+ net := types.Network{
+ Name: name,
}
- _, err = network.Create(connText, &opts)
+ _, err = network.Create(connText, &net)
Expect(err).To(BeNil())
report, err := network.Remove(connText, name, nil)
Expect(err).To(BeNil())
@@ -177,10 +178,10 @@ var _ = Describe("Podman networks", func() {
// Removing a network that is being used without force should be 500
name = "used"
- opts = network.CreateOptions{
- Name: &name,
+ net = types.Network{
+ Name: name,
}
- _, err = network.Create(connText, &opts)
+ _, err = network.Create(connText, &net)
Expect(err).To(BeNil())
// Start container and wait