mirror of https://github.com/docker/cli.git
Adding network options to service create/update
Changes added to accept network specific options in docker service create/update Signed-off-by: Abhinandan Prativadi <abhi@docker.com>
This commit is contained in:
parent
d156151ba1
commit
40341ae089
|
@ -396,17 +396,18 @@ func (c *credentialSpecOpt) Value() *swarm.CredentialSpec {
|
||||||
return c.value
|
return c.value
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertNetworks(ctx context.Context, apiClient client.NetworkAPIClient, networks []string) ([]swarm.NetworkAttachmentConfig, error) {
|
func convertNetworks(ctx context.Context, apiClient client.NetworkAPIClient, networks opts.NetworkOpt) ([]swarm.NetworkAttachmentConfig, error) {
|
||||||
nets := []swarm.NetworkAttachmentConfig{}
|
var netAttach []swarm.NetworkAttachmentConfig
|
||||||
for _, networkIDOrName := range networks {
|
for _, net := range networks.Value() {
|
||||||
network, err := apiClient.NetworkInspect(ctx, networkIDOrName, false)
|
networkIDOrName := net.Target
|
||||||
|
_, err := apiClient.NetworkInspect(ctx, networkIDOrName, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
nets = append(nets, swarm.NetworkAttachmentConfig{Target: network.ID})
|
netAttach = append(netAttach, swarm.NetworkAttachmentConfig{Target: net.Target, Aliases: net.Aliases, DriverOpts: net.DriverOpts})
|
||||||
}
|
}
|
||||||
sort.Sort(byNetworkTarget(nets))
|
sort.Sort(byNetworkTarget(netAttach))
|
||||||
return nets, nil
|
return netAttach, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type endpointOptions struct {
|
type endpointOptions struct {
|
||||||
|
@ -539,7 +540,7 @@ type serviceOptions struct {
|
||||||
placementPrefs placementPrefOpts
|
placementPrefs placementPrefOpts
|
||||||
update updateOptions
|
update updateOptions
|
||||||
rollback updateOptions
|
rollback updateOptions
|
||||||
networks opts.ListOpts
|
networks opts.NetworkOpt
|
||||||
endpoint endpointOptions
|
endpoint endpointOptions
|
||||||
|
|
||||||
registryAuth bool
|
registryAuth bool
|
||||||
|
@ -565,7 +566,6 @@ func newServiceOptions() *serviceOptions {
|
||||||
dnsOption: opts.NewListOpts(nil),
|
dnsOption: opts.NewListOpts(nil),
|
||||||
dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch),
|
dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch),
|
||||||
hosts: opts.NewListOpts(opts.ValidateExtraHost),
|
hosts: opts.NewListOpts(opts.ValidateExtraHost),
|
||||||
networks: opts.NewListOpts(nil),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -627,7 +627,7 @@ func (opts *serviceOptions) ToService(ctx context.Context, apiClient client.Netw
|
||||||
return service, err
|
return service, err
|
||||||
}
|
}
|
||||||
|
|
||||||
networks, err := convertNetworks(ctx, apiClient, opts.networks.GetAll())
|
networks, err := convertNetworks(ctx, apiClient, opts.networks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return service, err
|
return service, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -1028,8 +1028,8 @@ func updateNetworks(ctx context.Context, apiClient client.NetworkAPIClient, flag
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.Changed(flagNetworkAdd) {
|
if flags.Changed(flagNetworkAdd) {
|
||||||
values := flags.Lookup(flagNetworkAdd).Value.(*opts.ListOpts).GetAll()
|
values := flags.Lookup(flagNetworkAdd).Value.(*opts.NetworkOpt)
|
||||||
networks, err := convertNetworks(ctx, apiClient, values)
|
networks, err := convertNetworks(ctx, apiClient, *values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue