void setNetworkMode(Instance instance, ContainerConfig containerConfig, HostConfig hostConfig) {
if(DataAccessor.fields(instance).withKey(FIELD_NETWORK_MODE).get() != null)
return;
String netMode = null;
if (containerConfig != null && containerConfig.isNetworkDisabled()) {
netMode = NetworkConstants.NETWORK_MODE_NONE;
} else if (hostConfig != null) {
String inspectNetMode = hostConfig.getNetworkMode();
if (NetworkConstants.NETWORK_MODE_BRIDGE.equals(inspectNetMode) ||
NetworkConstants.NETWORK_MODE_HOST.equals(inspectNetMode) ||
NetworkConstants.NETWORK_MODE_NONE.equals(inspectNetMode)) {
netMode = inspectNetMode;
} else if (NetworkConstants.NETWORK_MODE_DEFAULT.equals(inspectNetMode) || StringUtils.isBlank(inspectNetMode)) {
netMode = NetworkConstants.NETWORK_MODE_BRIDGE;
} else if (StringUtils.startsWith(inspectNetMode, NetworkConstants.NETWORK_MODE_CONTAINER)) {
throw new ClientVisibleException(ResponseCodes.UNPROCESSABLE_ENTITY, ValidationErrorCodes.INVALID_OPTION,
"Transformer API does not support container network mode.", null);
} else {
throw new ClientVisibleException(ResponseCodes.UNPROCESSABLE_ENTITY, ValidationErrorCodes.INVALID_OPTION,
"Unrecognized network mode: " + inspectNetMode, null);
}
}
setField(instance, FIELD_NETWORK_MODE, netMode);
}