@@ -115,8 +115,8 @@ def _container_config(self, image, command, hostname=None, user=None,
115
115
command = shlex .split (str (command ))
116
116
if isinstance (environment , dict ):
117
117
environment = [
118
- ( six .text_type ('{0}={1}' ).format (k , v )
119
- for k , v in environment . items () )
118
+ six .text_type ('{0}={1}' ).format (k , v )
119
+ for k , v in six . iteritems ( environment )
120
120
]
121
121
122
122
if isinstance (mem_limit , six .string_types ):
@@ -911,63 +911,7 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
911
911
restart_policy = None , cap_add = None , cap_drop = None , devices = None ,
912
912
extra_hosts = None ):
913
913
914
- start_config = {}
915
-
916
- if isinstance (container , dict ):
917
- container = container .get ('Id' )
918
-
919
- if isinstance (lxc_conf , dict ):
920
- formatted = []
921
- for k , v in six .iteritems (lxc_conf ):
922
- formatted .append ({'Key' : k , 'Value' : str (v )})
923
- lxc_conf = formatted
924
-
925
- if lxc_conf :
926
- start_config ['LxcConf' ] = lxc_conf
927
-
928
- if binds :
929
- start_config ['Binds' ] = utils .convert_volume_binds (binds )
930
-
931
- if port_bindings :
932
- start_config ['PortBindings' ] = utils .convert_port_bindings (
933
- port_bindings
934
- )
935
-
936
- if publish_all_ports :
937
- start_config ['PublishAllPorts' ] = publish_all_ports
938
-
939
- if links :
940
- if isinstance (links , dict ):
941
- links = six .iteritems (links )
942
-
943
- formatted_links = [
944
- '{0}:{1}' .format (k , v ) for k , v in sorted (links )
945
- ]
946
-
947
- start_config ['Links' ] = formatted_links
948
-
949
- if extra_hosts :
950
- if isinstance (extra_hosts , dict ):
951
- extra_hosts = six .iteritems (extra_hosts )
952
-
953
- formatted_extra_hosts = [
954
- '{0}:{1}' .format (k , v ) for k , v in sorted (extra_hosts )
955
- ]
956
-
957
- start_config ['ExtraHosts' ] = formatted_extra_hosts
958
-
959
- if privileged :
960
- start_config ['Privileged' ] = privileged
961
-
962
- if utils .compare_version ('1.10' , self ._version ) >= 0 :
963
- if dns is not None :
964
- start_config ['Dns' ] = dns
965
- if volumes_from is not None :
966
- if isinstance (volumes_from , six .string_types ):
967
- volumes_from = volumes_from .split (',' )
968
- start_config ['VolumesFrom' ] = volumes_from
969
- else :
970
-
914
+ if utils .compare_version ('1.10' , self ._version ) < 0 :
971
915
if dns is not None :
972
916
raise errors .APIError (
973
917
'dns is only supported for API version >= 1.10'
@@ -976,23 +920,18 @@ def start(self, container, binds=None, port_bindings=None, lxc_conf=None,
976
920
raise errors .APIError (
977
921
'volumes_from is only supported for API version >= 1.10'
978
922
)
979
- if dns_search :
980
- start_config ['DnsSearch' ] = dns_search
981
-
982
- if network_mode :
983
- start_config ['NetworkMode' ] = network_mode
984
-
985
- if restart_policy :
986
- start_config ['RestartPolicy' ] = restart_policy
987
-
988
- if cap_add :
989
- start_config ['CapAdd' ] = cap_add
990
923
991
- if cap_drop :
992
- start_config ['CapDrop' ] = cap_drop
924
+ start_config = utils .create_host_config (
925
+ binds = binds , port_bindings = port_bindings , lxc_conf = lxc_conf ,
926
+ publish_all_ports = publish_all_ports , links = links , dns = dns ,
927
+ privileged = privileged , dns_search = dns_search , cap_add = cap_add ,
928
+ cap_drop = cap_drop , volumes_from = volumes_from , devices = devices ,
929
+ network_mode = network_mode , restart_policy = restart_policy ,
930
+ extra_hosts = extra_hosts
931
+ )
993
932
994
- if devices :
995
- start_config [ 'Devices' ] = utils . parse_devices ( devices )
933
+ if isinstance ( container , dict ) :
934
+ container = container . get ( 'Id' )
996
935
997
936
url = self ._url ("/containers/{0}/start" .format (container ))
998
937
if not start_config :
0 commit comments