(options types.NetworkCreateOptions, stdout io.Writer)
| 27 | ) |
| 28 | |
| 29 | func 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 | } |
no test coverage detected
searching dependent graphs…