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

Prepare for integrations and add Infoblox integration #134

Merged
merged 16 commits into from
Jun 12, 2023

Conversation

snaselj
Copy link
Contributor

@snaselj snaselj commented Jun 5, 2023

Closes #128 #115

  • Adds Infoblox integration from nautobot-plugin-ssot-infoblox.
  • Adds dynamic integration loading.

TODO

  • Test integration.

@snaselj snaselj marked this pull request as ready for review June 5, 2023 14:33
@snaselj snaselj requested a review from a team as a code owner June 5, 2023 14:33
@snaselj
Copy link
Contributor Author

snaselj commented Jun 5, 2023

This PR is ready for review now. Integration is not tested as I do not have access to any Infoblox instance. Commit 82b006a contains changes to files copied from nautobot-plugin-ssot-infoblox.

Copy link
Contributor

@Kircheneer Kircheneer left a comment

Choose a reason for hiding this comment

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

I did not review the Infoblox-related code as I assume it comes from an established plugin?

@@ -362,11 +362,11 @@ Once the dependencies are resolved, stop the existing containers, rebuild the Do

### Installing Additional Nautobot Plugins

Let's say for example you want the new plugin you're creating to integrate into Slack. To do this, you will want to integrate into the existing Nautobot ChatOps Plugin.
Let's say for example you want the new plugin you're creating to integrate into Nautobot SSoT. To do this, you will want to integrate into the existing Nautobot SSoT Plugin.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be a specific example of a tool to integrate with, like "Infoblox", shouldn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was probably copied from ChatOps plugin without changing the text, I just fixed it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Related to Slack, it's not an Integration, it's Chat Provider. There is no similar entity in SSoT App, that's why I changed Slack -> Nautobot. Any suggestions welcome.

Comment on lines 195 to 208
def _add_integrations(this_module):
for module in each_enabled_integration_module("models"):
for attr_name in dir(module):
attr = getattr(module, attr_name)
if isinstance(attr, type) and issubclass(attr, models.Model) and attr is not models.Model:
logger.debug("Adding model %s from %s", attr_name, module.__file__)
if attr_name in this_module:
raise ValueError(
f"Duplicate model name: {attr_name} from {module.__file__} class {attr.__class__.__name__}"
)
this_module[attr_name] = attr


_add_integrations(globals())
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we maybe solve this using some kind of registration pattern that allows us not to mess with globals? It looks like a little too much magic for my taste 😃

If not, I would at least appreciate a docstring and some comments here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Other option is to use sys.modules, that needs to be imported. Using globals() seems better for me, as it doesn't need to be imported. Will add comments.

nautobot_ssot/urls.py Outdated Show resolved Hide resolved
nautobot_ssot/utils.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
snaselj and others added 3 commits June 5, 2023 17:00
Co-authored-by: Leo Kirchner <Kircheneer@users.noreply.github.com>
Co-authored-by: Leo Kirchner <Kircheneer@users.noreply.github.com>
Co-authored-by: Leo Kirchner <Kircheneer@users.noreply.github.com>
@snaselj
Copy link
Contributor Author

snaselj commented Jun 5, 2023

I did not review the Infoblox-related code as I assume it comes from an established plugin?

Correct.

Copy link
Contributor

@jdrew82 jdrew82 left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Just a few questions and things to address before I can approve though.

development/docker-compose.base.yml Outdated Show resolved Hide resolved
return os.getenv(f"NAUTOBOT_SSOT_{name}", default)


def _get_bool_env(name: str, default=False) -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you're not using the is_truthy helper function that's already imported from settings? I believe that's our standard pattern to use for determining the boolean of a particular value in nautobot_config.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Several reasons :-)

  • is_truthy is using strtobool, that's deprecated in Python 3.10, will be removed.
  • get_bool_env does more that is_truthy (reads from env, prefixing NAUTOBOT_SSOT here), IMHO easier to implement locally using standard libs over custom implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can rename these functions to _get_ssot_env or _get_ssot_bool_env, would that be more clear?

Copy link
Contributor

Choose a reason for hiding this comment

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

I wasn't aware of the deprecation. If that's the case, it might make more sense to update that function in the core app to your method as I guarantee there are a lot of configurations in use out there using is_truthy that's going to break in the future. Better to fix that and continue using it instead of creating some replacement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed as proposed.

development/nautobot_config.py Outdated Show resolved Hide resolved
nautobot_ssot/__init__.py Outdated Show resolved Hide resolved
nautobot_ssot/integrations/infoblox/urls.py Outdated Show resolved Hide resolved
Copy link
Contributor

@jdrew82 jdrew82 left a comment

Choose a reason for hiding this comment

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

Mostly looks good. Just a few questions and things to address before I can approve though.

@snaselj
Copy link
Contributor Author

snaselj commented Jun 6, 2023

Tested and passed Infoblox ⟹ Nautobot job import.

Copy link
Contributor

@Kircheneer Kircheneer left a comment

Choose a reason for hiding this comment

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

LGTM

@bryanculver bryanculver requested a review from jdrew82 June 7, 2023 12:22
Copy link
Contributor

@jdrew82 jdrew82 left a comment

Choose a reason for hiding this comment

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

Still a misunderstanding of the change requested.

development/nautobot_config.py Outdated Show resolved Hide resolved
@snaselj snaselj changed the title Add Infoblox integrations Prepare for integrations and add Infoblox integration Jun 9, 2023
@snaselj
Copy link
Contributor Author

snaselj commented Jun 12, 2023

Resolved conflicts with develop.

Copy link
Contributor

@jdrew82 jdrew82 left a comment

Choose a reason for hiding this comment

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

LGTM!

@jdrew82 jdrew82 merged commit 2bd55ec into develop Jun 12, 2023
16 checks passed
@jdrew82 jdrew82 deleted the u/snaselj-115-integrations branch June 12, 2023 15:04
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.

Migrate Infoblox SSoT Plugin to This Repo
3 participants