github.com/dougm/docker@v1.5.0/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  		for _, pair := range lxcConf {
    46  			// because lxc conf gets the driver name lxc.XXXX we need to trim it off
    47  			// and let the lxc driver add it back later if needed
    48  			if !strings.Contains(pair.Key, ".") {
    49  				return nil, errors.New("Illegal Key passed into LXC Configurations")
    50  			}
    51  			parts := strings.SplitN(pair.Key, ".", 2)
    52  			out = append(out, fmt.Sprintf("%s=%s", parts[1], pair.Value))
    53  		}
    54  	}
    55  
    56  	return out, nil
    57  }