Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Netbox execution module #48916

Merged
merged 3 commits into from Aug 8, 2018

Conversation

Projects
None yet
4 participants
@Ichabond
Copy link
Contributor

commented Aug 3, 2018

What does this PR do?

Add multiple functions to interact with the Netbox API.

New Behavior

This PR adds more functions to the Netbox execution module. This further expands the functionality by allowing deletion and creation of Netbox objects as well.

Tests written?

No

Commits signed with GPG?

No

CC: @zachmoody @mirceaulinic

@Ichabond Ichabond force-pushed the Ichabond:develop branch from ae36222 to b7fb85b Aug 3, 2018

if id:
item = getattr(getattr(nb, app), endpoint).get(id)
else:
item = getattr(getattr(nb, app), endpoint).get(**salt.utils.args.clean_kwargs(**kwargs))

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Aug 3, 2018

Contributor

instead of using salt.utils.args.clean_kwargs, it is already injected in these modules, just use __utils__['args.clean_kwargs'](**kwargs)

This comment has been minimized.

Copy link
@Ichabond

Ichabond Aug 3, 2018

Author Contributor

I've updated this, but this breaks the unit tests:

Traceback (most recent call last):
  File "/Users/tstrickx/Library/Python/2.7/lib/python/site-packages/mock/mock.py", line 1305, in patched
    return func(*args, **keywargs)
  File "/Users/tstrickx/Documents/Projects/salt/tests/unit/modules/test_netbox.py", line 86, in test_token_present
    netbox.get_('dcim', 'devices', name='test')
  File "/Users/tstrickx/Documents/Projects/salt/salt/modules/netbox.py", line 191, in get_
    return _dict(_get(app, endpoint, id=id, auth_required=True if app in AUTH_ENDPOINTS else False, **kwargs))
  File "/Users/tstrickx/Documents/Projects/salt/salt/modules/netbox.py", line 128, in _get
    kwargs = __utils__['args.clean_kwargs'](**kwargs)
KeyError: u'args.clean_kwargs'

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Aug 3, 2018

Contributor

Are you using this on 2017.7 or older? because the args.py file was added starting in 2018.3.

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Aug 3, 2018

Contributor

you would need to include the args.py in your salt://_utils as well for older versions.

This comment has been minimized.

Copy link
@Ichabond

Ichabond Aug 3, 2018

Author Contributor

This happened while running the unit tests using ./runtests.py --name=unit.modules.test_netbox. Not sure how that relates to which version of Salt I'm running.
Maybe this is relevant?

pytest-salt (2018.2.2)          - Pytest Salt Plugin
  INSTALLED: 2018.2.2 (latest)
}
}
}
oc_if[if_name] = salt.utils.dictupdate.update(oc_if[if_name], subif_descr)

This comment has been minimized.

Copy link
@gtmanfred

gtmanfred Aug 3, 2018

Contributor

__utils__['dictupdate.update']()

return if_name, '0'


def filter_(app, endpoint, **kwargs):

This comment has been minimized.

Copy link
@cachedout

cachedout Aug 3, 2018

Collaborator

We like to avoid the use of **kwargs because it's unclear to the end user what it supposed to be passed here. We either need this made into an explicit variable or an explanation of what's expected here inserted into the function documentation, please.

This comment has been minimized.

Copy link
@Ichabond

Ichabond Aug 3, 2018

Author Contributor

Done.

salt myminion netbox.create_device edge_router router MX480 Juniper BRU
'''
try:

This comment has been minimized.

Copy link
@cachedout

cachedout Aug 3, 2018

Collaborator

This is duplicated in a few places. Can we refactor it into a single location?

This comment has been minimized.

Copy link
@Ichabond

Ichabond Aug 3, 2018

Author Contributor

What do you mean exactly?

This comment has been minimized.

Copy link
@Ichabond

Ichabond Aug 6, 2018

Author Contributor

From what I understood, you want to refactor the "does this object exist in netbox" checks to a single location. Most of these checks are single use, except for the device one, which I guess could be put in a function. Is this what you meant?

nb_device = _get('dcim', 'devices', auth_required=True, name=name)
for k, v in kwargs.items():
setattr(nb_device, k, v)
try:

This comment has been minimized.

Copy link
@cachedout

cachedout Aug 3, 2018

Collaborator

Same here. DRY?

if not nb_man:
create_manufacturer(manufacturer_name)
nb_man = get_('dcim', 'manufacturers', name=manufacturer_name)
if not serial:

This comment has been minimized.

Copy link
@cachedout

cachedout Aug 3, 2018

Collaborator

Should we just make the empty strings the keyword defaults?

This comment has been minimized.

Copy link
@Ichabond

Ichabond Aug 3, 2018

Author Contributor

Done

@Ichabond Ichabond force-pushed the Ichabond:develop branch 4 times, most recently from bf22380 to 10b9ec5 Aug 3, 2018

Update netbox execution module
Add multiple functions to interact with the Netbox API.

@Ichabond Ichabond force-pushed the Ichabond:develop branch from 10b9ec5 to dda283e Aug 6, 2018

@Ichabond

This comment has been minimized.

Copy link
Contributor Author

commented Aug 6, 2018

I have made the requested changes, and updated the tests to function. Please let me know if there's anything else that needs to be done before merging.

@rallytime
Copy link
Contributor

left a comment

This looks good to me. Thanks for updating this.

@Ichabond Ichabond changed the base branch from develop to fluorine Aug 7, 2018

@Ichabond

This comment has been minimized.

Copy link
Contributor Author

commented Aug 7, 2018

I changed the branch to Fluorine. CC @rallytime

@rallytime

This comment has been minimized.

Copy link
Contributor

commented Aug 8, 2018

Thanks @Ichabond! And congrats on your first Salt PR!

@rallytime rallytime merged commit 4f6eccd into saltstack:fluorine Aug 8, 2018

3 of 8 checks passed

continuous-integration/jenkins/pr-merge This commit cannot be built
Details
jenkins/pr/py2-centos-7 The py2-centos-7 job has failed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has failed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has failed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has failed
Details
WIP ready for review
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint The lint job has passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.