Skip to content

Commit

Permalink
Merge branch 'feature_support_more_network_modes' into 'master'
Browse files Browse the repository at this point in the history
Feature support more network modes

See merge request evernym/utilities/devlab!20
  • Loading branch information
absltkaos committed Feb 9, 2023
2 parents 42306b3 + 2d59eae commit b16e1c1
Show file tree
Hide file tree
Showing 6 changed files with 554 additions and 6 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,15 @@ The structure looks like this:
{
"name": "",
"device_name": "",
"cidr": ""
"cidr": "",
"gateway": "",
"ip_range": "",
"ipv6": false,
"driver": "",
"driver_opts": {
"key": "value"
},
"scope": ""
}
```

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

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

Expand Down
33 changes: 29 additions & 4 deletions devlab_bench/helpers/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,44 @@ def build_image(self, name, tag, context, docker_file, apply_filter_label=True,
else:
self.log.error("Cannot find docker_file: %s", docker_file)
return (1, ['Cannot find docker_file: {}'.format(docker_file)])
def create_network(self, name, cidr=None, driver='bridge', device_name=None):
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'):
"""
Create a docker network
Args:
name: str, Name of the network to create
cidr: str, CIDR Notation for the network
cidr: str, CIDR Notation for the network (Same as subnet arg)
gateway: str, for use with network drivers that require the argument
ip_range: str, for use with network drivers that require the argument
ipv6: bool, whether to enable ipv6 for the network. Default: False
driver: str, which docker driver to use. Default: 'bridge'
driver_opts: dict, list of key=value pairs to pass with --opt to
the docker network create command.
scope: str, for use with network drivers that require the argument
subnet: str, CIDR notation for the subnet network (Same argument as cidr)
device_name: str, specify the exact name of the bridge device for
docker to create
[NOTE] Almost all of these arguments have 1:1 correlation to
arguments for: 'docker network create --help'
"""
opts = [
'network',
'create',
'--subnet',
cidr,
'--driver',
driver
]
if subnet or cidr:
cidr = subnet
opts += [ '--subnet', cidr ]
if gateway:
opts += ['--gateway', gateway]
if ip_range:
opts += ['--ip-range', ip_range]
if ipv6:
opts += ['--ipv6=true']
if scope:
opts += ['--scope', scope]
if self.labels:
for label in self.labels:
opts += [
Expand All @@ -151,6 +173,9 @@ def create_network(self, name, cidr=None, driver='bridge', device_name=None):
]
if self.filter_label:
opts.append('--label={}'.format(self.filter_label))
if driver_opts:
for dkey, dval in driver_opts.items():
opts += ['--opt', '{}={}'.format(dkey,dval)]
if device_name:
opts.append('--opt')
opts.append('com.docker.network.bridge.name={}'.format(device_name))
Expand Down
2 changes: 1 addition & 1 deletion examples/aws_sam_ddb/DevlabConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ network:
cidr: 172.30.255.48/28
domain: dev.lab
project_filter: lab.dev.aws.sam.example.type=devlab
wizard_enabled: false
wizard_enabled: true
components:
dynamodb:
image: 'amazon/dynamodb-local:latest'
Expand Down
8 changes: 8 additions & 0 deletions examples/aws_sam_ddb/wizard
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

if ! which sam 2>&1 ; then
echo "ERROR: This project expects aws SAM to be installed somewhere on your local system for the foreground component"
echo "See: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html for some instructions"
echo "Aborting!"
exit 1
fi
35 changes: 35 additions & 0 deletions examples/pihole_with_wizard/defaults/DevlabConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
paths:
component_persistence: persistent_data
component_persistence_wizard_paths:
- wizard.yaml
network:
name: pi-hole
project_filter: pihole.type=devlab
wizard_enabled: true
components:
pihole:
image: 'pihole/pihole:latest'
enabled: true
run_opts:
- "--dns=127.0.0.1"
- "--dns=192.168.251.101"
- "--restart=unless-stopped"
- "--hostname=pi.hole"
- "-e"
- "TZ=America/Denver"
- "-e"
- "VIRTUAL_HOST=pi.hole"
- "-e"
- "PROXY_LOCATION=pi.hole"
- "-e"
- "FTLCONF_LOCAL_IPV4=TBD" # This will be filled in by the wizard
mounts:
- ':/devlab'
- 'persistent_data/pihole/etc-pihole:/etc/pihole'
- 'persistent_data/pihole/etc-dnsmasq.d:/etc/dnsmasq.d'
ordinal:
group: 0
number: 1
reset_paths:
- etc-pihole/
- etc-dnsmasq.d
Loading

0 comments on commit b16e1c1

Please sign in to comment.