@@ -127,22 +127,44 @@ def build_image(self, name, tag, context, docker_file, apply_filter_label=True,
127127 else :
128128 self .log .error ("Cannot find docker_file: %s" , docker_file )
129129 return (1 , ['Cannot find docker_file: {}' .format (docker_file )])
130- def create_network (self , name , cidr = None , driver = 'bridge' , device_name = None ):
130+ def create_network (self , name , cidr = None , gateway = None , ip_range = None , ipv6 = False , driver_opts = None , scope = None , subnet = None , device_name = None , driver = 'bridge' ):
131131 """
132132 Create a docker network
133133
134134 Args:
135135 name: str, Name of the network to create
136- cidr: str, CIDR Notation for the network
136+ cidr: str, CIDR Notation for the network (Same as subnet arg)
137+ gateway: str, for use with network drivers that require the argument
138+ ip_range: str, for use with network drivers that require the argument
139+ ipv6: bool, whether to enable ipv6 for the network. Default: False
140+ driver: str, which docker driver to use. Default: 'bridge'
141+ driver_opts: dict, list of key=value pairs to pass with --opt to
142+ the docker network create command.
143+ scope: str, for use with network drivers that require the argument
144+ subnet: str, CIDR notation for the subnet network (Same argument as cidr)
145+ device_name: str, specify the exact name of the bridge device for
146+ docker to create
147+
148+ [NOTE] Almost all of these arguments have 1:1 correlation to
149+ arguments for: 'docker network create --help'
137150 """
138151 opts = [
139152 'network' ,
140153 'create' ,
141- '--subnet' ,
142- cidr ,
143154 '--driver' ,
144155 driver
145156 ]
157+ if subnet or cidr :
158+ cidr = subnet
159+ opts += [ '--subnet' , cidr ]
160+ if gateway :
161+ opts += ['--gateway' , gateway ]
162+ if ip_range :
163+ opts += ['--ip-range' , ip_range ]
164+ if ipv6 :
165+ opts += ['--ipv6=true' ]
166+ if scope :
167+ opts += ['--scope' , scope ]
146168 if self .labels :
147169 for label in self .labels :
148170 opts += [
@@ -151,6 +173,9 @@ def create_network(self, name, cidr=None, driver='bridge', device_name=None):
151173 ]
152174 if self .filter_label :
153175 opts .append ('--label={}' .format (self .filter_label ))
176+ if driver_opts :
177+ for dkey , dval in driver_opts .items ():
178+ opts += ['--opt' , '{}={}' .format (dkey ,dval )]
154179 if device_name :
155180 opts .append ('--opt' )
156181 opts .append ('com.docker.network.bridge.name={}' .format (device_name ))
0 commit comments