2016-09-06 21:46:37 +03:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2016-11-15 05:08:24 +03:00
|
|
|
"encoding/json"
|
2016-09-06 21:46:37 +03:00
|
|
|
"net/url"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ServiceUpdate updates a Service.
|
2016-11-15 05:08:24 +03:00
|
|
|
func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error) {
|
2016-09-06 21:46:37 +03:00
|
|
|
var (
|
|
|
|
headers map[string][]string
|
|
|
|
query = url.Values{}
|
|
|
|
)
|
|
|
|
|
|
|
|
if options.EncodedRegistryAuth != "" {
|
|
|
|
headers = map[string][]string{
|
|
|
|
"X-Registry-Auth": {options.EncodedRegistryAuth},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-08 02:32:44 +03:00
|
|
|
if options.RegistryAuthFrom != "" {
|
|
|
|
query.Set("registryAuthFrom", options.RegistryAuthFrom)
|
|
|
|
}
|
|
|
|
|
2017-02-16 20:27:01 +03:00
|
|
|
if options.Rollback != "" {
|
|
|
|
query.Set("rollback", options.Rollback)
|
|
|
|
}
|
|
|
|
|
2016-09-06 21:46:37 +03:00
|
|
|
query.Set("version", strconv.FormatUint(version.Index, 10))
|
|
|
|
|
2016-11-15 05:08:24 +03:00
|
|
|
var response types.ServiceUpdateResponse
|
2016-09-06 21:46:37 +03:00
|
|
|
resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers)
|
2016-11-15 05:08:24 +03:00
|
|
|
if err != nil {
|
|
|
|
return response, err
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.NewDecoder(resp.body).Decode(&response)
|
2016-09-06 21:46:37 +03:00
|
|
|
ensureReaderClosed(resp)
|
2016-11-15 05:08:24 +03:00
|
|
|
return response, err
|
2016-09-06 21:46:37 +03:00
|
|
|
}
|