mirror of https://github.com/docker/cli.git
Change "service inspect" to show defaults in place of empty fields
This adds a new parameter insertDefaults to /services/{id}. When this is set, an empty field (such as UpdateConfig) will be populated with default values in the API response. Make "service inspect" use this, so that empty fields do not result in missing information when inspecting a service. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
3ac3a56f1c
commit
07f55b2eb5
|
@ -123,7 +123,7 @@ type PluginAPIClient interface {
|
||||||
// ServiceAPIClient defines API client methods for the services
|
// ServiceAPIClient defines API client methods for the services
|
||||||
type ServiceAPIClient interface {
|
type ServiceAPIClient interface {
|
||||||
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error)
|
ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error)
|
||||||
ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error)
|
ServiceInspectWithRaw(ctx context.Context, serviceID string, options types.ServiceInspectOptions) (swarm.Service, []byte, error)
|
||||||
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
|
ServiceList(ctx context.Context, options types.ServiceListOptions) ([]swarm.Service, error)
|
||||||
ServiceRemove(ctx context.Context, serviceID string) error
|
ServiceRemove(ctx context.Context, serviceID string) error
|
||||||
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) (types.ServiceUpdateResponse, error)
|
||||||
|
|
|
@ -3,16 +3,21 @@ package client
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServiceInspectWithRaw returns the service information and the raw data.
|
// ServiceInspectWithRaw returns the service information and the raw data.
|
||||||
func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) {
|
func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts types.ServiceInspectOptions) (swarm.Service, []byte, error) {
|
||||||
serverResp, err := cli.get(ctx, "/services/"+serviceID, nil, nil)
|
query := url.Values{}
|
||||||
|
query.Set("insertDefaults", fmt.Sprintf("%v", opts.InsertDefaults))
|
||||||
|
serverResp, err := cli.get(ctx, "/services/"+serviceID, query, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if serverResp.statusCode == http.StatusNotFound {
|
if serverResp.statusCode == http.StatusNotFound {
|
||||||
return swarm.Service{}, nil, serviceNotFoundError{serviceID}
|
return swarm.Service{}, nil, serviceNotFoundError{serviceID}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
"github.com/docker/docker/api/types/swarm"
|
"github.com/docker/docker/api/types/swarm"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
|
@ -18,7 +19,7 @@ func TestServiceInspectError(t *testing.T) {
|
||||||
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing")
|
_, _, err := client.ServiceInspectWithRaw(context.Background(), "nothing", types.ServiceInspectOptions{})
|
||||||
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
if err == nil || err.Error() != "Error response from daemon: Server error" {
|
||||||
t.Fatalf("expected a Server Error, got %v", err)
|
t.Fatalf("expected a Server Error, got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +30,7 @@ func TestServiceInspectServiceNotFound(t *testing.T) {
|
||||||
client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
|
client: newMockClient(errorMock(http.StatusNotFound, "Server error")),
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown")
|
_, _, err := client.ServiceInspectWithRaw(context.Background(), "unknown", types.ServiceInspectOptions{})
|
||||||
if err == nil || !IsErrServiceNotFound(err) {
|
if err == nil || !IsErrServiceNotFound(err) {
|
||||||
t.Fatalf("expected a serviceNotFoundError error, got %v", err)
|
t.Fatalf("expected a serviceNotFoundError error, got %v", err)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ func TestServiceInspect(t *testing.T) {
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id")
|
serviceInspect, _, err := client.ServiceInspectWithRaw(context.Background(), "service_id", types.ServiceInspectOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue