Skip to content

Commit b16e1c1

Browse files
committed
Merge branch 'feature_support_more_network_modes' into 'master'
Feature support more network modes See merge request evernym/utilities/devlab!20
2 parents 42306b3 + 2d59eae commit b16e1c1

6 files changed

Lines changed: 554 additions & 6 deletions

File tree

README.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,15 @@ The structure looks like this:
185185
{
186186
"name": "",
187187
"device_name": "",
188-
"cidr": ""
188+
"cidr": "",
189+
"gateway": "",
190+
"ip_range": "",
191+
"ipv6": false,
192+
"driver": "",
193+
"driver_opts": {
194+
"key": "value"
195+
},
196+
"scope": ""
189197
}
190198
```
191199

@@ -196,6 +204,13 @@ All Keys that are in **bold** are required
196204
| **name** | String | The name of the docker network to use |
197205
| device_name | String | When creating the network use this name as the network interface on the host |
198206
| cidr | String | The CIDR notation of the network range to use for the new docker network |
207+
| gateway | String | For use with network drivers that require or use the --gateway argument |
208+
| ip_range | String | For use with network drivers that require or use the --ip-range argument |
209+
| ipv6 | Boolean | Whether to enable ipv6 for the network. Default is `false` |
210+
| driver | String | Specify which driver to use when creating the docker network. Default is `bridge` |
211+
| driver_opts | Hash | Key value pairs to pass with --opt to the docker network cread command |
212+
| scope | String | For use with network drivers that require or use the --scope argument |
213+
| subnet | String | Alias for `cidr` above |
199214

200215
***[NOTE]*** All of the above keys are required unless you have pre-created the network.
201216

devlab_bench/helpers/docker.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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))

examples/aws_sam_ddb/DevlabConfig.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ network:
66
cidr: 172.30.255.48/28
77
domain: dev.lab
88
project_filter: lab.dev.aws.sam.example.type=devlab
9-
wizard_enabled: false
9+
wizard_enabled: true
1010
components:
1111
dynamodb:
1212
image: 'amazon/dynamodb-local:latest'

examples/aws_sam_ddb/wizard

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
if ! which sam 2>&1 ; then
4+
echo "ERROR: This project expects aws SAM to be installed somewhere on your local system for the foreground component"
5+
echo "See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html for some instructions"
6+
echo "Aborting!"
7+
exit 1
8+
fi
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
paths:
2+
component_persistence: persistent_data
3+
component_persistence_wizard_paths:
4+
- wizard.yaml
5+
network:
6+
name: pi-hole
7+
project_filter: pihole.type=devlab
8+
wizard_enabled: true
9+
components:
10+
pihole:
11+
image: 'pihole/pihole:latest'
12+
enabled: true
13+
run_opts:
14+
- "--dns=127.0.0.1"
15+
- "--dns=192.168.251.101"
16+
- "--restart=unless-stopped"
17+
- "--hostname=pi.hole"
18+
- "-e"
19+
- "TZ=America/Denver"
20+
- "-e"
21+
- "VIRTUAL_HOST=pi.hole"
22+
- "-e"
23+
- "PROXY_LOCATION=pi.hole"
24+
- "-e"
25+
- "FTLCONF_LOCAL_IPV4=TBD" # This will be filled in by the wizard
26+
mounts:
27+
- ':/devlab'
28+
- 'persistent_data/pihole/etc-pihole:/etc/pihole'
29+
- 'persistent_data/pihole/etc-dnsmasq.d:/etc/dnsmasq.d'
30+
ordinal:
31+
group: 0
32+
number: 1
33+
reset_paths:
34+
- etc-pihole/
35+
- etc-dnsmasq.d

0 commit comments

Comments
 (0)