Skip to content

Commit

Permalink
Merge pull request #10 from amarao/add_vrf
Browse files Browse the repository at this point in the history
feat: add vrf type device to ip_link_device
  • Loading branch information
amarao authored Sep 26, 2022
2 parents e9e89c7 + e37c47a commit 200f41d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ansible-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install flake8==4.0.0 pytest==6.2.4
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install kernel extra modules
run: sudo apt-get install -y linux-modules-extra-$(uname -r)
Expand Down
2 changes: 1 addition & 1 deletion ansible_collections/amarao/ip/galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace: amarao

name: ip

version: 0.1.10
version: 0.1.11

readme: README.md

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
DOCUMENTATION = """
---
module: ip_address
version_added: "2.10"
version_added: "0.0.1"
author: "George Shuklin (@amarao)"
short_description: Create or delete IP addresses on interfaces
requirements: [iproute2]
Expand Down
39 changes: 35 additions & 4 deletions ansible_collections/amarao/ip/plugins/modules/ip_link_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
DOCUMENTATION = """
---
module: ip_link_device
version_added: "2.10"
version_added: "0.0.1"
author: "George Shuklin (@amarao)"
short_description: Create or delete network interfaces in Linux
requirements: [iproute2]
Expand Down Expand Up @@ -81,7 +81,7 @@
type:
type: str
choices: [bridge, dummy, gre, gretap, veth, vlan, vxlan, bond]
choices: [bridge, dummy, gre, gretap, veth, vlan, vxlan, bond, vrf]
description:
- Type of a new interface to add or delete.
- Can be specified instead of I(name) or I(group_id)
Expand Down Expand Up @@ -1156,6 +1156,19 @@
system defaults to using the masters'
mac address as actors' system address.
- Valid only for I(mode)=C(802.3ad).
vrf_options:
type: dict
description:
- Options, specific for I(type)=C(vrf)
- Should not be used for any other type.
- VRF documentation is available at https://docs.kernel.org/networking/vrf.html
suboptions:
table:
type: str
description:
- ID of the routing table used for VRF.
notes:
- The module does not check the interface type when checking
if interface is present or not. I(type) and corresponding options are
Expand Down Expand Up @@ -1226,11 +1239,24 @@
bond_options:
mode: 802.3ad
lacp_rate: fast
- name: Add device to bond
ip_link_device_attribute: # it's a different module!
name: eth3
master: bond
- name: Create vrf
ip_link_device:
device: blue
type: vrf
state: present
vrf_options:
table: 42
- name: Enslave vxlan
ip_link_device_attribute: # it's a different module!
device: vxlan.42
master: blue
"""

RETURN = """
Expand Down Expand Up @@ -1414,6 +1440,9 @@
"ad_user_port_key": lambda val: ['ad_user_port_key', str(val)],
"ad_actor_sys_prio": lambda val: ['ad_actor_sys_prio', str(val)],
"ad_actor_system": lambda addr: ['ad_actor_system', str(addr)],
},
'vrf': {
"table": lambda table_id: ['table', str(table_id)],
}
}

Expand Down Expand Up @@ -1589,7 +1618,8 @@ def main():
'state': {'choices': ['present', 'absent'], 'required': True},
'type': {'choices': [
'veth', 'vlan', 'vxlan', 'gre',
'gretap', 'dummy', 'bridge', 'bond'
'gretap', 'dummy', 'bridge', 'bond',
'vrf'
]},
'link': {},
'txqueuelen': {'type': 'int'},
Expand All @@ -1608,6 +1638,7 @@ def main():
'gretap_options': {'type': 'dict'},
'bridge_options': {'type': 'dict'},
'bond_options': {'type': 'dict'},
'vrf_options': {'type': 'dict'},
},
supports_check_mode=True,
mutually_exclusive=[
Expand All @@ -1616,7 +1647,7 @@ def main():
[
'vlan_options', 'vxlan_options', 'gre_options',
'gretap_options', 'veth_options', 'bridge_options',
'bond_options'
'bond_options', 'vrf_options'
]
],
required_one_of=[['name', 'group_id']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
DOCUMENTATION = """
---
module: ip_link_device_attribute
version_added: "2.10"
version_added: "0.0.1"
author: "George Shuklin (@amarao)"
short_description: Set link-level properties for network interfaces for Linux
requirements: [iproute2]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,29 @@
- 'ip link del veth42'
- 'ip link del bond42'
failed_when: false


# TEST10 created vrf interface
- name: TEST10 - vrf creation
tags: [test10]
become: true
block:
- name: TEST10, create vrf
ip_link_device:
device: vrf-blue
type: vrf
state: present
vrf_options:
table: 42
- name: TEST10, get results
command: ip -d link show dev vrf-blue
register: ip_output
- name: TEST9, check results
assert:
that:
- "'vrf-blue' in ip_output.stdout"
- "'table 42' in ip_output.stdout"
always:
- name: TEST10, cleanup
command: ip link del vrf-blue
failed_when: false

0 comments on commit 200f41d

Please sign in to comment.