1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

re-vendor engine-api

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2016-07-05 11:20:49 -04:00 committed by Brian Goff
parent a04a11f3e5
commit 140ec59db6
11 changed files with 64 additions and 19 deletions

View file

@ -5,6 +5,7 @@ import (
"github.com/docker/docker/api/client" "github.com/docker/docker/api/client"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/engine-api/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -33,7 +34,7 @@ func newCreateCommand(dockerCli *client.DockerCli) *cobra.Command {
func runCreate(dockerCli *client.DockerCli, opts *serviceOptions) error { func runCreate(dockerCli *client.DockerCli, opts *serviceOptions) error {
apiClient := dockerCli.Client() apiClient := dockerCli.Client()
headers := map[string][]string{} createOpts := types.ServiceCreateOptions{}
service, err := opts.ToService() service, err := opts.ToService()
if err != nil { if err != nil {
@ -49,10 +50,10 @@ func runCreate(dockerCli *client.DockerCli, opts *serviceOptions) error {
if err != nil { if err != nil {
return err return err
} }
headers["X-Registry-Auth"] = []string{encodedAuth} createOpts.EncodedRegistryAuth = encodedAuth
} }
response, err := apiClient.ServiceCreate(ctx, service, headers) response, err := apiClient.ServiceCreate(ctx, service, createOpts)
if err != nil { if err != nil {
return err return err
} }

View file

@ -169,7 +169,7 @@ func printContainerSpec(out io.Writer, containerSpec swarm.ContainerSpec) {
for _, v := range containerSpec.Mounts { for _, v := range containerSpec.Mounts {
fmt.Fprintf(out, " Target = %s\n", v.Target) fmt.Fprintf(out, " Target = %s\n", v.Target)
fmt.Fprintf(out, " Source = %s\n", v.Source) fmt.Fprintf(out, " Source = %s\n", v.Source)
fmt.Fprintf(out, " Writable = %v\n", v.Writable) fmt.Fprintf(out, " ReadOnly = %v\n", v.ReadOnly)
fmt.Fprintf(out, " Type = %v\n", v.Type) fmt.Fprintf(out, " Type = %v\n", v.Type)
} }
} }

View file

@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/client" "github.com/docker/docker/api/client"
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/engine-api/types"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -77,7 +78,7 @@ func runServiceScale(dockerCli *client.DockerCli, serviceID string, scale string
} }
serviceMode.Replicated.Replicas = &uintScale serviceMode.Replicated.Replicas = &uintScale
err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, nil) err = client.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, types.ServiceUpdateOptions{})
if err != nil { if err != nil {
return err return err
} }

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/cli" "github.com/docker/docker/cli"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
runconfigopts "github.com/docker/docker/runconfig/opts" runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/swarm" "github.com/docker/engine-api/types/swarm"
"github.com/docker/go-connections/nat" "github.com/docker/go-connections/nat"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -39,7 +40,7 @@ func newUpdateCommand(dockerCli *client.DockerCli) *cobra.Command {
func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID string) error { func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID string) error {
apiClient := dockerCli.Client() apiClient := dockerCli.Client()
ctx := context.Background() ctx := context.Background()
headers := map[string][]string{} updateOpts := types.ServiceUpdateOptions{}
service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID) service, _, err := apiClient.ServiceInspectWithRaw(ctx, serviceID)
if err != nil { if err != nil {
@ -64,10 +65,10 @@ func runUpdate(dockerCli *client.DockerCli, flags *pflag.FlagSet, serviceID stri
if err != nil { if err != nil {
return err return err
} }
headers["X-Registry-Auth"] = []string{encodedAuth} updateOpts.EncodedRegistryAuth = encodedAuth
} }
err = apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, headers) err = apiClient.ServiceUpdate(ctx, service.ID, service.Version, service.Spec, updateOpts)
if err != nil { if err != nil {
return err return err
} }

View file

@ -184,13 +184,13 @@ func deployServices(
if service, exists := existingServiceMap[name]; exists { if service, exists := existingServiceMap[name]; exists {
fmt.Fprintf(out, "Updating service %s (id: %s)\n", name, service.ID) fmt.Fprintf(out, "Updating service %s (id: %s)\n", name, service.ID)
// TODO(nishanttotla): Pass headers with X-Registry-Auth // TODO(nishanttotla): Pass auth token
if err := apiClient.ServiceUpdate( if err := apiClient.ServiceUpdate(
ctx, ctx,
service.ID, service.ID,
service.Version, service.Version,
serviceSpec, serviceSpec,
nil, types.ServiceUpdateOptions{},
); err != nil { ); err != nil {
return err return err
} }
@ -198,7 +198,7 @@ func deployServices(
fmt.Fprintf(out, "Creating service %s\n", name) fmt.Fprintf(out, "Creating service %s\n", name)
// TODO(nishanttotla): Pass headers with X-Registry-Auth // TODO(nishanttotla): Pass headers with X-Registry-Auth
if _, err := apiClient.ServiceCreate(ctx, serviceSpec, nil); err != nil { if _, err := apiClient.ServiceCreate(ctx, serviceSpec, types.ServiceCreateOptions{}); err != nil {
return err return err
} }
} }

View file

@ -60,7 +60,7 @@ clone git golang.org/x/net 2beffdc2e92c8a3027590f898fe88f69af48a3f8 https://gith
clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git clone git golang.org/x/sys eb2c74142fd19a79b3f237334c7384d5167b1b46 https://github.com/golang/sys.git
clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3 clone git github.com/docker/go-units 651fc226e7441360384da338d0fd37f2440ffbe3
clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d clone git github.com/docker/go-connections fa2850ff103453a9ad190da0df0af134f0314b3d
clone git github.com/docker/engine-api 62043eb79d581a32ea849645277023c550732e52 clone git github.com/docker/engine-api 139c221fcbe6e67dfac3c8807870e7136884a45b
clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837 clone git github.com/RackSec/srslog 259aed10dfa74ea2961eddd1d9847619f6e98837
clone git github.com/imdario/mergo 0.2.1 clone git github.com/imdario/mergo 0.2.1

View file

@ -100,11 +100,11 @@ type NodeAPIClient 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, headers map[string][]string) (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) (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, headers map[string][]string) error ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) error
TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error)
TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error) TaskList(ctx context.Context, options types.TaskListOptions) ([]swarm.Task, error)
} }

View file

@ -9,7 +9,15 @@ import (
) )
// ServiceCreate creates a new Service. // ServiceCreate creates a new Service.
func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, headers map[string][]string) (types.ServiceCreateResponse, error) { func (cli *Client) ServiceCreate(ctx context.Context, service swarm.ServiceSpec, options types.ServiceCreateOptions) (types.ServiceCreateResponse, error) {
var headers map[string][]string
if options.EncodedRegistryAuth != "" {
headers = map[string][]string{
"X-Registry-Auth": []string{options.EncodedRegistryAuth},
}
}
var response types.ServiceCreateResponse var response types.ServiceCreateResponse
resp, err := cli.post(ctx, "/services/create", nil, service, headers) resp, err := cli.post(ctx, "/services/create", nil, service, headers)
if err != nil { if err != nil {

View file

@ -4,14 +4,26 @@ import (
"net/url" "net/url"
"strconv" "strconv"
"github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/swarm" "github.com/docker/engine-api/types/swarm"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
// ServiceUpdate updates a Service. // ServiceUpdate updates a Service.
func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, headers map[string][]string) error { func (cli *Client) ServiceUpdate(ctx context.Context, serviceID string, version swarm.Version, service swarm.ServiceSpec, options types.ServiceUpdateOptions) error {
query := url.Values{} var (
headers map[string][]string
query = url.Values{}
)
if options.EncodedRegistryAuth != "" {
headers = map[string][]string{
"X-Registry-Auth": []string{options.EncodedRegistryAuth},
}
}
query.Set("version", strconv.FormatUint(version.Index, 10)) query.Set("version", strconv.FormatUint(version.Index, 10))
resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers) resp, err := cli.post(ctx, "/services/"+serviceID+"/update", query, service, headers)
ensureReaderClosed(resp) ensureReaderClosed(resp)
return err return err

View file

@ -246,6 +246,15 @@ type NodeListOptions struct {
Filter filters.Args Filter filters.Args
} }
// ServiceCreateOptions contains the options to use when creating a service.
type ServiceCreateOptions struct {
// EncodedRegistryAuth is the encoded registry authorization credentials to
// use when updating the service.
//
// This field follows the format of the X-Registry-Auth header.
EncodedRegistryAuth string
}
// ServiceCreateResponse contains the information returned to a client // ServiceCreateResponse contains the information returned to a client
// on the creation of a new service. // on the creation of a new service.
type ServiceCreateResponse struct { type ServiceCreateResponse struct {
@ -253,6 +262,19 @@ type ServiceCreateResponse struct {
ID string ID string
} }
// ServiceUpdateOptions contains the options to be used for updating services.
type ServiceUpdateOptions struct {
// EncodedRegistryAuth is the encoded registry authorization credentials to
// use when updating the service.
//
// This field follows the format of the X-Registry-Auth header.
EncodedRegistryAuth string
// TODO(stevvooe): Consider moving the version parameter of ServiceUpdate
// into this field. While it does open API users up to racy writes, most
// users may not need that level of consistency in practice.
}
// ServiceListOptions holds parameters to list services with. // ServiceListOptions holds parameters to list services with.
type ServiceListOptions struct { type ServiceListOptions struct {
Filter filters.Args Filter filters.Args

View file

@ -30,7 +30,7 @@ type Mount struct {
Type MountType `json:",omitempty"` Type MountType `json:",omitempty"`
Source string `json:",omitempty"` Source string `json:",omitempty"`
Target string `json:",omitempty"` Target string `json:",omitempty"`
Writable bool `json:",omitempty"` ReadOnly bool `json:",omitempty"`
BindOptions *BindOptions `json:",omitempty"` BindOptions *BindOptions `json:",omitempty"`
VolumeOptions *VolumeOptions `json:",omitempty"` VolumeOptions *VolumeOptions `json:",omitempty"`
@ -61,7 +61,7 @@ type BindOptions struct {
// VolumeOptions represents the options for a mount of type volume. // VolumeOptions represents the options for a mount of type volume.
type VolumeOptions struct { type VolumeOptions struct {
Populate bool `json:",omitempty"` NoCopy bool `json:",omitempty"`
Labels map[string]string `json:",omitempty"` Labels map[string]string `json:",omitempty"`
DriverConfig *Driver `json:",omitempty"` DriverConfig *Driver `json:",omitempty"`
} }