Example #1
0
// GetNetworkName gets network name from network UUID
func GetNetworkName(nwID string) (string, error) {
	libnetAPI := libnetClient.NewRemoteAPI("")

	nw, err := libnetAPI.NetworkByID(nwID)
	if err != nil {
		log.Infof("Error: %v", err)
		return "", err
	}

	log.Infof("Returning network name %s for ID %s", nw.Name(), nwID)

	return nw.Name(), nil
}
Example #2
0
// GetEndpointName Returns endpoint name from networkId, endpointId
func GetEndpointName(nwID, epID string) (string, error) {
	libnetAPI := libnetClient.NewRemoteAPI("")

	nw, err := libnetAPI.NetworkByID(nwID)
	if err != nil {
		log.Infof("Error: %v", err)
		return "", err
	}

	ep, err := nw.EndpointByID(epID)
	if err != nil {
		log.Infof("Error: %v", err)
		return "", err
	}

	log.Infof("Returning endpoint name %s for ID %s/%s", ep.Name(), nwID, epID)

	return ep.Name(), nil
}
Example #3
0
// createDockNet Creates a network in docker daemon
func createDockNet(networkName string) error {
	api := libnetClient.NewRemoteAPI("")

	// Check if the network already exists
	nw, err := api.NetworkByName(networkName)
	if err == nil && nw.Type() == driverName {
		return nil
	} else if err == nil && nw.Type() != driverName {
		log.Errorf("Network name %s used by another driver %s", networkName, nw.Type())
		return errors.New("Network name used by another driver")
	}

	// Create network
	_, err = api.NewNetwork(driverName, networkName)
	if err != nil {
		log.Errorf("Error creating network %s. Err: %v", networkName, err)
		// FIXME: Ignore errors till we fully move to docker 1.9
		return nil
	}

	return nil
}