8000 [nxos_interfaces] resource module POC by trishnaguha · Pull Request #2 · ansible/network · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Apr 20, 2021. It is now read-only.

[nxos_interfaces] resource module POC #2

Closed
wants to merge 21 commits into from

Conversation

trishnaguha
Copy link
Member

Signed-off-by: Trishna Guha trishnaguha17@gmail.com

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha changed the title [WIP]nxos_interfaces resource module [WIP]nxos_interfaces resource module POC Mar 11, 2019
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch 3 times, most recently from e8925c4 to eb3560d Compare March 13, 2019 04:48
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from eb3560d to 4c8d98e Compare March 13, 2019 06:41
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from 67666aa to b04a7ab Compare March 14, 2019 10:45
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch 2 times, most recently from 267fc31 to b041981 Compare March 18, 2019 15:04
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch 4 times, most recently from 77b51c5 to 6487949 Compare March 19, 2019 06:07
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from 6487949 to b42fbe9 Compare March 19, 2019 06:12
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from d475218 to ef011c6 Compare March 19, 2019 12:27
from ansible.module_utils.six import iteritems


class ArgspecBase(object):
Copy link
8000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are planning to provide direct attribute access to dict values, you should implement __delattr__ as well.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How will other module arguments be implemented? required_if, required_together, etc

Copy link
Member Author
@trishnaguha trishnaguha Mar 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@privateip Thanks for the review. So Base class code is actually not in use anymore, it's the old code. I have updated the Base class to be empty now. This is actually going to be achieved by the code generator.

Other module arguments such as required_if would be used the following way:

diff --git a/library/nxos_interfaces.py b/library/nxos_interfaces.py
index a636aa6..e902e50 100644
--- a/library/nxos_interfaces.py
+++ b/library/nxos_interfaces.py
@@ -50,6 +50,7 @@ def main():
     """ main entry point for module execution
     """
     module = AnsibleModule(argument_spec=Interface.argument_spec,
+                           required_if=Interface.required_if,
                            supports_check_mode=True)
 
     result = Interface(module).execute_module()
diff --git a/module_utils/argspec/nxos/interfaces/interfaces.py b/module_utils/argspec/nxos/interfaces/interfaces.py
index a97550e..62cefd6 100644
--- a/module_utils/argspec/nxos/interfaces/interfaces.py
+++ b/module_utils/argspec/nxos/interfaces/interfaces.py
@@ -19,3 +19,5 @@ class InterfaceArgs(ArgspecBase):
         'state': dict(default='merged', choices=['merged', 'replaced', 'overriden', 'deleted']),
         'config': dict(type='list', elements='dict', options=config_spec)
     }
+
+    required_if = [('state', 'merged', ('mode',))]

if key in self.argument_spec:
setattr(self, key, value)

def __getattr__(self, key):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method should raise an AttributeError if the request key is not in the dict. Also, in otder to avoid recursive lookups, the key should be checked against __dict__ not self.values.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attributes that begin with _ should only be checked against the internal structure not the instance variable, imho

argument_spec = {}

def __init__(self, **kwargs):
self.values = {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from dc03bf8 to 2e45771 Compare March 22, 2019 07:27
class FactsArgs(ArgspecBase):

argument_spec = {
'gather_subset': dict(default=['all'], type='list')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add individual supported keys, so that it is clear to the user which all option values it can support?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed.

self._module = module
self._connection = self._get_connection()

def _get_connection(self):
Copy link
Member

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?

Copy link
Member Author
@trishnaguha trishnaguha Mar 26, 2019

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?

class Facts(FactsArgs, FactsBase):

VALID_SUBSETS = [
'net_configuration_interfaces',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add this value in the argspec for class FactsArgs(ArgspecBase)

 'gather_subset': dict(default=['all'], choices=['net_configuration_interfaces', 'all'], type='list')

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@@ -0,0 +1,4 @@
class ArgspecBase(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this class?

Copy link
Member Author
@trishnaguha trishnaguha Mar 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is empty as of now. When we merge this POC with code generator that will generate the argspec, we can decide then?

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
:rtype: A text string
:returns: A text string if match is found
"""
match = re.search(r'%s (.+)(\n|$)' % arg, cfg, re.M)
Copy link
@NilashishC NilashishC Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a base class for Facts, can we make this more generic by making this accept the pattern instead of hardcoding it? For e.g., something like this which is being utilized here.

Copy link
Member Author
@trishnaguha trishnaguha Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NilashishC this is base class only for NXOS facts. This method is not a generic method for all kind of regex matches, rather for strings that start with the key we are looking for the value right after it.
For example,
description Configured by Ansible
feature nxapi
hostname test

The example you shared has the exact same regex pattern for all the keys, so the regex pattern can act as a generic pattern in the method definition for all those keys IMO.
Maybe we need a better method name?

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from 4af98a0 to afafdcc Compare April 8, 2019 08:45
@pabelanger
Copy link
Contributor

recheck

@ansible-zuul
Copy link
Contributor
ansible-zuul bot commented Apr 25, 2019

Build failed.

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@ansible-zuul
Copy link
Contributor
ansible-zuul bot commented Apr 30, 2019

Build failed.

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@ansible-zuul
Copy link
Contributor
ansible-zuul bot commented May 2, 2019

Build failed.

@ansible-zuul
Copy link
Contributor
ansible-zuul bot commented May 20, 2019

Build failed.

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
@trishnaguha trishnaguha force-pushed the interfaces_module_poc branch from b810dfa to f96e588 Compare May 23, 2019 10:24
@ansible-zuul
Copy link
Contributor
ansible-zuul bot commented May 23, 2019

Build failed.

@trishnaguha trishnaguha changed the title [WIP]nxos_interfaces resource module POC nxos_interfaces resource module POC May 30, 2019
@ikhan2010 ikhan2010 changed the title nxos_interfaces resource module POC [nxos_interfaces] resource module POC Jul 15, 2019
@trishnaguha
Copy link
Member Author

Closed by PR ansible/ansible#60421

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0