MCPcopy Create free account
hub / github.com/containerd/nerdctl / List

Function List

pkg/cmd/network/list.go:42–143  ·  view source on GitHub ↗
(ctx context.Context, options types.NetworkListOptions)

Source from the content-addressed store, hash-verified

40}
41
42func List(ctx context.Context, options types.NetworkListOptions) error {
43 globalOptions := options.GOptions
44 quiet := options.Quiet
45 format := options.Format
46 w := options.Stdout
47 filters := options.Filters
48 var tmpl *template.Template
49
50 switch format {
51 case "", "table", "wide":
52 w = tabwriter.NewWriter(w, 4, 8, 4, ' ', 0)
53 if !quiet {
54 fmt.Fprintln(w, "NETWORK ID\tNAME\tFILE")
55 }
56 case "raw":
57 return errors.New("unsupported format: \"raw\"")
58 default:
59 if quiet {
60 return errors.New("format and quiet must not be specified together")
61 }
62 var err error
63 tmpl, err = formatter.ParseTemplate(format)
64 if err != nil {
65 return err
66 }
67 }
68
69 e, err := netutil.NewCNIEnv(globalOptions.CNIPath, globalOptions.CNINetConfPath, netutil.WithNamespace(options.GOptions.Namespace))
70 if err != nil {
71 return err
72 }
73 netConfigs, err := e.NetworkList()
74 if err != nil {
75 return err
76 }
77
78 labelFilterFuncs, nameFilterFuncs, err := getNetworkFilterFuncs(filters)
79 if err != nil {
80 return err
81 }
82 if len(filters) > 0 {
83 filtered := make([]*netutil.NetworkConfig, 0)
84 for _, net := range netConfigs {
85 if networkMatchesFilter(net, labelFilterFuncs, nameFilterFuncs) {
86 filtered = append(filtered, net)
87 }
88 }
89 netConfigs = filtered
90 }
91
92 pp := make([]networkPrintable, len(netConfigs))
93 for i, n := range netConfigs {
94 p := networkPrintable{
95 Name: n.Name,
96 file: n.File,
97 }
98 if n.NerdctlID != nil {
99 p.ID = *n.NerdctlID

Callers 1

listActionFunction · 0.92

Calls 9

NetworkListMethod · 0.95
ParseTemplateFunction · 0.92
NewCNIEnvFunction · 0.92
WithNamespaceFunction · 0.92
FormatLabelsFunction · 0.92
getNetworkFilterFuncsFunction · 0.85
networkMatchesFilterFunction · 0.85
FlushMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…