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
|
||||
}
|
||||
|
||||
func convertNetworks(ctx context.Context, apiClient client.NetworkAPIClient, networks []string) ([]swarm.NetworkAttachmentConfig, error) {
|
||||
nets := []swarm.NetworkAttachmentConfig{}
|
||||
for _, networkIDOrName := range networks {
|
||||
network, err := apiClient.NetworkInspect(ctx, networkIDOrName, false)
|
||||
func convertNetworks(ctx context.Context, apiClient client.NetworkAPIClient, networks opts.NetworkOpt) ([]swarm.NetworkAttachmentConfig, error) {
|
||||
var netAttach []swarm.NetworkAttachmentConfig
|
||||
for _, net := range networks.Value() {
|
||||
networkIDOrName := net.Target
|
||||
_, err := apiClient.NetworkInspect(ctx, networkIDOrName, false)
|
||||
if err != nil {
|
||||
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))
|
||||
return nets, nil
|
||||
sort.Sort(byNetworkTarget(netAttach))
|
||||
return netAttach, nil
|
||||
}
|
||||
|
||||
type endpointOptions struct {
|
||||
|
@ -539,7 +540,7 @@ type serviceOptions struct {
|
|||
placementPrefs placementPrefOpts
|
||||
update updateOptions
|
||||
rollback updateOptions
|
||||
networks opts.ListOpts
|
||||
networks opts.NetworkOpt
|
||||
endpoint endpointOptions
|
||||
|
||||
registryAuth bool
|
||||
|
@ -565,7 +566,6 @@ func newServiceOptions() *serviceOptions {
|
|||
dnsOption: opts.NewListOpts(nil),
|
||||
dnsSearch: opts.NewListOpts(opts.ValidateDNSSearch),
|
||||
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
|
||||
}
|
||||
|
||||
networks, err := convertNetworks(ctx, apiClient, opts.networks.GetAll())
|
||||
networks, err := convertNetworks(ctx, apiClient, opts.networks)
|
||||
if err != nil {
|
||||
return service, err
|
||||
}
|
||||
|
|
|
@ -1028,8 +1028,8 @@ func updateNetworks(ctx context.Context, apiClient client.NetworkAPIClient, flag
|
|||
}
|
||||
|
||||
if flags.Changed(flagNetworkAdd) {
|
||||
values := flags.Lookup(flagNetworkAdd).Value.(*opts.ListOpts).GetAll()
|
||||
networks, err := convertNetworks(ctx, apiClient, values)
|
||||
values := flags.Lookup(flagNetworkAdd).Value.(*opts.NetworkOpt)
|
||||
networks, err := convertNetworks(ctx, apiClient, *values)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue