mirror of
https://github.com/containers/podman-compose.git
synced 2025-04-30 12:24:36 +02:00
Support network level mac_address attribute
Signed-off-by: Songmin Li <lisongmin@protonmail.com>
This commit is contained in:
parent
75d7be2b7b
commit
ac7ec5c166
@ -38,6 +38,12 @@ Podman-compose in addition supports the specification of MAC addresses on a per-
|
|||||||
is done by adding a `x-podman.mac_address` key to the network configuration in the container. The
|
is done by adding a `x-podman.mac_address` key to the network configuration in the container. The
|
||||||
value of the `x-podman.mac_address` key is the MAC address to be used for the network interface.
|
value of the `x-podman.mac_address` key is the MAC address to be used for the network interface.
|
||||||
|
|
||||||
|
Note that the [compose spec](https://github.com/compose-spec/compose-spec/blob/main/05-services.md#mac_address)
|
||||||
|
now supports `mac_address` on the network level, so we recommend using
|
||||||
|
the standard `mac_address` key for setting the MAC address. The
|
||||||
|
`x-podman.mac_address` is still supported for backwards compatibility.
|
||||||
|
|
||||||
|
|
||||||
Specifying a MAC address for the container and for individual networks at the same time is not
|
Specifying a MAC address for the container and for individual networks at the same time is not
|
||||||
supported.
|
supported.
|
||||||
|
|
||||||
@ -69,7 +75,7 @@ services:
|
|||||||
x-podman.mac_address: "02:aa:aa:aa:aa:aa"
|
x-podman.mac_address: "02:aa:aa:aa:aa:aa"
|
||||||
net1:
|
net1:
|
||||||
ipv4_address: "192.168.1.10"
|
ipv4_address: "192.168.1.10"
|
||||||
x-podman.mac_address: "02:bb:bb:bb:bb:bb"
|
mac_address: "02:bb:bb:bb:bb:bb" # mac_address is supported
|
||||||
```
|
```
|
||||||
|
|
||||||
## Podman-specific network modes
|
## Podman-specific network modes
|
||||||
|
1
newsfragments/network_level_mac_address.feature
Normal file
1
newsfragments/network_level_mac_address.feature
Normal file
@ -0,0 +1 @@
|
|||||||
|
Support network level mac_address attribute.
|
@ -966,7 +966,7 @@ def get_net_args_from_networks(compose, cnt):
|
|||||||
# specified on the network level as well
|
# specified on the network level as well
|
||||||
if mac_address is not None:
|
if mac_address is not None:
|
||||||
for net_config in multiple_nets.values():
|
for net_config in multiple_nets.values():
|
||||||
network_mac = net_config.get("x-podman.mac_address")
|
network_mac = net_config.get("mac_address", net_config.get("x-podman.mac_address"))
|
||||||
if network_mac is not None:
|
if network_mac is not None:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
f"conflicting mac addresses {mac_address} and {network_mac}:"
|
f"conflicting mac addresses {mac_address} and {network_mac}:"
|
||||||
@ -983,8 +983,10 @@ def get_net_args_from_networks(compose, cnt):
|
|||||||
|
|
||||||
ipv4 = net_config_.get("ipv4_address")
|
ipv4 = net_config_.get("ipv4_address")
|
||||||
ipv6 = net_config_.get("ipv6_address")
|
ipv6 = net_config_.get("ipv6_address")
|
||||||
# custom extension; not supported by docker-compose v3
|
# Note: mac_address is supported by compose spec now, and x-podman.mac_address
|
||||||
mac = net_config_.get("x-podman.mac_address")
|
# is only for backward compatibility
|
||||||
|
# https://github.com/compose-spec/compose-spec/blob/main/05-services.md#mac_address
|
||||||
|
mac = net_config_.get("mac_address", net_config_.get("x-podman.mac_address"))
|
||||||
aliases_on_net = norm_as_list(net_config_.get("aliases", []))
|
aliases_on_net = norm_as_list(net_config_.get("aliases", []))
|
||||||
|
|
||||||
# if a mac_address was specified on the container level, apply it to the first network
|
# if a mac_address was specified on the container level, apply it to the first network
|
||||||
|
@ -23,7 +23,7 @@ services:
|
|||||||
x-podman.mac_address: "02:01:01:00:01:01"
|
x-podman.mac_address: "02:01:01:00:01:01"
|
||||||
internal-network:
|
internal-network:
|
||||||
ipv4_address: "172.19.2.10"
|
ipv4_address: "172.19.2.10"
|
||||||
x-podman.mac_address: "02:01:01:00:02:01"
|
mac_address: "02:01:01:00:02:01"
|
||||||
volumes:
|
volumes:
|
||||||
- ./test1.txt:/var/www/html/index.txt:ro,z
|
- ./test1.txt:/var/www/html/index.txt:ro,z
|
||||||
web2:
|
web2:
|
||||||
|
@ -149,11 +149,15 @@ class TestGetNetArgs(unittest.TestCase):
|
|||||||
args = get_net_args(compose, container)
|
args = get_net_args(compose, container)
|
||||||
self.assertListEqual(expected_args, args)
|
self.assertListEqual(expected_args, args)
|
||||||
|
|
||||||
def test_mac_on_network(self):
|
@parameterized.expand([
|
||||||
|
"mac_address",
|
||||||
|
"x-podman.mac_address",
|
||||||
|
])
|
||||||
|
def test_mac_on_network(self, mac_attr):
|
||||||
mac = "00:11:22:33:44:55"
|
mac = "00:11:22:33:44:55"
|
||||||
compose = get_networked_compose()
|
compose = get_networked_compose()
|
||||||
container = get_minimal_container()
|
container = get_minimal_container()
|
||||||
container["networks"] = {"net0": {"x-podman.mac_address": mac}}
|
container["networks"] = {"net0": {mac_attr: mac}}
|
||||||
|
|
||||||
expected_args = [
|
expected_args = [
|
||||||
f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}",
|
f"--network={PROJECT_NAME}_net0:mac={mac},alias={SERVICE_NAME}",
|
||||||
|
Loading…
Reference in New Issue
Block a user