func getIntNames(netID string, docker *dockerclient.Client) (*intNames, error) { net, err := docker.NetworkInspect(context.Background(), netID) if err != nil { log.Errorf("Error getting networks: %v", err) return nil, err } names := &intNames{} if net.Driver != "vxlan" { log.Errorf("Network %v is not a vxlan network", netID) return nil, errors.New("Not a vxlan network") } names.VxlanName = "vx_" + netID[:12] // get interface names from options first for k, v := range net.Options { if k == "vxlanName" { names.VxlanName = v } } return names, nil }
func getGateway(netID string, docker dockerclient.Client) (string, error) { net, err := docker.NetworkInspect(context.Background(), netID) if err != nil { log.Errorf("Error inspecting network: %v", err) return "", err } for _, config := range net.IPAM.Config { if config.Gateway != "" { return config.Gateway, nil } } return "", nil }
// PurgeOnionNetwork purges an onion network, disconnecting all containers with // it. We assume that nobody is adding containers to this network. func PurgeOnionNetwork(cli *client.Client, network string) error { inspect, err := cli.NetworkInspect(network) if err != nil { return err } for container, _ := range inspect.Containers { log.Infof("purge network %s: disconnecting container %s", network, container) if err := cli.NetworkDisconnect(network, container, true); err != nil { return err } } return cli.NetworkRemove(network) }