2014-02-11 23:04:39 -05:00
|
|
|
package runconfig
|
|
|
|
|
|
|
|
import (
|
2015-04-10 20:05:21 -04:00
|
|
|
"encoding/json"
|
|
|
|
"io"
|
2014-05-02 19:59:28 -04:00
|
|
|
|
2015-12-18 13:36:17 -05:00
|
|
|
"github.com/docker/docker/api/types/container"
|
2014-02-11 23:04:39 -05:00
|
|
|
)
|
|
|
|
|
2015-07-25 05:11:45 -04: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 13:36:17 -05:00
|
|
|
func DecodeHostConfig(src io.Reader) (*container.HostConfig, error) {
|
2015-04-10 20:05:21 -04:00
|
|
|
decoder := json.NewDecoder(src)
|
|
|
|
|
2015-05-14 10:39:44 -04:00
|
|
|
var w ContainerConfigWrapper
|
2015-04-10 20:05:21 -04:00
|
|
|
if err := decoder.Decode(&w); err != nil {
|
|
|
|
return nil, err
|
2014-07-10 17:51:15 -04:00
|
|
|
}
|
2014-08-04 19:14:43 -04:00
|
|
|
|
2015-07-09 18:12:36 -04:00
|
|
|
hc := w.getHostConfig()
|
2015-04-10 20:05:21 -04:00
|
|
|
return hc, nil
|
2014-02-11 23:04:39 -05:00
|
|
|
}
|
2015-07-09 18:12:36 -04: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 13:36:17 -05:00
|
|
|
func SetDefaultNetModeIfBlank(hc *container.HostConfig) *container.HostConfig {
|
2015-07-09 18:12:36 -04:00
|
|
|
if hc != nil {
|
2015-12-18 13:36:17 -05:00
|
|
|
if hc.NetworkMode == container.NetworkMode("") {
|
|
|
|
hc.NetworkMode = container.NetworkMode("default")
|
2015-07-09 18:12:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return hc
|
|
|
|
}
|