func (m *NetworkManagerImpl) LocateNetwork(fqname, subnet string) (*types.VirtualNetwork, error) {
	obj, err := m.client.FindByName("virtual-network", fqname)
	if err == nil {
		return obj.(*types.VirtualNetwork), nil
	}
	fqn := strings.Split(fqname, ":")
	project := strings.Join(fqn[0:len(fqn)-1], ":")
	name := fqn[len(fqn)-1]
	proj, err := m.client.FindByName("project", project)
	if err != nil {
		glog.Infof("GET %s: %v", project, err)
		return nil, err
	}
	var ipams[] *types.NetworkIpam = make([]*types.NetworkIpam, 1)
	ipams[0] = new(types.NetworkIpam)
	ipams[0].SetParent(proj.(*types.Project))
	ipams[0].SetName(fmt.Sprintf("%s-ipam", name))
	err = m.client.Create(ipams[0])
	if err != nil {
		glog.Errorf("Create ipam for network %s:%s failed: %v", project, name, err)
		return nil, err
	}
	var subnets[] string = make([]string, 1)
	subnets[0] = subnet
	uid, err := config.CreateNetworkWithIpam(m.client, proj.(*types.Project), name, subnets, ipams)
	if err != nil {
		glog.Infof("Create %s: %v", name, err)
		return nil, err
	}
	obj, err = m.client.FindByUuid("virtual-network", uid)
	if err != nil {
		glog.Infof("GET %s: %v", name, err)
		return nil, err
	}
	glog.Infof("Create network %s", fqname)
	return obj.(*types.VirtualNetwork), nil
}
LocateNetwork creates a private network.

It is used to create pod and service networks.
package opencontrail
import (
	"fmt"
	"regexp"
	"strings"
	"github.com/golang/glog"
	"github.com/Juniper/contrail-go-api"
	"github.com/Juniper/contrail-go-api/config"
	"github.com/Juniper/contrail-go-api/types"
)
type NetworkManager interface {
	LocateFloatingIpPool(network *types.VirtualNetwork) (*types.FloatingIpPool, error)
	LookupFloatingIpPool(network *types.VirtualNetwork) (*types.FloatingIpPool, error)
	DeleteFloatingIpPool(network *types.VirtualNetwork, cascade bool) error
	LookupNetwork(projectName, networkName string) (*types.VirtualNetwork, error)
	LocateNetwork(fqname, subnet string) (*types.VirtualNetwork, error)
	DeleteNetwork(*types.VirtualNetwork) error
	ReleaseNetworkIfEmpty(network *types.VirtualNetwork) (bool, error)
	LocateFloatingIp(network *types.VirtualNetwork, resourceName, address string) (*types.FloatingIp, error)
	DeleteFloatingIp(network *types.VirtualNetwork, resourceName string) error
	GetPublicNetwork() *types.VirtualNetwork
	GetClusterNetwork() *types.VirtualNetwork
	GetGatewayAddress(network *types.VirtualNetwork) (string, error)
	Connect(network *types.VirtualNetwork, targetCSN string) error
	Disconnect(networkFQN []string, targetCSN string) error
	DeleteConnections(network *types.VirtualNetwork, policies map[string]string) error
}
type NetworkManagerImpl struct {
	client        contrail.ApiClient
	config        *Config
	publicNetwork *types.VirtualNetwork
	clusterNetwork *types.VirtualNetwork
}
func NewNetworkManager(client contrail.ApiClient, config *Config) NetworkManager {
	manager := new(NetworkManagerImpl)
	manager.client = client
	manager.config = config
	if config.PublicSubnet != "" {
		manager.initializePublicNetwork()
	}
	manager.initializeClusterNetwork()
	return manager
}
func (m *NetworkManagerImpl) GetPublicNetwork() *types.VirtualNetwork {
	return m.publicNetwork
}
func (m *NetworkManagerImpl) GetClusterNetwork() *types.VirtualNetwork {
	return m.clusterNetwork
}
func makePoolName(network *types.VirtualNetwork) string {
	fqn := make([]string, len(network.GetFQName()), len(network.GetFQName())+1)
	copy(fqn, network.GetFQName())
	fqn = append(fqn, fqn[len(fqn)-1])
	return strings.Join(fqn, ":")
}
func (m *NetworkManagerImpl) LocateFloatingIpPool(network *types.VirtualNetwork) (*types.FloatingIpPool, error) {
	obj, err := m.client.FindByName("floating-ip-pool", makePoolName(network))
	if err == nil {
		return obj.(*types.FloatingIpPool), nil
	}
	pool := new(types.FloatingIpPool)
	pool.SetName(network.GetName())
	pool.SetParent(network)
	err = m.client.Create(pool)
	if err != nil {
		glog.Errorf("Create floating-ip-pool %s: %v", network.GetName(), err)
		return nil, err
	}
	return pool, nil
}
func (m *NetworkManagerImpl) LookupFloatingIpPool(network *types.VirtualNetwork) (*types.FloatingIpPool, error) {
	pool, err := types.FloatingIpPoolByName(m.client, makePoolName(network))
	return pool, err
}
func (m *NetworkManagerImpl) floatingIpPoolDeleteChildren(pool *types.FloatingIpPool) error {
	fips, err := pool.GetFloatingIps()
	if err != nil {
		glog.Errorf("Get floating-ip-pool %s: %v", pool.GetName(), err)
		return err
	}
	for _, fip := range fips {
		err := m.client.DeleteByUuid("floating-ip", fip.Uuid)
		if err != nil {
			glog.Errorf("Delete floating-ip %s: %v", fip.Uuid, err)
		}
	}
	return nil
}
func (m *NetworkManagerImpl) DeleteFloatingIpPool(network *types.VirtualNetwork, cascade bool) error {
	obj, err := m.client.FindByName("floating-ip-pool", makePoolName(network))
	if err != nil {
		glog.Errorf("Get floating-ip-pool %s: %v", network.GetName(), err)
		return err
	}
	if cascade {
		pool := obj.(*types.FloatingIpPool)
		m.floatingIpPoolDeleteChildren(pool)
	}
	m.client.Delete(obj)
	return nil
}
func (m *NetworkManagerImpl) updateSubnetConfig(network *types.VirtualNetwork, prefix string) error {
	prefixList, err := m.NetworkIPPrefixList(network)
	if err != nil {
		glog.Fatal(err)
	}
	add := true
	for _, pfx := range prefixList {
		if pfx == prefix {
			add = false
			continue
		}
		ipRefs, err := network.GetInstanceIpBackRefs()
		if err != nil {
			glog.Error(err)
			continue
		}
		if len(ipRefs) > 0 {
			glog.Warningf(
				"network %s %s is stale but there are %d instance-ips present",
				network.GetName(), pfx, len(ipRefs))
			continue
		}
		pool, err := m.LookupFloatingIpPool(network)
		if err == nil {
			floatRefs, err := pool.GetFloatingIps()
			if err != nil {
				glog.Error(err)
				continue
			}
			if len(floatRefs) > 0 {
				glog.Warningf(
					"network %s %s is stale but there are %d floating-ip addresses present",
					network.GetName(), pfx, len(floatRefs))
				continue
			}
		}
		err = config.RemoveSubnet(m.client, network, pfx)
		if err != nil {
			glog.Error(err)
		}
	}
	if add {
		_, err := config.AddSubnet(m.client, network, m.config.PublicSubnet)
		if err != nil {
			glog.Error(err)
		}
		return err
	}
	return nil
}
func (m *NetworkManagerImpl) initializeNetwork(netFqn, subnet string) (*types.VirtualNetwork) {
	var network *types.VirtualNetwork
	obj, err := m.client.FindByName("virtual-network", netFqn)
	if err != nil {
		fqn := strings.Split(netFqn, ":")
		project := strings.Join(fqn[0:len(fqn)-1], ":")
		name := fqn[len(fqn)-1]
		projectId, err := m.client.UuidByName("project", project)
		if err != nil {
			glog.Fatalf("%s: %v", project, err)
		}
		var networkID string
		networkID, err = config.CreateNetworkWithSubnet(
			m.client, projectId, name, subnet)
		if err != nil {
			glog.Fatalf("%s: %v", project, err)
		}
		glog.Infof("Created network %s",name)
		obj, err := m.client.FindByUuid("virtual-network", networkID)
		if err != nil {
			glog.Fatalf("GET %s %v", networkID, err)
		}
		network = obj.(*types.VirtualNetwork)
	} else {
		network = obj.(*types.VirtualNetwork)
		m.updateSubnetConfig(network, subnet)
	}
	m.LocateFloatingIpPool(network)
	return network
}
func (m *NetworkManagerImpl) initializePublicNetwork() {
	var network, err = m.LocateNetwork(m.config.PublicNetwork, m.config.PublicSubnet)
	if err != nil {
		glog.Errorf("Cannot initialize Public Network: %s", err)
		return
	}
	m.publicNetwork = network
	m.LocateFloatingIpPool(m.publicNetwork)
}
func (m *NetworkManagerImpl) initializeClusterNetwork() {
	obj, err := m.client.FindByName("virtual-network", ClusterServiceNetworkName)
	if err != nil {
		fqn := strings.Split(ClusterServiceNetworkName, ":")
		project := strings.Join(fqn[0:len(fqn) - 1], ":")
		name := fqn[len(fqn) - 1]
		proj, err := m.client.FindByName("project", project)
		if err != nil {
			glog.Infof("GET %s: %v", project, err)
			return
		}
		var ipams[] *types.NetworkIpam = make([]*types.NetworkIpam, 2)
		ipams[0] = new(types.NetworkIpam)
		ipams[0].SetParent(proj.(*types.Project))
		ipams[0].SetName(fmt.Sprintf("%s-svc-ipam", name))
		err = m.client.Create(ipams[0])
		if err != nil {
			glog.Errorf("Create svc ipam for network %s:%s failed: %v", project, name, err)
			return
		}
		ipams[1] = new(types.NetworkIpam)
		ipams[1].SetParent(proj.(*types.Project))
		ipams[1].SetName(fmt.Sprintf("%s-pod-ipam", name))
		err = m.client.Create(ipams[1])
		if err != nil {
			glog.Errorf("Create pod ipam for network %s:%s failed: %v", project, name, err)
			return
		}
		var subnets[] string = make([]string, 2)
		subnets[0] = m.config.ServiceSubnet
		subnets[1] = m.config.PrivateSubnet
		uid, err := config.CreateNetworkWithIpam(m.client, proj.(*types.Project), name, subnets, ipams)
		if err != nil {
			glog.Errorf("Create %s: %v", name, err)
			return
		}
		obj, err = m.client.FindByUuid("virtual-network", uid)
		if err != nil {
			glog.Errorf("GET %s: %v", name, err)
			return
		}
		glog.Infof("Create network %s", ClusterServiceNetworkName)
	}
	m.clusterNetwork = obj.(*types.VirtualNetwork)
	m.LocateFloatingIpPool(m.clusterNetwork)
}
func (m *NetworkManagerImpl) LookupNetwork(projectName, networkName string) (*types.VirtualNetwork, error) {
	fqn := []string{m.config.DefaultDomain, projectName, networkName}
	obj, err := m.client.FindByName("virtual-network", strings.Join(fqn, ":"))
	if err != nil {
		glog.V(3).Infof("GET virtual-network %s: %v", networkName, err)
		return nil, err
	}
	return obj.(*types.VirtualNetwork), nil
}