2014-04-17 17:43:01 -04:00
|
|
|
package daemon
|
2014-03-07 21:42:29 -05:00
|
|
|
|
|
|
|
import (
|
2014-12-08 19:45:42 -05:00
|
|
|
"errors"
|
2014-03-13 12:03:09 -04:00
|
|
|
"fmt"
|
2014-05-23 20:51:16 -04:00
|
|
|
"strings"
|
|
|
|
|
2014-07-24 18:19:50 -04:00
|
|
|
"github.com/docker/docker/nat"
|
|
|
|
"github.com/docker/docker/runconfig"
|
2014-03-07 21:42:29 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2014-12-08 19:45:42 -05:00
|
|
|
func mergeLxcConfIntoOptions(hostConfig *runconfig.HostConfig) ([]string, error) {
|
2014-03-13 12:03:09 -04:00
|
|
|
if hostConfig == nil {
|
2014-12-08 19:45:42 -05:00
|
|
|
return nil, nil
|
2014-03-13 12:03:09 -04:00
|
|
|
}
|
|
|
|
|
2014-09-29 18:40:26 -04:00
|
|
|
out := []string{}
|
|
|
|
|
2014-03-13 12:03:09 -04:00
|
|
|
// merge in the lxc conf options into the generic config map
|
|
|
|
if lxcConf := hostConfig.LxcConf; lxcConf != nil {
|
2015-04-10 20:05:21 -04:00
|
|
|
lxSlice := lxcConf.Slice()
|
|
|
|
for _, pair := range lxSlice {
|
2014-03-13 12:03:09 -04:00
|
|
|
// 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
|
2014-12-08 19:45:42 -05:00
|
|
|
if !strings.Contains(pair.Key, ".") {
|
|
|
|
return nil, errors.New("Illegal Key passed into LXC Configurations")
|
|
|
|
}
|
2014-03-13 12:03:09 -04:00
|
|
|
parts := strings.SplitN(pair.Key, ".", 2)
|
2014-09-29 18:40:26 -04:00
|
|
|
out = append(out, fmt.Sprintf("%s=%s", parts[1], pair.Value))
|
2014-03-13 12:03:09 -04:00
|
|
|
}
|
|
|
|
}
|
2014-09-29 18:40:26 -04:00
|
|
|
|
2014-12-08 19:45:42 -05:00
|
|
|
return out, nil
|
2014-03-13 12:03:09 -04:00
|
|
|
}
|