summaryrefslogtreecommitdiff
path: root/cmd/podman/networks
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/podman/networks')
-rw-r--r--cmd/podman/networks/connect.go6
-rw-r--r--cmd/podman/networks/create.go10
-rw-r--r--cmd/podman/networks/disconnect.go6
-rw-r--r--cmd/podman/networks/exists.go6
-rw-r--r--cmd/podman/networks/inspect.go8
-rw-r--r--cmd/podman/networks/list.go77
-rw-r--r--cmd/podman/networks/network.go9
-rw-r--r--cmd/podman/networks/prune.go10
-rw-r--r--cmd/podman/networks/reload.go10
-rw-r--r--cmd/podman/networks/rm.go10
10 files changed, 85 insertions, 67 deletions
diff --git a/cmd/podman/networks/connect.go b/cmd/podman/networks/connect.go
index 8afc0c7c0..9fa088b78 100644
--- a/cmd/podman/networks/connect.go
+++ b/cmd/podman/networks/connect.go
@@ -2,9 +2,9 @@ package network
import (
"github.com/containers/common/pkg/completion"
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/networks/create.go b/cmd/podman/networks/create.go
index d1cbe253f..64ca2464a 100644
--- a/cmd/podman/networks/create.go
+++ b/cmd/podman/networks/create.go
@@ -5,11 +5,11 @@ import (
"net"
"github.com/containers/common/pkg/completion"
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/parse"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/libpod/define"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/parse"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/libpod/define"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/networks/disconnect.go b/cmd/podman/networks/disconnect.go
index a30315774..26861eec6 100644
--- a/cmd/podman/networks/disconnect.go
+++ b/cmd/podman/networks/disconnect.go
@@ -1,9 +1,9 @@
package network
import (
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
diff --git a/cmd/podman/networks/exists.go b/cmd/podman/networks/exists.go
index 2eb485b36..fdbd0ef11 100644
--- a/cmd/podman/networks/exists.go
+++ b/cmd/podman/networks/exists.go
@@ -1,9 +1,9 @@
package network
import (
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go
index bd9f76ea9..953f5e6e8 100644
--- a/cmd/podman/networks/inspect.go
+++ b/cmd/podman/networks/inspect.go
@@ -1,10 +1,10 @@
package network
import (
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/inspect"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/inspect"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
)
diff --git a/cmd/podman/networks/list.go b/cmd/podman/networks/list.go
index 6f63e97cc..2181f850b 100644
--- a/cmd/podman/networks/list.go
+++ b/cmd/podman/networks/list.go
@@ -1,7 +1,6 @@
package network
import (
- "encoding/json"
"fmt"
"os"
"strings"
@@ -10,12 +9,11 @@ import (
"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/report"
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/parse"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/cmd/podman/validate"
- "github.com/containers/podman/v2/libpod/network"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/cmd/podman/validate"
+ "github.com/containers/podman/v3/libpod/network"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
@@ -78,13 +76,38 @@ func networkList(cmd *cobra.Command, args []string) error {
}
switch {
- case report.IsJSON(networkListOptions.Format):
- return jsonOut(responses)
+ // quiet means we only print the network names
case networkListOptions.Quiet:
- // quiet means we only print the network names
- return quietOut(responses)
+ quietOut(responses)
+
+ // JSON output formatting
+ case report.IsJSON(networkListOptions.Format):
+ err = jsonOut(responses)
+
+ // table or other format output
+ default:
+ err = templateOut(responses, cmd)
+ }
+
+ return err
+}
+
+func quietOut(responses []*entities.NetworkListReport) {
+ for _, r := range responses {
+ fmt.Println(r.Name)
+ }
+}
+
+func jsonOut(responses []*entities.NetworkListReport) error {
+ prettyJSON, err := json.MarshalIndent(responses, "", " ")
+ if err != nil {
+ return err
}
+ fmt.Println(string(prettyJSON))
+ return nil
+}
+func templateOut(responses []*entities.NetworkListReport, cmd *cobra.Command) error {
nlprs := make([]ListPrintReports, 0, len(responses))
for _, r := range responses {
nlprs = append(nlprs, ListPrintReports{r})
@@ -99,13 +122,16 @@ func networkList(cmd *cobra.Command, args []string) error {
"Labels": "labels",
"ID": "network id",
})
- renderHeaders := true
- row := "{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
+
+ renderHeaders := report.HasTable(networkListOptions.Format)
+ var row, format string
if cmd.Flags().Changed("format") {
- renderHeaders = parse.HasTable(networkListOptions.Format)
row = report.NormalizeFormat(networkListOptions.Format)
+ } else { // 'podman network ls' equivalent to 'podman network ls --format="table {{.ID}} {{.Name}} {{.Version}} {{.Plugins}}" '
+ renderHeaders = true
+ row = "{{.ID}}\t{{.Name}}\t{{.Version}}\t{{.Plugins}}\n"
}
- format := parse.EnforceRange(row)
+ format = report.EnforceRange(row)
tmpl, err := template.New("listNetworks").Parse(format)
if err != nil {
@@ -122,34 +148,22 @@ func networkList(cmd *cobra.Command, args []string) error {
return tmpl.Execute(w, nlprs)
}
-func quietOut(responses []*entities.NetworkListReport) error {
- for _, r := range responses {
- fmt.Println(r.Name)
- }
- return nil
-}
-
-func jsonOut(responses []*entities.NetworkListReport) error {
- b, err := json.MarshalIndent(responses, "", " ")
- if err != nil {
- return err
- }
- fmt.Println(string(b))
- return nil
-}
-
+// ListPrintReports returns the network list report
type ListPrintReports struct {
*entities.NetworkListReport
}
+// Version returns the CNI version
func (n ListPrintReports) Version() string {
return n.CNIVersion
}
+// Plugins returns the CNI Plugins
func (n ListPrintReports) Plugins() string {
return network.GetCNIPlugins(n.NetworkConfigList)
}
+// Labels returns any labels added to a Network
func (n ListPrintReports) Labels() string {
list := make([]string, 0, len(n.NetworkListReport.Labels))
for k, v := range n.NetworkListReport.Labels {
@@ -158,6 +172,7 @@ func (n ListPrintReports) Labels() string {
return strings.Join(list, ",")
}
+// ID returns the Podman Network ID
func (n ListPrintReports) ID() string {
length := 12
if noTrunc {
diff --git a/cmd/podman/networks/network.go b/cmd/podman/networks/network.go
index b5f9ef9fd..4d6cd8abd 100644
--- a/cmd/podman/networks/network.go
+++ b/cmd/podman/networks/network.go
@@ -1,13 +1,16 @@
package network
import (
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/cmd/podman/validate"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/cmd/podman/validate"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
)
var (
+ // Pull in configured json library
+ json = registry.JSONLibrary()
+
// Command: podman _network_
networkCmd = &cobra.Command{
Use: "network",
diff --git a/cmd/podman/networks/prune.go b/cmd/podman/networks/prune.go
index d6c7d3a7f..ebba06db5 100644
--- a/cmd/podman/networks/prune.go
+++ b/cmd/podman/networks/prune.go
@@ -6,11 +6,11 @@ import (
"os"
"strings"
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/cmd/podman/utils"
- "github.com/containers/podman/v2/cmd/podman/validate"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/cmd/podman/utils"
+ "github.com/containers/podman/v3/cmd/podman/validate"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
diff --git a/cmd/podman/networks/reload.go b/cmd/podman/networks/reload.go
index 16655c18c..8f2fbf011 100644
--- a/cmd/podman/networks/reload.go
+++ b/cmd/podman/networks/reload.go
@@ -3,11 +3,11 @@ package network
import (
"fmt"
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/cmd/podman/utils"
- "github.com/containers/podman/v2/cmd/podman/validate"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/cmd/podman/utils"
+ "github.com/containers/podman/v3/cmd/podman/validate"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)
diff --git a/cmd/podman/networks/rm.go b/cmd/podman/networks/rm.go
index 1504d9385..1ae79b27d 100644
--- a/cmd/podman/networks/rm.go
+++ b/cmd/podman/networks/rm.go
@@ -4,11 +4,11 @@ import (
"fmt"
"strings"
- "github.com/containers/podman/v2/cmd/podman/common"
- "github.com/containers/podman/v2/cmd/podman/registry"
- "github.com/containers/podman/v2/cmd/podman/utils"
- "github.com/containers/podman/v2/libpod/define"
- "github.com/containers/podman/v2/pkg/domain/entities"
+ "github.com/containers/podman/v3/cmd/podman/common"
+ "github.com/containers/podman/v3/cmd/podman/registry"
+ "github.com/containers/podman/v3/cmd/podman/utils"
+ "github.com/containers/podman/v3/libpod/define"
+ "github.com/containers/podman/v3/pkg/domain/entities"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"