This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from nautobot/release-v1.1.1
Release v1.1.1
- Loading branch information
Showing
9 changed files
with
183 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""IP Fabric data models.""" | ||
|
||
from datetime import datetime | ||
|
||
|
||
class Snapshot: | ||
"""IP Fabric Snapshot model.""" | ||
|
||
def __init__(self, **kwargs): | ||
"""Initialize Snapshot class.""" | ||
self.name = kwargs.get("name", None) | ||
self.snapshot_id = kwargs.get("id") | ||
self.end = datetime.fromtimestamp(int(kwargs.get("tsEnd", 0) / 1000)) | ||
self.locked = kwargs.get("locked", False) | ||
self.last = kwargs.get("last", False) | ||
self.prev = kwargs.get("prev", False) | ||
self.last_locked = kwargs.get("last_locked", False) | ||
|
||
def __hash__(self): | ||
"""Snapshot ID is unique so return it's hash.""" | ||
return hash(self.snapshot_id) | ||
|
||
def __repr__(self): | ||
"""Return Description to represent the class.""" | ||
return self.description | ||
|
||
@property | ||
def description(self): | ||
"""Create a description for Slack menu.""" | ||
desc = "🔒 " if self.locked else "" | ||
if self.last: | ||
desc += "$last: " | ||
elif self.prev: | ||
desc += "$prev: " | ||
elif self.last_locked: | ||
desc += "$lastLocked: " | ||
if self.name: | ||
desc += self.name + " - " + self.end.ctime() | ||
else: | ||
desc += self.end.ctime() + " - " + self.snapshot_id | ||
return desc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Test IP Fabric models.""" | ||
import unittest | ||
|
||
from nautobot_chatops_ipfabric import ipfabric_models | ||
|
||
|
||
class TestIPFabricModels(unittest.TestCase): | ||
"""Test Models of IP Fabric.""" | ||
|
||
def test_snapshot(self): | ||
"""Verify the snapshot model works.""" | ||
snap_json = { | ||
"name": None, | ||
"state": "loaded", | ||
"locked": False, | ||
"tsEnd": 1642608948957, | ||
"tsStart": 1642607756999, | ||
"id": "1980e282-df63-4b09-b7fb-701a966040f3", | ||
} | ||
snap = ipfabric_models.Snapshot(**snap_json) | ||
self.assertEqual(hash(snap), hash(snap_json["id"])) | ||
self.assertIn(snap_json["id"], str(snap)) |
Oops, something went wrong.