From 83253cd8f0c56a8d596f3d7a3411dd80f6948a70 Mon Sep 17 00:00:00 2001 From: Ricardo Carrillo Cruz Date: Thu, 6 Jul 2017 21:02:25 +0200 Subject: [PATCH] Add net_l3_interface vendor neutral module (#26484) * Add net_l3_interface vendor neutral module * Fix pep8 issue --- .../network/layer3/net_l3_interface.py | 78 +++++++++++++++++++ .../plugins/action/net_l3_interface.py | 27 +++++++ 2 files changed, 105 insertions(+) create mode 100644 lib/ansible/modules/network/layer3/net_l3_interface.py create mode 100644 lib/ansible/plugins/action/net_l3_interface.py diff --git a/lib/ansible/modules/network/layer3/net_l3_interface.py b/lib/ansible/modules/network/layer3/net_l3_interface.py new file mode 100644 index 0000000000..b6360d354a --- /dev/null +++ b/lib/ansible/modules/network/layer3/net_l3_interface.py @@ -0,0 +1,78 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +# (c) 2017, Ansible by Red Hat, inc +# +# This file is part of Ansible by Red Hat +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +# + +ANSIBLE_METADATA = {'metadata_version': '1.0', + 'status': ['preview'], + 'supported_by': 'core'} + + +DOCUMENTATION = """ +--- +module: net_l3_interface +version_added: "2.4" +author: "Ricardo Carrillo Cruz (@rcarrillocruz)" +short_description: Manage L3 interfaces on network devices +description: + - This module provides declarative management of L3 interfaces + on network devices. +options: + name: + description: + - Name of the L3 interface. + ipv4: + description: + - IPv4 of the L3 interface. + ipv6: + description: + - IPv6 of the L3 interface. + collection: + description: List of L3 interfaces definitions + purge: + description: + - Purge L3 interfaces not defined in the collections parameter. + default: no + state: + description: + - State of the L3 interface configuration. + default: present + choices: ['present', 'absent'] +""" + +EXAMPLES = """ +- name: Set eth0 IPv4 address + net_l3_interface: + name: eth0 + ipv4: 192.168.0.1/24 + +- name: Remove eth0 IPv4 address + net_l3_interface: + name: eth0 + state: absent +""" + +RETURN = """ +commands: + description: The list of configuration mode commands to send to the device + returned: always, except for the platforms that use Netconf transport to manage the device. + type: list + sample: + - set interfaces ethernet eth0 address '192.168.0.1/24' +""" diff --git a/lib/ansible/plugins/action/net_l3_interface.py b/lib/ansible/plugins/action/net_l3_interface.py new file mode 100644 index 0000000000..cad73f8a26 --- /dev/null +++ b/lib/ansible/plugins/action/net_l3_interface.py @@ -0,0 +1,27 @@ +# (c) 2017, Ansible Inc, +# +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +from ansible.plugins.action.net_base import ActionModule as _ActionModule + + +class ActionModule(_ActionModule): + def run(self, tmp=None, task_vars=None): + result = super(ActionModule, self).run(tmp, task_vars) + + return result