MCPcopy Index your code
hub / github.com/docker/cli / parseNetworkAttachmentOpt

Function parseNetworkAttachmentOpt

cli/command/container/opts.go:859–898  ·  view source on GitHub ↗
(ep opts.NetworkAttachmentOpts)

Source from the content-addressed store, hash-verified

857}
858
859func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.EndpointSettings, error) {
860 if strings.TrimSpace(ep.Target) == "" {
861 return nil, errors.New("no name set for network")
862 }
863 if !container.NetworkMode(ep.Target).IsUserDefined() {
864 if len(ep.Aliases) > 0 {
865 return nil, errors.New("network-scoped aliases are only supported for user-defined networks")
866 }
867 if len(ep.Links) > 0 {
868 return nil, errors.New("links are only supported for user-defined networks")
869 }
870 }
871
872 epConfig := &network.EndpointSettings{
873 GwPriority: ep.GwPriority,
874 }
875 epConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)
876 if len(ep.DriverOpts) > 0 {
877 epConfig.DriverOpts = make(map[string]string)
878 epConfig.DriverOpts = ep.DriverOpts
879 }
880 if len(ep.Links) > 0 {
881 epConfig.Links = ep.Links
882 }
883 if ep.IPv4Address.IsValid() || ep.IPv6Address.IsValid() || len(ep.LinkLocalIPs) > 0 {
884 epConfig.IPAMConfig = &network.EndpointIPAMConfig{
885 IPv4Address: ep.IPv4Address,
886 IPv6Address: ep.IPv6Address,
887 LinkLocalIPs: ep.LinkLocalIPs,
888 }
889 }
890 if ep.MacAddress != "" {
891 ma, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress))
892 if err != nil {
893 return nil, fmt.Errorf("%s is not a valid mac address", ep.MacAddress)
894 }
895 epConfig.MacAddress = network.HardwareAddr(ma)
896 }
897 return epConfig, nil
898}
899
900func convertToStandardNotation(ports []string) ([]string, error) {
901 optsList := []string{}

Callers 1

parseNetworkOptsFunction · 0.85

Calls 1

NetworkModeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…