Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #86 from nautobot/develop
Browse files Browse the repository at this point in the history
release: 0.5.2
  • Loading branch information
jdrew82 authored Jul 15, 2022
2 parents 7d9288d + f195aef commit 7108e29
Show file tree
Hide file tree
Showing 19 changed files with 51 additions and 78 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,23 @@ Below are the data mappings between objects within Infoblox and the correspondin
| ----------------- | -------------- |
| Network | Prefix |
| IP Address | IP Address |
| ~~Vlan~~ | ~~VLAN~~ |
| ~~Vlan view~~ | ~~VLAN Group~~ |
| VLAN | VLAN |
| VLAN view | VLAN Group |
| Network container | Aggregate |

> **_NOTE_**: VLAN and VLAN Group will be turned on within the next available releases.
### DiffSyncModel - Network

![Diffsync Model - Network](./diffsyncmodel-network.png)
![Diffsync Model - Network](./docs/static/diffsyncmodel-network.png)

### DiffSyncModel - IPAddress

![Diffsync Model - IPAddress](./diffsyncmodel-ipaddress.png)
![Diffsync Model - IPAddress](./docs/static/diffsyncmodel-ipaddress.png)

### DiffSyncModel - Aggregate

![Diffsync Model - Aggregate](./diffsyncmodel-aggregate.png)
![Diffsync Model - Aggregate](./docs/static/diffsyncmodel-aggregate.png)

## Contributing

Expand All @@ -102,12 +102,12 @@ Below is a quick start guide if you're already familiar with the development env

The [PyInvoke](http://www.pyinvoke.org/) library is used to provide some helper commands based on the environment. There are a few configuration parameters which can be passed to PyInvoke to override the default configuration:

* `nautobot_ver`: the version of Nautobot to use as a base for any built docker containers (default: 1.1.4)
* `project_name`: the default docker compose project name (default: nautobot_ssot_infoblox)
* `python_ver`: the version of Python to use as a base for any built docker containers (default: 3.6)
* `local`: a boolean flag indicating if invoke tasks should be run on the host or inside the docker containers (default: False, commands will be run in docker containers)
* `compose_dir`: the full path to a directory containing the project compose files
* `compose_files`: a list of compose files applied in order (see [Multiple Compose files](https://docs.docker.com/compose/extends/#multiple-compose-files) for more information)
- `nautobot_ver`: the version of Nautobot to use as a base for any built docker containers (default: 1.1.4)
- `project_name`: the default docker compose project name (default: nautobot_ssot_infoblox)
- `python_ver`: the version of Python to use as a base for any built docker containers (default: 3.6)
- `local`: a boolean flag indicating if invoke tasks should be run on the host or inside the docker containers (default: False, commands will be run in docker containers)
- `compose_dir`: the full path to a directory containing the project compose files
- `compose_files`: a list of compose files applied in order (see [Multiple Compose files](https://docs.docker.com/compose/extends/#multiple-compose-files) for more information)

Using **PyInvoke** these configuration options can be overridden using [several methods](http://docs.pyinvoke.org/en/stable/concepts/configuration.html). Perhaps the simplest is simply setting an environment variable `INVOKE_NAUTOBOT_SSOT_INFOBLOX_VARIABLE_NAME` where `VARIABLE_NAME` is the variable you are trying to override. The only exception is `compose_files`, because it is a list it must be overridden in a yaml file. There is an example `invoke.yml` (`invoke.example.yml`) in this directory which can be used as a starting point.

Expand Down Expand Up @@ -220,6 +220,6 @@ Sign up [here](http://slack.networktocode.com/)

## Screenshots

![Infoblox SSoT Status](./ssot-status.png)
![Infoblox SSoT Status](./docs/static/ssot-status.png)

![Infoblox SSoT Logs](./ssot-logs.png)
![Infoblox SSoT Logs](./docs/static/ssot-logs.png)
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
2 changes: 1 addition & 1 deletion nautobot_ssot_infoblox/diffsync/adapters/infoblox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from diffsync import DiffSync
from diffsync.enum import DiffSyncFlags
from nautobot.extras.plugins.exceptions import PluginImproperlyConfigured
from nautobot_ssot_infoblox.diffsync.client import InfobloxApi
from nautobot_ssot_infoblox.utils.client import InfobloxApi
from nautobot_ssot_infoblox.diffsync.models.infoblox import (
InfobloxAggregate,
InfobloxIPAddress,
Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot_infoblox/diffsync/adapters/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
NautobotVlan,
)
from nautobot_ssot_infoblox.constant import TAG_COLOR
from nautobot_ssot_infoblox.utils import nautobot_vlan_status
from nautobot_ssot_infoblox.utils.diffsync import nautobot_vlan_status


class NautobotMixin:
Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot_infoblox/diffsync/models/nautobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from nautobot.ipam.models import VLAN as OrmVlan
from nautobot.ipam.models import VLANGroup as OrmVlanGroup
from nautobot_ssot_infoblox.diffsync.models.base import Aggregate, Network, IPAddress, Vlan, VlanView
from nautobot_ssot_infoblox.diffsync.utilities import create_tag_sync_from_infoblox
from nautobot_ssot_infoblox.utils.diffsync import create_tag_sync_from_infoblox


class NautobotNetwork(Network):
Expand Down
17 changes: 0 additions & 17 deletions nautobot_ssot_infoblox/diffsync/utilities.py

This file was deleted.

2 changes: 1 addition & 1 deletion nautobot_ssot_infoblox/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from diffsync import DiffSyncFlags
from nautobot_ssot_infoblox.diffsync.adapters import infoblox, nautobot
from nautobot_ssot_infoblox.diffsync.client import InfobloxApi
from nautobot_ssot_infoblox.utils.client import InfobloxApi
from nautobot_ssot_infoblox.constant import PLUGIN_CFG


Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot_infoblox/tests/fixtures_infoblox.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os


from nautobot_ssot_infoblox.diffsync import client
from nautobot_ssot_infoblox.utils import client

FIXTURES = os.environ.get("FIXTURE_DIR", "nautobot_ssot_infoblox/tests/fixtures")

Expand Down
10 changes: 5 additions & 5 deletions nautobot_ssot_infoblox/tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import requests_mock

# from requests_mock.mocker import mock
from nautobot_ssot_infoblox.diffsync.client import InvalidUrlScheme
from nautobot_ssot_infoblox.utils.client import InvalidUrlScheme
from nautobot_ssot_infoblox.tests.fixtures_infoblox import (
get_ptr_record_by_name,
localhost_client_infoblox,
Expand Down Expand Up @@ -423,7 +423,7 @@ def test_create_host_record_failure(self):

self.assertEqual(response, [])

@patch("nautobot_ssot_infoblox.diffsync.client.InfobloxApi._find_network_reference")
@patch("nautobot_ssot_infoblox.utils.client.InfobloxApi._find_network_reference")
def test_find_next_available_ip_success(self, mock_find_network_reference):
test_network = "10.220.0.0/22"
mock_find_network_reference.return_value = find_network_reference().get("result")
Expand All @@ -437,7 +437,7 @@ def test_find_next_available_ip_success(self, mock_find_network_reference):
print(next_ip)
self.assertEqual(next_ip, "10.220.0.1")

@patch("nautobot_ssot_infoblox.diffsync.client.InfobloxApi._find_network_reference")
@patch("nautobot_ssot_infoblox.utils.client.InfobloxApi._find_network_reference")
def test_find_next_available_ip_no_network_reference(self, mock_find_network_reference):
test_network = "10.220.0.0/22"
mock_find_network_reference.side_effect = Exception
Expand All @@ -451,7 +451,7 @@ def test_find_next_available_ip_no_network_reference(self, mock_find_network_ref

self.assertEqual(next_ip, "")

@patch("nautobot_ssot_infoblox.diffsync.client.InfobloxApi.find_next_available_ip")
@patch("nautobot_ssot_infoblox.utils.client.InfobloxApi.find_next_available_ip")
def test_reserve_fixed_address_success(self, mock_find_next_available_ip):
test_network = "10.220.0.0/22"
test_mac = "11:22:33:AA:BB:CC"
Expand All @@ -466,7 +466,7 @@ def test_reserve_fixed_address_success(self, mock_find_next_available_ip):

self.assertEqual(reserved_ip, "10.220.0.1")

@patch("nautobot_ssot_infoblox.diffsync.client.InfobloxApi.find_next_available_ip")
@patch("nautobot_ssot_infoblox.utils.client.InfobloxApi.find_next_available_ip")
def test_reserve_fixed_address_no_ip(self, mock_find_next_available_ip):
test_network = "10.220.0.0/22"
test_mac = "11:22:33:AA:BB:CC"
Expand Down
2 changes: 1 addition & 1 deletion nautobot_ssot_infoblox/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Util tests that do not require Django."""
import unittest

from nautobot_ssot_infoblox.utils import get_vlan_view_name, nautobot_vlan_status
from nautobot_ssot_infoblox.utils.diffsync import get_vlan_view_name, nautobot_vlan_status


class TestUtils(unittest.TestCase):
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot_infoblox/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Utility functions for working with Infoblox and Nautobot."""
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def _get_network_ref(self, prefix): # pylint: disable=inconsistent-return-state
Returns Response:
"network/ZG5zLm5ldHdvcmskMTkyLjAuMi4wLzI0LzA:192.0.2.0/24/default"
"""
for item in self.get_all_networks(prefix):
for item in self.get_all_subnets(prefix):
if item["network"] == prefix:
return item["_ref"]

Expand Down Expand Up @@ -252,39 +252,6 @@ def get_all_ipv4address_networks(self, prefixes):
logger.info(response.json()[0])
return response.json()[0]

def get_all_networks(self, prefix=None):
"""Get all IPv4 networks.
Args:
prefix (str): Network prefix - '10.220.0.0/22'
Returns:
(list): IPv4 dict objects
Return Response:
[
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMjIzLjAuMC8yMS8w:10.223.0.0/21/default",
"network": "10.223.0.0/21",
"network_view": "default"
},
{
"_ref": "network/ZG5zLm5ldHdvcmskMTAuMjIwLjY0LjAvMjEvMA:10.220.64.0/21/default",
"network": "10.220.64.0/21",
"network_view": "default"
}
]
"""
params = {"_return_as_object": 1}

if prefix:
params.update({"network": prefix})

api_path = "network"
response = self._request("GET", api_path, params=params)
logger.info(response.json)
return response.json().get("result")

def create_network(self, prefix, comment=None):
"""Create a network.
Expand Down Expand Up @@ -683,9 +650,12 @@ def get_dhcp_lease_from_hostname(self, hostname):
logger.info(response.json)
return response.json()

def get_all_subnets(self):
def get_all_subnets(self, prefix: str = None):
"""Get all Subnets.
Args:
prefix (str): Network prefix - '10.220.0.0/22'
Returns:
(list) of record dicts
Expand All @@ -705,6 +675,9 @@ def get_all_subnets(self):
"""
url_path = "network"
params = {"_return_as_object": 1, "_return_fields": "network,network_view,comment", "_max_results": 10000}

if prefix:
params.update({"network": prefix})
try:
response = self._request("GET", url_path, params=params)
except HTTPError as err:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
"""Utilities."""
"""Utilities for DiffSync related stuff."""

from nautobot.extras.models import Tag
from nautobot_ssot_infoblox.constant import TAG_COLOR


def create_tag_sync_from_infoblox():
"""Create tag for tagging objects that have been created by Infoblox."""
tag, _ = Tag.objects.get_or_create(
slug="ssot-synced-from-infoblox",
defaults={
"name": "SSoT Synced from Infoblox",
"description": "Object synced at some point from Infoblox",
"color": TAG_COLOR,
},
)
return tag


def get_vlan_view_name(reference):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nautobot-ssot-infoblox"
version = "0.5.1"
version = "0.5.2"
description = "Nautobot SSoT Infoblox"
authors = ["Network to Code, LLC <[email protected]>"]
license = "Apache-2.0"
Expand Down
Binary file removed ssot-under-the-hood.gif
Binary file not shown.

0 comments on commit 7108e29

Please sign in to comment.