| 1 |
|
| 2 |
|
| 3 |
. |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_vrfs |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_vrfs |
| 17 |
version_added: 1.0.0 |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
- This module does not support the deletion of mgmt VRF. |
| 22 |
Deletion of mgmt VRF can be done using the "sonic_config" resource module as shown in "playbooks/common_examples/mgmt_vrf_off.yaml". |
| 23 |
It can also be done using the SONiC CLI or by using a standalone REST API. |
| 24 |
short_description: Manage VRFs and associate VRFs to interfaces such as, Eth, LAG, VLAN, and loopback |
| 25 |
description: Manages VRF and VRF interface attributes in Enterprise SONiC Distribution by Dell Technologies. |
| 26 |
author: Abirami N (@abirami-n) |
| 27 |
options: |
| 28 |
config: |
| 29 |
description: A list of VRF configurations. |
| 30 |
type: list |
| 31 |
elements: dict |
| 32 |
suboptions: |
| 33 |
name: |
| 34 |
type: str |
| 35 |
description: The name of the VRF interface. |
| 36 |
required: true |
| 37 |
members: |
| 38 |
type: dict |
| 39 |
description: Holds a dictionary mapping of list of interfaces linked to a VRF interface. |
| 40 |
suboptions: |
| 41 |
interfaces: |
| 42 |
type: list |
| 43 |
elements: dict |
| 44 |
description: List of interface names that are linked to a specific VRF interface. |
| 45 |
suboptions: |
| 46 |
name: |
| 47 |
type: str |
| 48 |
description: The name of the physical interface. |
| 49 |
state: |
| 50 |
description: "The state of the configuration after module completion." |
| 51 |
type: str |
| 52 |
choices: |
| 53 |
- merged |
| 54 |
- replaced |
| 55 |
- overridden |
| 56 |
- deleted |
| 57 |
default: merged |
| 58 |
""" |
| 59 |
|
| 60 |
EXAMPLES = """ |
| 61 |
# Using "deleted" state |
| 62 |
# |
| 63 |
# Before state: |
| 64 |
# ------------- |
| 65 |
# |
| 66 |
# show ip vrf |
| 67 |
# VRF-NAME INTERFACES |
| 68 |
# ---------------------------------------------------------------- |
| 69 |
# Vrfcheck1 |
| 70 |
# Vrfcheck2 |
| 71 |
# Vrfcheck3 Eth1/3 |
| 72 |
# Eth1/14 |
| 73 |
# Eth1/16 |
| 74 |
# Eth1/17 |
| 75 |
# Vrfcheck4 Eth1/5 |
| 76 |
# Eth1/6 |
| 77 |
# |
| 78 |
- name: Configuring vrf deleted state |
| 79 |
dellemc.enterprise_sonic.sonic_vrfs: |
| 80 |
config: |
| 81 |
- name: Vrfcheck4 |
| 82 |
members: |
| 83 |
interfaces: |
| 84 |
- name: Eth1/6 |
| 85 |
- name: Vrfcheck3 |
| 86 |
members: |
| 87 |
interfaces: |
| 88 |
- name: Eth1/3 |
| 89 |
- name: Eth1/14 |
| 90 |
state: deleted |
| 91 |
# |
| 92 |
# After state: |
| 93 |
# ------------ |
| 94 |
# |
| 95 |
# show ip vrf |
| 96 |
# VRF-NAME INTERFACES |
| 97 |
# ---------------------------------------------------------------- |
| 98 |
# Vrfcheck1 |
| 99 |
# Vrfcheck2 |
| 100 |
# Vrfcheck3 Eth1/16 |
| 101 |
# Eth1/17 |
| 102 |
# Vrfcheck4 Eth1/5 |
| 103 |
# |
| 104 |
# |
| 105 |
# Using "merged" state |
| 106 |
# |
| 107 |
# Before state: |
| 108 |
# ------------- |
| 109 |
# |
| 110 |
# show ip vrf |
| 111 |
# VRF-NAME INTERFACES |
| 112 |
# ---------------------------------------------------------------- |
| 113 |
# Vrfcheck1 |
| 114 |
# Vrfcheck2 |
| 115 |
# Vrfcheck3 Eth1/16 |
| 116 |
# Eth1/17 |
| 117 |
# Vrfcheck4 |
| 118 |
# |
| 119 |
- name: Configuring vrf merged state |
| 120 |
dellemc.enterprise_sonic.sonic_vrfs: |
| 121 |
config: |
| 122 |
- name: Vrfcheck4 |
| 123 |
members: |
| 124 |
interfaces: |
| 125 |
- name: Eth1/5 |
| 126 |
- name: Eth1/6 |
| 127 |
- name: Vrfcheck3 |
| 128 |
members: |
| 129 |
interfaces: |
| 130 |
- name: Eth1/3 |
| 131 |
- name: Eth1/14 |
| 132 |
state: merged |
| 133 |
# |
| 134 |
# After state: |
| 135 |
# ------------ |
| 136 |
# |
| 137 |
# show ip vrf |
| 138 |
# VRF-NAME INTERFACES |
| 139 |
# ---------------------------------------------------------------- |
| 140 |
# Vrfcheck1 |
| 141 |
# Vrfcheck2 |
| 142 |
# Vrfcheck3 Eth1/3 |
| 143 |
# Eth1/14 |
| 144 |
# Eth1/16 |
| 145 |
# Eth1/17 |
| 146 |
# Vrfcheck4 Eth1/5 |
| 147 |
# Eth1/6 |
| 148 |
# |
| 149 |
# Using "overridden" state |
| 150 |
# |
| 151 |
# Before state: |
| 152 |
# ------------- |
| 153 |
# |
| 154 |
# show ip vrf |
| 155 |
# VRF-NAME INTERFACES |
| 156 |
# ---------------------------------------------------------------- |
| 157 |
# Vrfcheck1 |
| 158 |
# Vrfcheck2 |
| 159 |
# Vrfcheck3 Eth1/7 |
| 160 |
# Eth1/8 |
| 161 |
# |
| 162 |
- name: Overridden VRF configuration |
| 163 |
dellemc.enterprise_sonic.sonic_vrfs: |
| 164 |
sonic_vrfs: |
| 165 |
config: |
| 166 |
- name: Vrfcheck1 |
| 167 |
members: |
| 168 |
interfaces: |
| 169 |
- name: Eth1/3 |
| 170 |
- name: Eth1/14 |
| 171 |
- name: Vrfcheck3 |
| 172 |
members: |
| 173 |
interfaces: |
| 174 |
- name: Eth1/5 |
| 175 |
- name: Eth1/6 |
| 176 |
state: overridden |
| 177 |
# |
| 178 |
# After state: |
| 179 |
# ------------ |
| 180 |
# |
| 181 |
# show ip vrf |
| 182 |
# VRF-NAME INTERFACES |
| 183 |
# ---------------------------------------------------------------- |
| 184 |
# Vrfcheck1 Eth1/3 |
| 185 |
# Eth1/14 |
| 186 |
# Vrfcheck2 |
| 187 |
# Vrfcheck3 Eth1/5 |
| 188 |
# Eth1/6 |
| 189 |
# |
| 190 |
# Using "replaced" state |
| 191 |
# |
| 192 |
# Before state: |
| 193 |
# ------------- |
| 194 |
# |
| 195 |
# show ip vrf |
| 196 |
# VRF-NAME INTERFACES |
| 197 |
# ---------------------------------------------------------------- |
| 198 |
# Vrfcheck1 Eth1/3 |
| 199 |
# Vrfcheck2 |
| 200 |
# Vrfcheck3 Eth1/5 |
| 201 |
# Eth1/6 |
| 202 |
# |
| 203 |
- name: Replace VRF configuration |
| 204 |
dellemc.enterprise_sonic.sonic_vrfs: |
| 205 |
sonic_vrfs: |
| 206 |
config: |
| 207 |
- name: Vrfcheck1 |
| 208 |
members: |
| 209 |
interfaces: |
| 210 |
- name: Eth1/3 |
| 211 |
- name: Eth1/14 |
| 212 |
- name: Vrfcheck3 |
| 213 |
members: |
| 214 |
interfaces: |
| 215 |
- name: Eth1/5 |
| 216 |
- name: Eth1/6 |
| 217 |
state: replaced |
| 218 |
# |
| 219 |
# After state: |
| 220 |
# ------------ |
| 221 |
# |
| 222 |
# show ip vrf |
| 223 |
# VRF-NAME INTERFACES |
| 224 |
# ---------------------------------------------------------------- |
| 225 |
# Vrfcheck1 Eth1/3 |
| 226 |
# Eth1/14 |
| 227 |
# Vrfcheck2 |
| 228 |
# Vrfcheck3 Eth1/5 |
| 229 |
# Eth1/6 |
| 230 |
# |
| 231 |
""" |
| 232 |
|
| 233 |
RETURN = """ |
| 234 |
before: |
| 235 |
description: The configuration prior to the module invocation. |
| 236 |
returned: always |
| 237 |
type: list |
| 238 |
sample: > |
| 239 |
The configuration returned is always in the same format |
| 240 |
as the parameters above. |
| 241 |
after: |
| 242 |
description: The resulting configuration module invocation. |
| 243 |
returned: when changed |
| 244 |
type: list |
| 245 |
sample: > |
| 246 |
The configuration returned is always in the same format |
| 247 |
as the parameters above. |
| 248 |
commands: |
| 249 |
description: The set of commands pushed to the remote device. |
| 250 |
returned: always |
| 251 |
type: list |
| 252 |
sample: ['command 1', 'command 2', 'command 3'] |
| 253 |
""" |
| 254 |
|
| 255 |
|
| 256 |
from ansible.module_utils.basic import AnsibleModule |
| 257 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.vrfs.vrfs import VrfsArgs |
| 258 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.vrfs.vrfs import Vrfs |
| 259 |
|
| 260 |
|
| 261 |
def main(): |
| 262 |
""" |
| 263 |
Main entry point for module execution |
| 264 |
|
| 265 |
:returns: the result form module invocation |
| 266 |
""" |
| 267 |
module = AnsibleModule(argument_spec=VrfsArgs.argument_spec, |
| 268 |
supports_check_mode=True) |
| 269 |
|
| 270 |
result = Vrfs(module).execute_module() |
| 271 |
module.exit_json(**result) |
| 272 |
|
| 273 |
|
| 274 |
if __name__ == '__main__': |
| 275 |
main() |