Browse Source

Add support for changing network.

pull/2/head
Chris Smith 7 years ago
parent
commit
b6443e3c82
3 changed files with 25 additions and 4 deletions
  1. 2
    1
      README.md
  2. 13
    1
      docker_rerun.py
  3. 10
    2
      test.py

+ 2
- 1
README.md View File

@@ -51,7 +51,7 @@ At present docker-rerun supports copying a number of commonly used arguments:
51 51
  * Labels (-l/--label)
52 52
  * Links (--link)
53 53
  * Names (--name)
54
- * Networks (--net)
54
+ * Networks (--network)
55 55
  * Port publications (-p)
56 56
  * Restart policies (--restart)
57 57
  * User switching (-u/--user)
@@ -79,6 +79,7 @@ of the container's parameters.
79 79
                             would happen.
80 80
       --pull                Docker pull the image before re-running the container
81 81
       --image IMAGE         Image to use in place of the original
82
+      --network NETWORK     The new network configuration to use
82 83
       --port PORT, -p PORT  Additional port to expose
83 84
       --tag TAG             Image tag (version) to use
84 85
 

+ 13
- 1
docker_rerun.py View File

@@ -165,7 +165,7 @@ def handle_network_mode(container):
165 165
     """Copies the network mode (--net) argument."""
166 166
     network = container.info['HostConfig']['NetworkMode']
167 167
     if network != 'default':
168
-        container.args.append('--net=%s' % network)
168
+        container.args.append('--network=%s' % network)
169 169
 
170 170
 
171 171
 def handle_ports(container):
@@ -219,6 +219,18 @@ def modify_image(parser=None, args=None, container=None):
219 219
         container.image = args.image
220 220
 
221 221
 
222
+def modify_network(parser=None, args=None, container=None):
223
+    """Allows the network to be modified."""
224
+    if parser:
225
+        parser.add_argument('--network',
226
+                            help='The new network configuration to use')
227
+    elif args.network:
228
+        # Get rid of any existing network options, and add the new one
229
+        container.args = [a for a in container.args
230
+                          if not a.startswith('--network=')]
231
+        container.args.extend(['--network=%s' % args.network])
232
+
233
+
222 234
 def modify_port_add(parser=None, args=None, container=None):
223 235
     """Allows a additional ports to be exposed."""
224 236
     if parser:

+ 10
- 2
test.py View File

@@ -39,12 +39,12 @@ def test_command_matches():
39 39
     yield check, ['docker', 'run', '--env=FOO=bar baz', '--name=test123', '-d', 'hello-world']
40 40
     yield check, ['docker', 'run', '--name=test123', '--restart=always', '-d', 'hello-world']
41 41
     yield check, ['docker', 'run', '--name=test123', '--restart=on-failure:10', '-d', 'hello-world']
42
-    yield check, ['docker', 'run', '--name=test123', '--net=host', '-d', 'hello-world']
42
+    yield check, ['docker', 'run', '--name=test123', '--network=host', '-d', 'hello-world']
43 43
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=127.0.0.1:443:443', '-p=127.0.0.1::1336/udp', 'hello-world']
44 44
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=443', 'hello-world']
45 45
     yield check, ['docker', 'run', '--name=test123', '-d', '-p=80:80', '-p=90', 'hello-world']
46 46
     yield check, ['docker', 'run', '--name=test123', '--user=root', '-d', 'hello-world', '/hello', 'foobar']
47
-    yield check, ['docker', 'run', '--name=test123', '--net=host', '--user=root:root', '-d', 'hello-world']
47
+    yield check, ['docker', 'run', '--name=test123', '--network=host', '--user=root:root', '-d', 'hello-world']
48 48
     yield check, ['docker', 'run', '--name=test123', '--volume=/dev/null:/null', '--volume=/dev/urandom:/mnt/random', '-d', 'hello-world']
49 49
     yield check, ['docker', 'run', '--label=com.example=123 456', '--name=test123', '-d', 'hello-world']
50 50
     yield check, ['docker', 'run', '--label=com.example.1', '--label=com.example.2=345', '--name=test123', '-d', 'hello-world']
@@ -73,6 +73,14 @@ def test_modifiers():
73 73
            ['docker', 'run', '--name=test123', '-d', 'hello-world'],
74 74
            ['--tag', 'latest'],
75 75
            ['docker', 'run', '--name=test123', '-d', 'hello-world:latest'])
76
+    yield (check,
77
+           ['docker', 'run', '--name=test123', '-d', 'hello-world'],
78
+           ['--network', 'none'],
79
+           ['docker', 'run', '--name=test123', '--network=none', '-d', 'hello-world'])
80
+    yield (check,
81
+           ['docker', 'run', '--name=test123', '--network=host', '-d', 'hello-world'],
82
+           ['--network', 'none'],
83
+           ['docker', 'run', '--name=test123', '--network=none', '-d', 'hello-world'])
76 84
 
77 85
 
78 86
 @with_setup(setup_each, teardown_each)

Loading…
Cancel
Save