Updating apiClient version using server version

Signed-off-by: Nishant Totla <nishanttotla@gmail.com>
This commit is contained in:
Nishant Totla 2016-04-05 09:17:16 -07:00
parent cbb7c27621
commit 012dffeee3
3 changed files with 31 additions and 1 deletions

View File

@ -347,6 +347,10 @@ func (client *MockClient) ServerVersion(ctx context.Context) (types.Version, err
return args.Get(0).(types.Version), args.Error(1)
}
// UpdateClientVersion updates the client version
func (client *MockClient) UpdateClientVersion(v string) {
}
// VolumeCreate creates a volume in the docker host
func (client *MockClient) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) {
args := client.Mock.Called(ctx, options)

View File

@ -297,6 +297,10 @@ func (client *NopClient) ServerVersion(ctx context.Context) (types.Version, erro
return types.Version{}, errNoEngine
}
// UpdateClientVersion updates the client version
func (client *NopClient) UpdateClientVersion(v string) {
}
// VolumeCreate creates a volume in the docker host
func (client *NopClient) VolumeCreate(ctx context.Context, options types.VolumeCreateRequest) (types.Volume, error) {
return types.Volume{}, errNoEngine

View File

@ -414,6 +414,26 @@ func (e *Engine) CheckConnectionErr(err error) {
// other errors may be ambiguous.
}
// Update API Version in apiClient
func (e *Engine) updateClientVersionFromServer(serverVersion string) {
// v will be >= 1.6, since this is checked earlier
v := version.Version(serverVersion)
switch {
case v.LessThan(version.Version("1.7")):
e.apiClient.UpdateClientVersion("1.18")
case v.LessThan(version.Version("1.8")):
e.apiClient.UpdateClientVersion("1.19")
case v.LessThan(version.Version("1.9")):
e.apiClient.UpdateClientVersion("1.20")
case v.LessThan(version.Version("1.10")):
e.apiClient.UpdateClientVersion("1.21")
case v.LessThan(version.Version("1.11")):
e.apiClient.UpdateClientVersion("1.22")
default:
e.apiClient.UpdateClientVersion("1.23")
}
}
// Gather engine specs (CPU, memory, constraints, ...).
func (e *Engine) updateSpecs() error {
info, err := e.apiClient.Info(context.TODO())
@ -441,8 +461,10 @@ func (e *Engine) updateSpecs() error {
e.CheckConnectionErr(err)
return err
}
// update version
// update server version
e.Version = v.Version
// update client version. engine-api handles backward compatibility where needed
e.updateClientVersionFromServer(v.Version)
e.Lock()
defer e.Unlock()