From 25bd22491967217949cd3caae74c7f7b212055ca Mon Sep 17 00:00:00 2001 From: scicco Date: Thu, 25 Aug 2022 15:27:00 +0200 Subject: [PATCH] fix missing schema declaration for network.type (KeyError) Signed-off-by: scicco --- scompose/config/schema.py | 1 + scompose/project/instance.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/scompose/config/schema.py b/scompose/config/schema.py index 560641a..4f11462 100644 --- a/scompose/config/schema.py +++ b/scompose/config/schema.py @@ -56,6 +56,7 @@ def validate_config(filepath): "properties": { "allocate_ip": {"type": "boolean"}, "enable": {"type": "boolean"}, + "type": {"type": "string"}, # --network-args "args": string_list, }, diff --git a/scompose/project/instance.py b/scompose/project/instance.py index c2b227a..6d5c17c 100644 --- a/scompose/project/instance.py +++ b/scompose/project/instance.py @@ -171,6 +171,11 @@ def set_network(self, params): # if not specified, set the default value for the property for key in ["enable", "allocate_ip"]: self.network[key] = self.network.get(key, True) + + fakeroot = "--fakeroot" in self.start_opts or "-f" in self.start_opts + default_network_value = "fakeroot" if fakeroot else "bridge" + + self.network["type"] = self.network.get("type", default_network_value if self.network["enable"] is True else "none") def set_ports(self, params): """ @@ -240,7 +245,7 @@ def _get_network_commands(self, ip_address=None, network_type=None): # network_type is "bridge" by default when network.enable is True ports += ["--network", network_type] - if network_type is None and (not self.sudo and not fakeroot): + if network_type is None:# and (not self.sudo and not fakeroot): ports += ["--network", "none"] for pair in self.ports: @@ -609,8 +614,9 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False): # Network configuration + Ports if self.network["enable"]: # if network.enable is true a --network must be always added - # using bridge as default - network_type = self.network["type"] or "bridge" + # using bridge or fakeroot as default + fakeroot = "--fakeroot" in self.start_opts or "-f" in self.start_opts + network_type = self.network["type"] or "fakeroot" if fakeroot else "bridge" options += self._get_network_commands(ip_address, network_type) # Start options