| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
""" |
| 8 |
The module file for sonic_bgp_as_paths |
| 9 |
""" |
| 10 |
|
| 11 |
from __future__ import absolute_import, division, print_function |
| 12 |
__metaclass__ = type |
| 13 |
|
| 14 |
DOCUMENTATION = """ |
| 15 |
--- |
| 16 |
module: sonic_bgp_as_paths |
| 17 |
version_added: 1.0.0 |
| 18 |
notes: |
| 19 |
- Tested against Enterprise SONiC Distribution by Dell Technologies. |
| 20 |
- Supports C(check_mode). |
| 21 |
short_description: Manage BGP autonomous system path (or as-path-list) and its parameters |
| 22 |
description: |
| 23 |
- This module provides configuration management of BGP bgp_as_paths for devices |
| 24 |
running Enterprise SONiC Distribution by Dell Technologies. |
| 25 |
author: Kumaraguru Narayanan (@nkumaraguru) |
| 26 |
options: |
| 27 |
config: |
| 28 |
description: A list of 'bgp_as_paths' configurations. |
| 29 |
type: list |
| 30 |
elements: dict |
| 31 |
suboptions: |
| 32 |
name: |
| 33 |
required: True |
| 34 |
type: str |
| 35 |
description: |
| 36 |
- Name of as-path-list. |
| 37 |
members: |
| 38 |
required: False |
| 39 |
type: list |
| 40 |
elements: str |
| 41 |
description: |
| 42 |
- Members of this BGP as-path; regular expression string can be provided. |
| 43 |
permit: |
| 44 |
required: False |
| 45 |
type: bool |
| 46 |
description: |
| 47 |
- Permits or denies this as-path. |
| 48 |
- Default value while adding a new as-path-list is C(False). |
| 49 |
state: |
| 50 |
description: |
| 51 |
- The state of the configuration after module completion. |
| 52 |
type: str |
| 53 |
choices: |
| 54 |
- merged |
| 55 |
- deleted |
| 56 |
- replaced |
| 57 |
- overridden |
| 58 |
default: merged |
| 59 |
""" |
| 60 |
|
| 61 |
EXAMPLES = """ |
| 62 |
# Using "deleted" state |
| 63 |
|
| 64 |
# Before state: |
| 65 |
# ------------- |
| 66 |
# |
| 67 |
# show bgp as-path-access-list |
| 68 |
# AS path list test: |
| 69 |
# action: permit |
| 70 |
# members: 808.*,909.* |
| 71 |
|
| 72 |
- name: Delete BGP as path list |
| 73 |
dellemc.enterprise_sonic.sonic_bgp_as_paths: |
| 74 |
config: |
| 75 |
- name: test |
| 76 |
members: |
| 77 |
- 909.* |
| 78 |
permit: true |
| 79 |
state: deleted |
| 80 |
|
| 81 |
# After state: |
| 82 |
# ------------ |
| 83 |
# |
| 84 |
# show bgp as-path-access-list |
| 85 |
# AS path list test: |
| 86 |
# action: permit |
| 87 |
# members: 808.* |
| 88 |
|
| 89 |
|
| 90 |
# Using "deleted" state |
| 91 |
|
| 92 |
# Before state: |
| 93 |
# ------------- |
| 94 |
# |
| 95 |
# show bgp as-path-access-list |
| 96 |
# AS path list test: |
| 97 |
# action: permit |
| 98 |
# members: 808.*,909.* |
| 99 |
# AS path list test1: |
| 100 |
# action: deny |
| 101 |
# members: 608.*,709.* |
| 102 |
|
| 103 |
- name: Deletes BGP as-path list |
| 104 |
dellemc.enterprise_sonic.sonic_bgp_as_paths: |
| 105 |
config: |
| 106 |
- name: test |
| 107 |
members: |
| 108 |
state: deleted |
| 109 |
|
| 110 |
# After state: |
| 111 |
# ------------ |
| 112 |
# |
| 113 |
# show bgp as-path-access-list |
| 114 |
# AS path list test1: |
| 115 |
# action: deny |
| 116 |
# members: 608.*,709.* |
| 117 |
|
| 118 |
|
| 119 |
# Using "deleted" state |
| 120 |
|
| 121 |
# Before state: |
| 122 |
# ------------- |
| 123 |
# |
| 124 |
# show bgp as-path-access-list |
| 125 |
# AS path list test: |
| 126 |
# action: permit |
| 127 |
# members: 808.*,909.* |
| 128 |
|
| 129 |
- name: Deletes BGP as-path list |
| 130 |
dellemc.enterprise_sonic.sonic_bgp_as_paths: |
| 131 |
config: |
| 132 |
state: deleted |
| 133 |
|
| 134 |
# After state: |
| 135 |
# ------------ |
| 136 |
# |
| 137 |
# show bgp as-path-access-list |
| 138 |
# (No bgp as-path-access-list configuration present) |
| 139 |
|
| 140 |
|
| 141 |
# Using "merged" state |
| 142 |
|
| 143 |
# Before state: |
| 144 |
# ------------- |
| 145 |
# |
| 146 |
# show bgp as-path-access-list |
| 147 |
# (No bgp as-path-access-list configuration present) |
| 148 |
|
| 149 |
- name: Create a BGP as-path list |
| 150 |
dellemc.enterprise_sonic.sonic_bgp_as_paths: |
| 151 |
config: |
| 152 |
- name: test |
| 153 |
members: |
| 154 |
- 909.* |
| 155 |
permit: true |
| 156 |
state: merged |
| 157 |
|
| 158 |
# After state: |
| 159 |
# ------------ |
| 160 |
# |
| 161 |
# show bgp as-path-access-list |
| 162 |
# AS path list test: |
| 163 |
# action: permit |
| 164 |
# members: 909.* |
| 165 |
|
| 166 |
|
| 167 |
# Using "replaced" state |
| 168 |
|
| 169 |
# Before state: |
| 170 |
# ------------- |
| 171 |
# |
| 172 |
# show bgp as-path-access-list |
| 173 |
# AS path list test: |
| 174 |
# action: permit |
| 175 |
# members: 800.*,808.* |
| 176 |
# AS path list test1: |
| 177 |
# action: deny |
| 178 |
# members: 500.* |
| 179 |
|
| 180 |
- name: Replace device configuration of specified BGP as-path lists with provided configuration |
| 181 |
dellemc.enterprise_sonic.sonic_bgp_as_paths: |
| 182 |
config: |
| 183 |
- name: test |
| 184 |
members: |
| 185 |
- 900.* |
| 186 |
- 901.* |
| 187 |
permit: true |
| 188 |
- name: test1 |
| 189 |
- name: test2 |
| 190 |
members: |
| 191 |
- 100.* |
| 192 |
permit: true |
| 193 |
state: replaced |
| 194 |
|
| 195 |
# After state: |
| 196 |
# ------------ |
| 197 |
# |
| 198 |
# show bgp as-path-access-list |
| 199 |
# AS path list test: |
| 200 |
# action: permit |
| 201 |
# members: 900.*,901.* |
| 202 |
# AS path list test2: |
| 203 |
# action: permit |
| 204 |
# members: 100.* |
| 205 |
|
| 206 |
|
| 207 |
# Using "overridden" state |
| 208 |
|
| 209 |
# Before state: |
| 210 |
# ------------- |
| 211 |
# |
| 212 |
# show bgp as-path-access-list |
| 213 |
# AS path list test: |
| 214 |
# action: permit |
| 215 |
# members: 800.*,808.* |
| 216 |
# AS path list test1: |
| 217 |
# action: deny |
| 218 |
# members: 500.* |
| 219 |
|
| 220 |
- name: Override device configuration of all BGP as-path lists with provided configuration |
| 221 |
dellemc.enterprise_sonic.sonic_bgp_as_paths: |
| 222 |
config: |
| 223 |
- name: test |
| 224 |
members: |
| 225 |
- 900.* |
| 226 |
- 901.* |
| 227 |
permit: true |
| 228 |
state: overridden |
| 229 |
|
| 230 |
# After state: |
| 231 |
# ------------ |
| 232 |
# |
| 233 |
# show bgp as-path-access-list |
| 234 |
# AS path list test: |
| 235 |
# action: permit |
| 236 |
# members: 900.*,901.* |
| 237 |
""" |
| 238 |
|
| 239 |
RETURN = """ |
| 240 |
before: |
| 241 |
description: The configuration prior to the module invocation. |
| 242 |
returned: always |
| 243 |
type: list |
| 244 |
sample: > |
| 245 |
The configuration returned is always in the same format |
| 246 |
as the parameters above. |
| 247 |
after: |
| 248 |
description: The resulting configuration module invocation. |
| 249 |
returned: when changed |
| 250 |
type: list |
| 251 |
sample: > |
| 252 |
The configuration returned is always in the same format |
| 253 |
as the parameters above. |
| 254 |
commands: |
| 255 |
description: The set of commands pushed to the remote device. |
| 256 |
returned: always |
| 257 |
type: list |
| 258 |
sample: ['command 1', 'command 2', 'command 3'] |
| 259 |
""" |
| 260 |
|
| 261 |
|
| 262 |
from ansible.module_utils.basic import AnsibleModule |
| 263 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.bgp_as_paths.bgp_as_paths import Bgp_as_pathsArgs |
| 264 |
from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bgp_as_paths.bgp_as_paths import Bgp_as_paths |
| 265 |
|
| 266 |
|
| 267 |
def main(): |
| 268 |
""" |
| 269 |
Main entry point for module execution |
| 270 |
|
| 271 |
:returns: the result form module invocation |
| 272 |
""" |
| 273 |
module = AnsibleModule(argument_spec=Bgp_as_pathsArgs.argument_spec, |
| 274 |
supports_check_mode=True) |
| 275 |
|
| 276 |
result = Bgp_as_paths(module).execute_module() |
| 277 |
module.exit_json(**result) |
| 278 |
|
| 279 |
|
| 280 |
if __name__ == '__main__': |
| 281 |
main() |