From 3025738377410a7a668c4bab835e0008048b56fb Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Mon, 15 May 2017 13:28:08 +0000 Subject: [PATCH] Extract pluginNameFromAddress() function --- plugin/plugin.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index ddbc7327..91fb39d6 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -57,8 +57,7 @@ func run(dockerClient *docker.Client, weave *weaveapi.Client, address, meshAddre if !isPluginV2 { Log.Println("Creating default 'weave' network") options := map[string]interface{}{MulticastOption: "true"} - // TODO: the driver name should be extracted from pluginMeshSocket - dockerClient.EnsureNetwork("weave", "weavemesh", defaultSubnet, options) + dockerClient.EnsureNetwork("weave", pluginNameFromAddress(meshAddress), defaultSubnet, options) } ready() @@ -70,7 +69,7 @@ func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address if isPluginV2 { name = pluginV2Name } else { - name = strings.TrimSuffix(path.Base(address), ".sock") + name = pluginNameFromAddress(address) } d, err := netplugin.New(dockerClient, weave, name, scope, dns, isPluginV2, forceMulticast) @@ -95,3 +94,8 @@ func listenAndServe(dockerClient *docker.Client, weave *weaveapi.Client, address return listener, nil } + +// Take a socket address like "/run/docker/plugins/weavemesh.sock" and extract the plugin name "weavemesh" +func pluginNameFromAddress(address string) string { + return strings.TrimSuffix(path.Base(address), ".sock") +}