File tree Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Expand file tree Collapse file tree 2 files changed +20
-11
lines changed Original file line number Diff line number Diff line change 1
1
import copy
2
+ import ntpath
2
3
from collections import namedtuple
3
4
4
5
from ..api import APIClient
@@ -995,20 +996,25 @@ def _create_container_args(kwargs):
995
996
# sort to make consistent for tests
996
997
create_kwargs ['ports' ] = [tuple (p .split ('/' , 1 ))
997
998
for p in sorted (port_bindings .keys ())]
998
- binds = create_kwargs ['host_config' ].get ('Binds' )
999
- if binds :
1000
- create_kwargs ['volumes' ] = [_host_volume_from_bind (v ) for v in binds ]
999
+ if volumes :
1000
+ if isinstance (volumes , dict ):
1001
+ create_kwargs ['volumes' ] = [
1002
+ v .get ('bind' ) for v in volumes .values ()
1003
+ ]
1004
+ else :
1005
+ create_kwargs ['volumes' ] = [
1006
+ _host_volume_from_bind (v ) for v in volumes
1007
+ ]
1001
1008
return create_kwargs
1002
1009
1003
1010
1004
1011
def _host_volume_from_bind (bind ):
1005
- bits = bind .split (':' )
1006
- if len (bits ) == 1 :
1007
- return bits [0 ]
1008
- elif len (bits ) == 2 and bits [1 ] in ('ro' , 'rw' ):
1009
- return bits [0 ]
1012
+ drive , rest = ntpath .splitdrive (bind )
1013
+ bits = rest .split (':' , 1 )
1014
+ if len (bits ) == 1 or bits [1 ] in ('ro' , 'rw' ):
1015
+ return drive + bits [0 ]
1010
1016
else :
1011
- return bits [1 ]
1017
+ return bits [1 ]. rstrip ( ':ro' ). rstrip ( ':rw' )
1012
1018
1013
1019
1014
1020
ExecResult = namedtuple ('ExecResult' , 'exit_code,output' )
Original file line number Diff line number Diff line change @@ -102,6 +102,7 @@ def test_create_container_args(self):
102
102
'volumename:/mnt/vol3' ,
103
103
'/volumewithnohostpath' ,
104
104
'/anothervolumewithnohostpath:ro' ,
105
+ 'C:\\ windows\\ path:D:\\ hello\\ world:rw'
105
106
],
106
107
volumes_from = ['container' ],
107
108
working_dir = '/code'
@@ -120,7 +121,8 @@ def test_create_container_args(self):
120
121
'/var/www:/mnt/vol1:ro' ,
121
122
'volumename:/mnt/vol3' ,
122
123
'/volumewithnohostpath' ,
123
- '/anothervolumewithnohostpath:ro'
124
+ '/anothervolumewithnohostpath:ro' ,
125
+ 'C:\\ windows\\ path:D:\\ hello\\ world:rw'
124
126
],
125
127
'BlkioDeviceReadBps' : [{'Path' : 'foo' , 'Rate' : 3 }],
126
128
'BlkioDeviceReadIOps' : [{'Path' : 'foo' , 'Rate' : 3 }],
@@ -191,7 +193,8 @@ def test_create_container_args(self):
191
193
'/mnt/vol1' ,
192
194
'/mnt/vol3' ,
193
195
'/volumewithnohostpath' ,
194
- '/anothervolumewithnohostpath'
196
+ '/anothervolumewithnohostpath' ,
197
+ 'D:\\ hello\\ world'
195
198
],
196
199
working_dir = '/code'
197
200
)
You can’t perform that action at this time.
0 commit comments