diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 32847a4..cb10ccd 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -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 diff --git a/README.md b/README.md index a3ef1f5..3135360 100644 --- a/README.md +++ b/README.md @@ -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, diff --git a/docs/plugin.md b/docs/plugin.md index efc08cd..3577668 100644 --- a/docs/plugin.md +++ b/docs/plugin.md @@ -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": { diff --git a/nautobot_ssot_ipfabric/jobs.py b/nautobot_ssot_ipfabric/jobs.py index c5c4ae1..c73863b 100644 --- a/nautobot_ssot_ipfabric/jobs.py +++ b/nautobot_ssot_ipfabric/jobs.py @@ -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: @@ -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}: " @@ -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. @@ -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 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 949ad4d..08cbb65 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 "] license = "Apache-2.0"