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

Config context #36

Closed
wants to merge 19 commits into from
Closed

Config context #36

wants to merge 19 commits into from

Conversation

FragmentedPacket
Copy link

Since config contexts are new as of 2.4 I figured it'd be nice to be able to use those as host vars.

I'm not sure if this implementation is the best way so additional tweaks may be needed.

Overview

  • Add context: under hosts_vars in netbox.yml

hosts_vars: context: variable_name: config_context

  • Once context: is configured under hosts_vars it will gather the context data for a single device or all devices

Sample data

./netbox.py --host switch2 {"ansible_ssh_host": "192.168.1.1", "serial": "awadawd21254", "asset-tag": "1001", "config_context": {"ntp2": "192.168.1.2", "ntp1": "192.168.1.1"}}

./netbox.py --list {"_meta": {"hostvars": {"switch1": {"serial": "cisco-serial", "asset_tag": "1234", "config_context": {"radius": {"radius03": "10.0.0.3", "radius02": "10.0.0.2", "radius01": "10.0.0.1"}, "tacacs": {"acs03": "10.0.0.3", "acs02": "10.0.0.2", "acs01": "10.0.0.1"}, "ntp-servers": {"ntp2": "192.168.1.2", "ntp1": "192.168.1.1"} "10": ["permit 10.0.0.0 0.0.0.255", "permit 172.16.0.0 0.0.255.255"]}} "switch2": {"ansible_ssh_host": "192.168.1.1", "serial": "awadawd21254", "asset-tag": "1001", "config_context": {"ntp2": "192.168.1.2", "ntp1": "192.168.1.1"}}, "group1": ["switch1"], "group2": ["switch2"]}

Tested code and verified it is working as intended. I tested without host_vars.context existing and it works as it did previously and tested with and it add the context data from each host.
@FragmentedPacket
Copy link
Author

It appears it is only failing due to an issue with the Python3.5 TravisCI test:
The command "python setup.py requirements -t" failed and exited with 1 during .

@coveralls
Copy link

coveralls commented Aug 21, 2018

Coverage Status

Coverage decreased (-9.4%) to 90.566% when pulling 16805b8 on FragmentedPacket:config-context into 095cfb1 on AAbouZaid:devel.

I was using id as a variable which is a builtin varable - changed to device_id
@FragmentedPacket
Copy link
Author

FragmentedPacket commented Aug 21, 2018

To-do:

  • Create test for change - this should resolve the coverage/coveralls score and bring it back to 100%

@FragmentedPacket
Copy link
Author

@aabouzaid Do you see this as a benefit? I've never worked on creating tests and want to make sure my code, etc. makes sense before I continue on and learn how to write the tests.

@FragmentedPacket FragmentedPacket deleted the config-context branch August 22, 2018 22:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants