(dockerCLI command.Cli)
| 43 | } |
| 44 | |
| 45 | func newCreateCommand(dockerCLI command.Cli) *cobra.Command { |
| 46 | var ipv4, ipv6 bool |
| 47 | options := createOptions{ |
| 48 | driverOpts: *opts.NewMapOpts(nil, nil), |
| 49 | labels: opts.NewListOpts(opts.ValidateLabel), |
| 50 | ipam: ipamOptions{ |
| 51 | auxAddresses: *opts.NewMapOpts(nil, nil), |
| 52 | driverOpts: *opts.NewMapOpts(nil, nil), |
| 53 | }, |
| 54 | } |
| 55 | |
| 56 | cmd := &cobra.Command{ |
| 57 | Use: "create [OPTIONS] NETWORK", |
| 58 | Short: "Create a network", |
| 59 | Args: cli.ExactArgs(1), |
| 60 | RunE: func(cmd *cobra.Command, args []string) error { |
| 61 | options.name = args[0] |
| 62 | |
| 63 | if cmd.Flag("ipv4").Changed { |
| 64 | options.ipv4 = &ipv4 |
| 65 | } |
| 66 | if cmd.Flag("ipv6").Changed { |
| 67 | options.ipv6 = &ipv6 |
| 68 | } |
| 69 | |
| 70 | return runCreate(cmd.Context(), dockerCLI.Client(), dockerCLI.Out(), options) |
| 71 | }, |
| 72 | ValidArgsFunction: cobra.NoFileCompletions, |
| 73 | DisableFlagsInUseLine: true, |
| 74 | } |
| 75 | |
| 76 | flags := cmd.Flags() |
| 77 | flags.StringVarP(&options.driver, "driver", "d", "bridge", "Driver to manage the Network") |
| 78 | flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options") |
| 79 | flags.Var(&options.labels, "label", "Set metadata on a network") |
| 80 | flags.BoolVar(&options.internal, "internal", false, "Restrict external access to the network") |
| 81 | flags.BoolVar(&ipv4, "ipv4", true, "Enable or disable IPv4 address assignment") |
| 82 | flags.BoolVar(&ipv6, "ipv6", false, "Enable or disable IPv6 address assignment") |
| 83 | flags.BoolVar(&options.attachable, "attachable", false, "Enable manual container attachment") |
| 84 | flags.SetAnnotation("attachable", "version", []string{"1.25"}) |
| 85 | flags.BoolVar(&options.ingress, "ingress", false, "Create swarm routing-mesh network") |
| 86 | flags.SetAnnotation("ingress", "version", []string{"1.29"}) |
| 87 | flags.StringVar(&options.scope, "scope", "", "Control the network's scope") |
| 88 | flags.SetAnnotation("scope", "version", []string{"1.30"}) |
| 89 | flags.BoolVar(&options.configOnly, "config-only", false, "Create a configuration only network") |
| 90 | flags.SetAnnotation("config-only", "version", []string{"1.30"}) |
| 91 | flags.StringVar(&options.configFrom, "config-from", "", "The network from which to copy the configuration") |
| 92 | flags.SetAnnotation("config-from", "version", []string{"1.30"}) |
| 93 | |
| 94 | flags.StringVar(&options.ipam.driver, "ipam-driver", "default", "IP Address Management Driver") |
| 95 | flags.StringSliceVar(&options.ipam.subnets, "subnet", []string{}, "Subnet in CIDR format that represents a network segment") |
| 96 | flags.IPNetSliceVar(&options.ipam.ipRanges, "ip-range", nil, "Allocate container ip from a sub-range") |
| 97 | flags.IPSliceVar(&options.ipam.gateways, "gateway", nil, "IPv4 or IPv6 Gateway for the master subnet") |
| 98 | |
| 99 | flags.Var(&options.ipam.auxAddresses, "aux-address", "Auxiliary IPv4 or IPv6 addresses used by Network driver") |
| 100 | flags.Var(&options.ipam.driverOpts, "ipam-opt", "Set IPAM driver specific options") |
| 101 | |
| 102 | return cmd |
searching dependent graphs…