This repository was archived by the owner on Apr 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
[nxos_interfaces] resource module POC #2
Closed
Closed
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cb12d4a
nxos_interfaces resource module
trishnaguha 4c8d98e
facts generation
trishnaguha b04a7ab
fix argument_spec instantiation
trishnaguha 77c8699
change operation keyword to state
trishnaguha e1ede04
Add facts module
trishnaguha b42fbe9
cosmetic changes for APIs
trishnaguha abc4839
Add utils
trishnaguha ef011c6
execute_module API
trishnaguha 2832b3c
update ArgspecBase
trishnaguha 3819eca
ConfigBase class
trishnaguha a551055
fix regex and state_deleted
trishnaguha 9d76427
move argspec to ansible_network_os dir
trishnaguha 49241c6
standardize nomenclature
trishnaguha 2e45771
set module params as want instead of creating key-value pairs again
trishnaguha cfc870c
Address review comment
trishnaguha 2a5f6e8
remove ArgspecBase as it is not in use
trishnaguha 91fa629
use get
trishnaguha afafdcc
fix facts generation for before key in result
trishnaguha 522aa07
gather_network_resources attribute and facts update
trishnaguha 4c0357c
replace fix
trishnaguha f96e588
update with facts builder
trishnaguha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2019, Red Hat, Inc. | ||
# 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 | ||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'network'} | ||
|
||
|
||
DOCUMENTATION = """ | ||
--- | ||
module: nxos_facts | ||
extends_documentation_fragment: nxos | ||
version_added: "2.9" | ||
short_description: Gets facts about NX-OS switches | ||
description: | ||
- Collects facts from Cisco Nexus devices running the NX-OS operating | ||
system. Fact collection is supported over both Cli and Nxapi | ||
transports. This module prepends all of the base network fact keys | ||
with C(ansible_net_<fact>). The facts module will always collect a | ||
base set of facts from the device and can enable or disable | ||
collection of additional facts. | ||
author: | ||
- Trishna Guha (@trishnaguha) | ||
notes: | ||
- Tested against NXOSv 7.3.(0)D1(1) on VIRL | ||
options: | ||
gather_subset: | ||
description: | ||
- When supplied, this argument will restrict the facts collected | ||
to a given subset. Possible values for this argument include | ||
all, min, hardware, config, legacy, and interfaces. Can specify a | ||
list of values to include a larger subset.Values can also be used | ||
with an initial C(M(!)) to specify that a specific subset should | ||
not be collected. | ||
required: false | ||
default: '!config' | ||
version_added: "2.2" | ||
gather_network_resources: | ||
description: | ||
10000 - When supplied, this argument will restrict the facts collected | ||
to a given subset. Possible values for this argument include | ||
all and the resources like interfaces, vlans etc. | ||
Can specify a list of values to include a larger subset. Values | ||
can also be used with an initial C(M(!)) to specify that a | ||
specific subset should not be collected. | ||
required: false | ||
version_added: "2.9" | ||
""" | ||
|
||
EXAMPLES = """ | ||
# Gather all facts | ||
- nxos_facts: | ||
gather_subset: all | ||
gather_network_resources: all | ||
|
||
# Collect only the interfaces facts | ||
- nxos_facts: | ||
gather_subset: | ||
- !all | ||
- !min | ||
gather_network_resources: | ||
- interfaces | ||
|
||
# Do not collect interfaces facts | ||
- nxos_facts: | ||
gather_network_resources: | ||
- "!interfaces" | ||
|
||
# Collect interfaces and default facts | ||
- nxos_facts: | ||
gather_subset: min | ||
gather_network_resources: interfaces | ||
""" | ||
|
||
RETURN = """ | ||
ansible_net_gather_subset: | ||
description: The list of fact subsets collected from the device | ||
returned: always | ||
type: list | ||
ansible_gather_network_resources: | ||
description: The list of fact resource subsets collected from the device | ||
returned: always | ||
type: list | ||
""" | ||
|
||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.connection import Connection | ||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec | ||
from ansible.module_utils.nxos.facts.facts import Facts | ||
|
||
|
||
def main(): | ||
argument_spec = Facts.argument_spec | ||
argument_spec.update(nxos_argument_spec) | ||
module = AnsibleModule(argument_spec=argument_spec, | ||
supports_check_mode=True) | ||
warnings = ['default value for `gather_subset` will be changed to `min` from `!config` v2.11 onwards'] | ||
|
||
connection = Connection(module._socket_path) | ||
gather_subset = module.params['gather_subset'] | ||
gather_network_resources = module.params['gather_network_resources'] | ||
result = Facts().get_facts(module, connection, gather_subset, gather_network_resources) | ||
|
||
ansible_facts, additional_warnings = result | ||
warnings.extend(additional_warnings) | ||
|
||
module.exit_json(ansible_facts=ansible_facts, warnings=warnings) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
# (c) 2018, Red Hat, Inc. | ||
# 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 | ||
|
||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'network'} | ||
|
||
|
||
DOCUMENTATION = """ | ||
--- | ||
module: interfaces | ||
version_added: "2.8" | ||
short_description: Manages physical attributes of interfaces on Cisco NX-OS devices. | ||
description: | ||
- Manages physical attributes of interfaces of NX-OS switches. | ||
author: | ||
- Trishna Guha (@trishnaguha) | ||
options: {} | ||
""" | ||
|
||
EXAMPLES = """ | ||
- name: Configure interfaces | ||
nxos_interfaces: | ||
config: | ||
- name: Ethernet1/1 | ||
description: 'Configured by Ansible' | ||
enable: True | ||
- name: Ethernet1/2 | ||
description: 'Configured by Ansible' | ||
enable: False | ||
operation: merge | ||
|
||
""" | ||
|
||
RETURN = """ | ||
""" | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils.network.nxos.nxos import nxos_argument_spec | ||
from ansible.module_utils.nxos.config.interfaces.interfaces import Interfaces | ||
|
||
|
||
def main(): | ||
""" main entry point for module execution | ||
""" | ||
argument_spec = Interfaces.argument_spec | ||
argument_spec.update(nxos_argument_spec) | ||
module = AnsibleModule(argument_spec=argument_spec, | ||
supports_check_mode=True) | ||
|
||
result = Interfaces(module).execute_module() | ||
module.exit_json(**result) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | 9E12Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
class FactsArgs(object): | ||
|
||
def __init__(self, **kwargs): | ||
pass | ||
|
||
choices = [ | ||
'all', | ||
'interfaces', | ||
] | ||
|
||
argument_spec = { | ||
'gather_subset': dict(default=['!config'], type='list'), | ||
'gather_network_resources': dict(default=['all'], choices=choices, type='list'), | ||
} |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class InterfaceArgs(object): | ||
|
||
def __init__(self, **kwargs): | ||
pass | ||
|
||
config_spec = { | ||
'name': dict(type='str', required=True), | ||
'description': dict(), | ||
'enable': dict(default=True, type=bool), | ||
'speed': dict(), | ||
'mode': dict(choices=['layer2', 'layer3']), | ||
'mtu': dict(), | ||
'duplex': dict(choices=['full', 'half', 'auto']), | ||
'ip_forward': dict(choices=['enable', 'disable']), | ||
'fabric_forwarding_anycast_gateway': dict(type='bool'), | ||
} | ||
|
||
argument_spec = { | ||
'state': dict(default='merged', choices=['merged', 'replaced', 'overridden', 'deleted']), | ||
'config': dict(type='list', elements='dict', options=config_spec) | ||
} |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from ansible.module_utils.connection import Connection | ||
|
||
|
||
class ConfigBase(object): | ||
|
||
_connection = None | ||
|
||
def __init__(self, module): | ||
self._module = module | ||
self._connection = self._get_connection() | ||
|
||
def _get_connection(self): | ||
if self._connection: | ||
return self._connection | ||
self._connection = Connection(self._module._socket_path) | ||
return self._connection |
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API can be moved to the base class?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ganeshrn which base class are you referring to?