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

Commit

Permalink
Merge pull request #137 from nautobot/release-v2.0.2
Browse files Browse the repository at this point in the history
Release v2.0.2
  • Loading branch information
pke11y authored Jul 13, 2023
2 parents 8841977 + e952f0c commit 85654d1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 28 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## v2.0.2 - 2023-07-13

### Fixed

- #130 - Fix IP Fabric client snapshot reloading.
- #136 - Correct documentation on `nautobot-ssot` framework requirement.

## v2.0.1 - 2023-05-26

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Example `PLUGINS_CONFIG` to be updated in `nautobot_config.py` after successful
ability to call the sync job through chatops, you will be required to configure it.

```python
PLUGINS = ["nautobot_ssot", "nautobot_ssot_ipfabric"]

PLUGINS_CONFIG = {
"nautobot_chatops": {
"enable_slack": True,
Expand Down
2 changes: 1 addition & 1 deletion docs/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Once installed, the plugin needs to be enabled in your `nautobot_config.py` as w

```python
# In your nautobot_config.py
PLUGINS = ["nautobot_ssot_ipfabric"]
PLUGINS = ["nautobot_ssot", "nautobot_ssot_ipfabric"]

PLUGINS_CONFIG = {
"nautobot_ssot_ipfabric": {
Expand Down
60 changes: 34 additions & 26 deletions nautobot_ssot_ipfabric/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def is_valid_uuid(identifier):
return False


def get_formatted_snapshots(client):
def get_formatted_snapshots(client: IPFClient):
"""Get all loaded snapshots and format them for display in choice menu.
Returns:
Expand All @@ -50,8 +50,7 @@ def get_formatted_snapshots(client):
formatted_snapshots = {}
snapshot_refs = []
if client:
client.update()
for snapshot_ref, snapshot in client.snapshots.items():
for snapshot_ref, snapshot in client.loaded_snapshots.items():
description = ""
if snapshot_ref in [LAST, PREV, LAST_LOCKED]:
description += f"{snapshot_ref}: "
Expand Down Expand Up @@ -139,6 +138,20 @@ class Meta:
"dry_run",
)

@staticmethod
def _init_ipf_client():
try:
return IPFClient(
base_url=IPFABRIC_HOST,
token=IPFABRIC_API_TOKEN,
verify=IPFABRIC_SSL_VERIFY,
timeout=IPFABRIC_TIMEOUT,
unloaded=False,
)
except (RuntimeError, ConnectError) as error:
print(f"Got an error {error}")
return None

@classmethod
def _get_vars(cls):
"""Extend JobDataSource._get_vars to include some variables.
Expand All @@ -147,30 +160,23 @@ def _get_vars(cls):
"""
got_vars = super()._get_vars()

if cls.snapshot is None:
try:
cls.client = IPFClient(
base_url=IPFABRIC_HOST,
token=IPFABRIC_API_TOKEN,
verify=IPFABRIC_SSL_VERIFY,
timeout=IPFABRIC_TIMEOUT,
)
except (RuntimeError, ConnectError) as error:
print(f"Got an error {error}")
cls.client = None

formatted_snapshots = get_formatted_snapshots(cls.client)
if formatted_snapshots:
default_choice = formatted_snapshots["$last"][::-1]
else:
default_choice = "$last"
if cls.client is None:
cls.client = cls._init_ipf_client()
else:
cls.client.update()

cls.snapshot = ChoiceVar(
description="IPFabric snapshot to sync from. Defaults to $last",
default=default_choice,
choices=[(snapshot_id, snapshot_name) for snapshot_name, snapshot_id in formatted_snapshots.values()],
required=False,
)
formatted_snapshots = get_formatted_snapshots(cls.client)
if formatted_snapshots:
default_choice = formatted_snapshots["$last"][::-1]
else:
default_choice = "$last"

cls.snapshot = ChoiceVar(
description="IPFabric snapshot to sync from. Defaults to $last",
default=default_choice,
choices=[(snapshot_id, snapshot_name) for snapshot_name, snapshot_id in formatted_snapshots.values()],
required=False,
)

if hasattr(cls, "snapshot"):
got_vars["snapshot"] = cls.snapshot
Expand Down Expand Up @@ -219,6 +225,8 @@ def load_target_adapter(self):

def sync_data(self):
"""Sync a device data from IP Fabric into Nautobot."""
if self.client is None:
self.client = self._init_ipf_client()
if self.client is None:
self.log_failure(message="IPFabric client is not ready. Check your config.")
return
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-ipfabric"
version = "2.0.1"
version = "2.0.2"
description = "Nautobot SSoT IPFabric"
authors = ["Network to Code, LLC <info@networktocode.com>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 85654d1

Please sign in to comment.