// BasicNetworkFromGRPC converts a grpc Network to a NetworkResource. func BasicNetworkFromGRPC(n swarmapi.Network) basictypes.NetworkResource { spec := n.Spec var ipam networktypes.IPAM if spec.IPAM != nil { if spec.IPAM.Driver != nil { ipam.Driver = spec.IPAM.Driver.Name ipam.Options = spec.IPAM.Driver.Options } ipam.Config = make([]networktypes.IPAMConfig, 0, len(spec.IPAM.Configs)) for _, ic := range spec.IPAM.Configs { ipamConfig := networktypes.IPAMConfig{ Subnet: ic.Subnet, IPRange: ic.Range, Gateway: ic.Gateway, AuxAddress: ic.Reserved, } ipam.Config = append(ipam.Config, ipamConfig) } } nr := basictypes.NetworkResource{ ID: n.ID, Name: n.Spec.Annotations.Name, Scope: "swarm", EnableIPv6: spec.Ipv6Enabled, IPAM: ipam, Internal: spec.Internal, Attachable: spec.Attachable, Labels: n.Spec.Annotations.Labels, } if n.DriverState != nil { nr.Driver = n.DriverState.Name nr.Options = n.DriverState.Options } return nr }