daemon/utils.go
359b7df5
 package daemon
36c3614f
 
 import (
8dcbd6ab
 	"errors"
7a3070a6
 	"fmt"
6ec86cb6
 	"strings"
 
b3ee9ac7
 	"github.com/docker/docker/nat"
 	"github.com/docker/docker/runconfig"
36c3614f
 )
 
 func migratePortMappings(config *runconfig.Config, hostConfig *runconfig.HostConfig) error {
 	if config.PortSpecs != nil {
 		ports, bindings, err := nat.ParsePortSpecs(config.PortSpecs)
 		if err != nil {
 			return err
 		}
 		config.PortSpecs = nil
 		if len(bindings) > 0 {
 			if hostConfig == nil {
 				hostConfig = &runconfig.HostConfig{}
 			}
 			hostConfig.PortBindings = bindings
 		}
 
 		if config.ExposedPorts == nil {
 			config.ExposedPorts = make(nat.PortSet, len(ports))
 		}
 		for k, v := range ports {
 			config.ExposedPorts[k] = v
 		}
 	}
 	return nil
 }
 
8dcbd6ab
 func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig) ([]string, error) {
7a3070a6
 	if hostConfig == nil {
8dcbd6ab
 		return nil, nil
7a3070a6
 	}
 
32dca1a7
 	out := []string{}
 
7a3070a6
 	// merge in the lxc conf options into the generic config map
 	if lxcConf := hostConfig.LxcConf; lxcConf != nil {
767df67e
 		lxSlice := lxcConf.Slice()
 		for _, pair := range lxSlice {
7a3070a6
 			// because lxc conf gets the driver name lxc.XXXX we need to trim it off
 			// and let the lxc driver add it back later if needed
8dcbd6ab
 			if !strings.Contains(pair.Key, ".") {
 				return nil, errors.New("Illegal Key passed into LXC Configurations")
 			}
7a3070a6
 			parts := strings.SplitN(pair.Key, ".", 2)
32dca1a7
 			out = append(out, fmt.Sprintf("%s=%s", parts[1], pair.Value))
7a3070a6
 		}
 	}
32dca1a7
 
8dcbd6ab
 	return out, nil
7a3070a6
 }