github.com/ld86/docker@v1.7.1-rc3/daemon/utils.go (about)

     1  package daemon
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/docker/docker/nat"
     9  	"github.com/docker/docker/runconfig"
    10  )
    11  
    12  func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
    13  	if config.PortSpecs != nil {
    14  		ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
    15  		if err != nil {
    16  			return err
    17  		}
    18  		config.PortSpecs = nil
    19  		if len(bindings) > 0 {
    20  			if hostConfig == nil {
    21  				hostConfig = &runconfig.HostConfig{}
    22  			}
    23  			hostConfig.PortBindings = bindings
    24  		}
    25  
    26  		if config.ExposedPorts == nil {
    27  			config.ExposedPorts = make(nat.PortSet, len(ports))
    28  		}
    29  		for k, v := range ports {
    30  			config.ExposedPorts[k] = v
    31  		}
    32  	}
    33  	return nil
    34  }
    35  
    36  func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig) ([]string, error) {
    37  	if hostConfig == nil {
    38  		return nil, nil
    39  	}
    40  
    41  	out := []string{}
    42  
    43  	// merge in the lxc conf options into the generic config map
    44  	if lxcConf := hostConfig.LxcConf; lxcConf != nil {
    45  		lxSlice := lxcConf.Slice()
    46  		for _, pair := range lxSlice {
    47  			// because lxc conf gets the driver name lxc.XXXX we need to trim it off
    48  			// and let the lxc driver add it back later if needed
    49  			if !strings.Contains(pair.Key, ".") {
    50  				return nil, errors.New("Illegal Key passed into LXC Configurations")
    51  			}
    52  			parts := strings.SplitN(pair.Key, ".", 2)
    53  			out = append(out, fmt.Sprintf("%s=%s", parts[1], pair.Value))
    54  		}
    55  	}
    56  
    57  	return out, nil
    58  }