Skip to content

Commit

Permalink
migrate: support aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Oláh Kristóf authored and slyon committed Jun 3, 2024
1 parent 49d1ad7 commit ebf38ec
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions netplan_cli/cli/commands/migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ def command_migrate(self):
c['dhcp6'] = True

elif config['method'] == 'static':
# Handle interface aliases
if (":" in iface):
iface = iface.split(':')[0]

c = netplan_config.setdefault('network', {}).setdefault('ethernets', {}).setdefault(iface, {})

if 'addresses' not in c:
Expand Down
7 changes: 7 additions & 0 deletions tests/cli_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ def test_static_ipv4_netmask(self):
'version': 2,
'ethernets': {'en1': {'addresses': ["1.2.3.4/8"]}}}}, out.decode())

def test_static_ipv4_alias(self):
out = self.do_test('auto en1\niface en1 inet static\naddress 1.2.3.4/8\n'
'auto en1:1\niface en1:1 inet static\naddress 1.2.3.5/8', dry_run=True)[0]
self.assertEqual(_load_yaml(out), {'network': {
'version': 2,
'ethernets': {'en1': {'addresses': ["1.2.3.4/8", "1.2.3.5/8"]}}}}, out.decode())

def test_static_ipv4_no_address(self):
out, err = self.do_test('auto en1\niface en1 inet static\nnetmask 1.2.3.4', expect_success=False)
self.assertEqual(out, b'')
Expand Down

0 comments on commit ebf38ec

Please sign in to comment.