Repository: gabrieldemarmiesse/python-on-whales (language: python)

Issue:
'Network Disconnect' calls cli command 'network disconnet'; fails on call
As referenced in the subject line, the CLI command called by the 'docker network disconnect' command in python is shown in the traceback as failing due to the CLI command 'docker network disconnet'


Discussion / hints:
Thanks for the report! I'll take a look.

On Sat, 7 May 2022, 00:33 Chris Eloranta, ***@***.***> wrote:

> As referenced in the subject line, the CLI command called by the 'docker
> network disconnect' command in python is shown in the traceback as failing
> due to the CLI command 'docker network disconnet'
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/gabrieldemarmiesse/python-on-whales/issues/330>, or
> unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ADCLMK5RSQRVT6UXG36AXH3VIWM4RANCNFSM5VJM5QEQ>
> .
> You are receiving this because you are subscribed to this thread.Message
> ID: ***@***.***>
>


Fix patch:
diff --git a/python_on_whales/components/network/cli_wrapper.py b/python_on_whales/components/network/cli_wrapper.py
index 6b9535cc..3f5449ec 100644
--- a/python_on_whales/components/network/cli_wrapper.py
+++ b/python_on_whales/components/network/cli_wrapper.py
@@ -142,6 +142,17 @@ def connect(
             python_on_whales.components.container.cli_wrapper.ValidContainer
         ] = [],
     ) -> None:
+        """Connect a container to a network
+
+        # Arguments
+            network: The network to connect to
+            container: The container to connect
+            alias: Add network-scoped alias for the container
+            driver_options: Driver options for the network
+            ip: IPv4 address (e.g., `"172.30.100.104"`)
+            ip6: IPv6 address (e.g., `"2001:db8::33"`)
+            links: Add links to other containers
+        """
         full_cmd = self.docker_cmd + ["network", "connect"]
         full_cmd.add_simple_arg("--alias", alias)
         full_cmd.add_args_list("--driver-opt", driver_options)
@@ -185,7 +196,13 @@ def disconnect(
         container: python_on_whales.components.container.cli_wrapper.ValidContainer,
         force: bool = False,
     ):
-        full_cmd = self.docker_cmd + ["network", "disconnet"]
+        """Disconnect a container from a network
+
+        # Arguments
+            network: The name of the network.
+            container: The container to disconnect.
+        """
+        full_cmd = self.docker_cmd + ["network", "disconnect"]
         full_cmd.add_flag("--force", force)
         full_cmd += [network, container]
         run(full_cmd)


Test patch:
diff --git a/tests/python_on_whales/components/test_network.py b/tests/python_on_whales/components/test_network.py
index a453c756..0acdeab7 100644
--- a/tests/python_on_whales/components/test_network.py
+++ b/tests/python_on_whales/components/test_network.py
@@ -43,5 +43,14 @@ def test_context_manager():
     assert my_net not in docker.network.list()
 
 
+def test_network_connect_disconnect():
+    with docker.network.create(random_name()) as my_net:
+        with docker.container.run(
+            "busybox:1", ["sleep", "infinity"], detach=True
+        ) as my_container:
+            docker.network.connect(my_net, my_container)
+            docker.network.disconnect(my_net, my_container)
+
+
 def test_remove_nothing():
     docker.network.remove([])