Adding a pair of proxy and execution modules for managing Arista switches via the pyeapi#48356
Conversation
salt/modules/arista_pyeapi.py
Outdated
There was a problem hiding this comment.
We have nearly identical code over in netmiko_mod. Refactor for DRY?
There was a problem hiding this comment.
Apologies for late reply @cachedout. Yes, there's a little overlap between them. We could have the following function in the utils:
def prepare_kwargs(all_kwargs, class_init_kwargs):
for karg, warg in six.iteritems(all_kwargs):
if karg not in class_init_kwargs:
if warg is not None:
fun_kwargs[karg] = warg
continue
if warg is not None:
init_args[karg] = warg
return init_args, fun_kwargsThen the code in this execution module would become:
def _prepare_connection(**kwargs):
'''
Prepare the connection with the remote network device, and clean up the key
value pairs, removing the args used for the connection init.
'''
init_args = {}
fun_kwargs = {}
pyeapi_kwargs = __salt__['config.get']('pyeapi', {})
pyeapi_kwargs.update(kwargs) # merge the CLI args with the opts/pillar
init_args, fun_kwargs = salt.utils.args.prepare_kwargs(pyeapi_kwargs, PYEAPI_INIT_KWARGS)
if 'transport' not in init_args:
init_args['transport'] = 'https'
conn = pyeapi.client.connect(**init_args)
node = pyeapi.client.Node(conn, enablepwd=init_args.get('enablepwd'))
return node, fun_kwargsI'm not disagreeing, just that I'm not sure if it's really worth it, particularly as it's harder to port a module in an older Salt version due to the utils dependency.
On the other hand, I have a couple of more modules pending in the queued to be submitted, that would have the same code as well.
What do you think would be the best? Thanks!
There was a problem hiding this comment.
If you use __utils__['args.prepare_kwargs'] they should just have to drop the newer args module into salt://_utils/ and sync them and it should be easily portable.
There was a problem hiding this comment.
Fantastic, I will do it like that then - will refactor and push tomorrow morning. Thanks guys!
salt/modules/arista_pyeapi.py
Outdated
There was a problem hiding this comment.
Same here. Code is in the netmiko module. Refactor for DRY?
3d73ef6 to
dddef49
Compare
|
Hi @cachedout - I have pushed dddef49 to remove the redundant code. I will follow up with another PR for Netmiko to use the new CC. @gtmanfred @rallytime |
dddef49 to
8d81709
Compare
rallytime
left a comment
There was a problem hiding this comment.
I have two small changes that are needed.
salt/modules/arista_pyeapi.py
Outdated
| Minion. If you want to use the :mod:`pyeapi Proxy <salt.proxy.arista_pyeapi>`, | ||
| please follow the documentation notes for a proper setup. | ||
| ''' | ||
| from __future__ import absolute_import |
There was a problem hiding this comment.
We also need to import print_function and unicode_literals here.
salt/proxy/arista_pyeapi.py
Outdated
| username: example | ||
| password: example | ||
| ''' | ||
| from __future__ import absolute_import |
|
I'm good here now. Thanks, @mirceaulinic. If you can get the changes suggested by @rallytime in then I think we're good to go here. |
|
Okay, added 2b61f5d to solve the imports. |
|
Bump @cachedout @rallytime - apologies if I'm pushy, but I'd love to have this in so I can follow up with the next PR which depends on this (of course, if you are happy with the code), so I can finish before the 6th of Aug. Thanks! |
|
@mirceaulinic It's merged now. I was off yesterday so I hadn't see then notification yet. :) Thanks for working on all of this for the feature release! We appreciate it, as always. :) One thing - I know you've been adding a bunch of new modules - can you make sure you get those listed in the |
|
Yes, thanks for reminder @rallytime. I will surely add them to the release notes too! |
What does this PR do?
Adds the initial version of two new modules: one Proxy and one Execution module for managing Arista switches via pyeapi which is the official library from Arista, using the eAPI.
The execution module is flexible enough to execute the commands to the remote device without necessarily requiring to be running inside the
pyeapiProxy Minion. I named the modulesarista_pyeapi, as I will provide a set of modules for managing Arista switches without having thepyeapiexternal dependency without necessarily having feature parity witharista_pyeapi(as that would imply rewriting a good part of thepyeapilibrary into Salt).