2014-02-12 08:04:39 +04:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2015-04-11 03:05:21 +03:00
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2014-05-03 03:59:28 +04:00
|
|
|
|
2016-01-05 03:05:26 +03:00
|
|
|
"github.com/docker/engine-api/types/container"
|
2014-02-12 08:04:39 +04:00
|
|
|
)
|
|
|
|
|
2015-07-25 12:11:45 +03:00
|
|
|
// DecodeHostConfig creates a HostConfig based on the specified Reader.
|
|
|
|
// It assumes the content of the reader will be JSON, and decodes it.
|
2015-12-18 21:36:17 +03:00
|
|
|
func DecodeHostConfig(src io.Reader) (*container.HostConfig, error) {
|
2015-04-11 03:05:21 +03:00
|
|
|
decoder := json.NewDecoder(src)
|
|
|
|
|
2015-05-14 17:39:44 +03:00
|
|
|
var w ContainerConfigWrapper
|
2015-04-11 03:05:21 +03:00
|
|
|
if err := decoder.Decode(&w); err != nil {
|
|
|
|
return nil, err
|
2014-07-11 01:51:15 +04:00
|
|
|
}
|
2014-08-05 03:14:43 +04:00
|
|
|
|
2015-07-10 01:12:36 +03:00
|
|
|
hc := w.getHostConfig()
|
2015-04-11 03:05:21 +03:00
|
|
|
return hc, nil
|
2014-02-12 08:04:39 +04:00
|
|
|
}
|
2015-07-10 01:12:36 +03:00
|
|
|
|
|
|
|
// SetDefaultNetModeIfBlank changes the NetworkMode in a HostConfig structure
|
|
|
|
// to default if it is not populated. This ensures backwards compatibility after
|
|
|
|
// the validation of the network mode was moved from the docker CLI to the
|
|
|
|
// docker daemon.
|
2015-12-18 21:36:17 +03:00
|
|
|
func SetDefaultNetModeIfBlank(hc *container.HostConfig) *container.HostConfig {
|
2015-07-10 01:12:36 +03:00
|
|
|
if hc != nil {
|
2015-12-18 21:36:17 +03:00
|
|
|
if hc.NetworkMode == container.NetworkMode("") {
|
|
|
|
hc.NetworkMode = container.NetworkMode("default")
|
2015-07-10 01:12:36 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return hc
|
|
|
|
}
|