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

Function Create

pkg/cmd/network/create.go:29–50  ·  view source on GitHub ↗
(options types.NetworkCreateOptions, stdout io.Writer)

Source from the content-addressed store, hash-verified

27)
28
29func Create(options types.NetworkCreateOptions, stdout io.Writer) error {
30 if len(options.Subnets) == 0 {
31 if len(options.Gateway) > 0 || options.IPRange != "" {
32 return fmt.Errorf("cannot set gateway or ip-range without subnet, specify --subnet manually")
33 }
34 options.Subnets = []string{""}
35 }
36
37 e, err := netutil.NewCNIEnv(options.GOptions.CNIPath, options.GOptions.CNINetConfPath, netutil.WithNamespace(options.GOptions.Namespace))
38 if err != nil {
39 return err
40 }
41 net, err := e.CreateNetwork(options)
42 if err != nil {
43 if errdefs.IsAlreadyExists(err) {
44 return fmt.Errorf("network with name %s already exists", options.Name)
45 }
46 return err
47 }
48 _, err = fmt.Fprintln(stdout, *net.NerdctlID)
49 return err
50}

Callers 1

createActionFunction · 0.92

Calls 3

CreateNetworkMethod · 0.95
NewCNIEnvFunction · 0.92
WithNamespaceFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…