Skip to content

Commit

Permalink
Adding bgp_address_family
Browse files Browse the repository at this point in the history
Signed-off-by: GomathiselviS <gomathiselvi@gmail.com>
  • Loading branch information
GomathiselviS committed Feb 24, 2021
1 parent df81f31 commit 6284f6d
Show file tree
Hide file tree
Showing 8 changed files with 847 additions and 0 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# -*- coding: utf-8 -*-
# Copyright 2021 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

#############################################
# WARNING #
#############################################
#
# This file is auto generated by the resource
# module builder playbook.
#
# Do not edit this file manually.
#
# Changes to this file will be over written
# by the resource module builder.
#
# Changes should be made in the model used to
# generate this file or in the resource module
# builder template.
#
#############################################

"""
The arg spec for the vyos_bgp_address_family module
"""


class Bgp_address_familyArgs(object): # pylint: disable=R0903
"""The arg spec for the vyos_bgp_address_family module
"""

def __init__(self, **kwargs):
pass

argument_spec = {
"running_config": {},
"state": {
"default": "merged",
"type": "str",
"choices": [
"merged",
"replaced",
"deleted",
"gathered",
"parsed",
"rendered",
"purged",
"overridden",
],
},
"config": {
"type": "dict",
"options": {
"neighbors": {
"type": "dict",
"options": {
"address_family": {
"elements": "dict",
"type": "list",
"options": {
"nexthop_local": {"type": "bool"},
"soft_reconfiguration": {"type": "bool"},
"unsupress_map": {"type": "str"},
"nexthop_self": {"type": "bool"},
"weight": {"type": "int"},
"prefix_list": {
"elements": "dict",
"type": "list",
"options": {
"action": {
"type": "str",
"choices": ["export", "import"],
},
"prefix_list": {"type": "str"},
},
},
"default_originiate": {"type": "str"},
"distribute_list": {
"elements": "dict",
"type": "list",
"options": {
"action": {
"type": "str",
"choices": ["export", "import"],
},
"acl": {"type": "int"},
},
},
"allowas_in": {"type": "int"},
"filter_list": {
"elements": "dict",
"type": "list",
"options": {
"action": {
"type": "str",
"choices": ["export", "import"],
},
"path_list": {"type": "str"},
},
},
"route_server_client": {"type": "bool"},
"attribute_unchanged": {
"type": "str",
"choices": ["as_path", "med", "next_hop"],
},
"peer_group": {"type": "str"},
"maximum_prefix": {"type": "int"},
"route_reflector_client": {"type": "bool"},
"route_map": {
"elements": "dict",
"type": "list",
"options": {
"action": {
"type": "str",
"choices": ["export", "import"],
},
"route_map": {"type": "str"},
},
},
"capability": {
"type": "dict",
"options": {
"orf": {
"type": "str",
"choices": ["send", "receive"],
},
"dynamic": {"type": "bool"},
},
},
"remove_private_as": {"type": "bool"},
"as_override": {"type": "bool"},
"afi": {
"type": "str",
"choices": ["ipv4", "ipv6"],
},
},
},
"neighbor_address": {"type": "str"},
},
},
"as_number": {"type": "int"},
"address_family": {
"elements": "dict",
"type": "list",
"options": {
"afi": {"type": "str", "choices": ["ipv4", "ipv6"]},
"redistribute": {
"elements": "dict",
"type": "list",
"options": {
"table": {"type": "str"},
"metric": {"type": "int"},
"protocol": {
"type": "str",
"choices": [
"connected",
"kernel",
"ospf",
"ospfv3",
"rip",
"ripng",
"static",
],
},
"route_map": {"type": "str"},
},
},
"networks": {
"elements": "dict",
"type": "list",
"options": {
"backdoor": {"type": "bool"},
"prefix": {"type": "str"},
"path_limit": {"type": "int"},
"route_map": {"type": "str"},
},
},
"aggregate_address": {
"elements": "dict",
"type": "list",
"options": {
"summary_only": {"type": "bool"},
"prefix": {"type": "str"},
"as_set": {"type": "bool"},
},
},
},
},
},
},
} # pylint: disable=C0301
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#
# -*- coding: utf-8 -*-
# Copyright 2021 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
#

from __future__ import absolute_import, division, print_function
__metaclass__ = type

"""
The vyos_bgp_address_family config file.
It is in this file where the current configuration (as dict)
is compared to the provided configuration (as dict) and the command set
necessary to bring the current configuration to its desired end-state is
created.
"""

from copy import deepcopy

from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import (
dict_merge,
)
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.resource_module import (
ResourceModule,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.facts.facts import (
Facts,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import (
Bgp_address_familyTemplate,
)


class Bgp_address_family(ResourceModule):
"""
The vyos_bgp_address_family config class
"""

def __init__(self, module):
super(Bgp_address_family, self).__init__(
empty_fact_val={},
facts_module=Facts(module),
module=module,
resource="bgp_address_family",
tmplt=Bgp_address_familyTemplate(),
)
self.parsers = [
]

def execute_module(self):
""" Execute the module
:rtype: A dictionary
:returns: The result from module execution
"""
if self.state not in ["parsed", "gathered"]:
self.generate_commands()
self.run_commands()
return self.result

def generate_commands(self):
""" Generate configuration commands to send based on
want, have and desired state.
"""
wantd = {}
haved = {}

# if state is merged, merge want onto have and then compare
if self.state == "merged":
wantd = dict_merge(haved, wantd)

# if state is deleted, empty out wantd and set haved to wantd
if self.state == "deleted":
haved = {
k: v for k, v in iteritems(haved) if k in wantd or not wantd
}
wantd = {}

# remove superfluous config for overridden and deleted
if self.state in ["overridden", "deleted"]:
for k, have in iteritems(haved):
if k not in wantd:
self._compare(want={}, have=have)

for k, want in iteritems(wantd):
self._compare(want=want, have=haved.pop(k, {}))

def _compare(self, want, have):
"""Leverages the base class `compare()` method and
populates the list of commands to be run by comparing
the `want` and `have` data with the `parsers` defined
for the Bgp_address_family network resource.
"""
self.compare(parsers=self.parsers, want=want, have=have)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# Copyright 2021 Red Hat
# GNU General Public License v3.0+
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type

"""
The vyos bgp_address_family fact class
It is in this file the configuration is collected from the device
for a given resource, parsed, and the facts tree is populated
based on the configuration.
"""

from copy import deepcopy

from ansible.module_utils.six import iteritems
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common import (
utils,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.rm_templates.bgp_address_family import (
Bgp_address_familyTemplate,
)
from ansible_collections.vyos.vyos.plugins.module_utils.network.vyos.argspec.bgp_address_family.bgp_address_family import (
Bgp_address_familyArgs,
)

class Bgp_address_familyFacts(object):
""" The vyos bgp_address_family facts class
"""

def __init__(self, module, subspec='config', options='options'):
self._module = module
self.argument_spec = Bgp_address_familyArgs.argument_spec
spec = deepcopy(self.argument_spec)
if subspec:
if options:
facts_argument_spec = spec[subspec][options]
else:
facts_argument_spec = spec[subspec]
else:
facts_argument_spec = spec

self.generated_spec = utils.generate_dict(facts_argument_spec)

def populate_facts(self, connection, ansible_facts, data=None):
""" Populate the facts for Bgp_address_family network resource
:param connection: the device connection
:param ansible_facts: Facts dictionary
:param data: previously collected conf
:rtype: dictionary
:returns: facts
"""
facts = {}
objs = []

if not data:
data = connection.get()

# parse native config using the Bgp_address_family template
bgp_address_family_parser = Bgp_address_familyTemplate(lines=data.splitlines())
objs = bgp_address_family_parser.parse()

ansible_facts['ansible_network_resources'].pop('bgp_address_family', None)

params = utils.remove_empties(
utils.validate_config(self.argument_spec, {"config": objs})
)

facts['bgp_address_family'] = params['config']
ansible_facts['ansible_network_resources'].update(facts)

return ansible_facts
Loading

0 comments on commit 6284f6d

Please sign in to comment.