Skip to content

Commit

Permalink
mac-addr, netutils (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ndzdatm0ld authored May 18, 2022
1 parent 4450ff8 commit 43a4b0b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions development/nautobot_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@
"VSPHERE_USERNAME": os.getenv("VSPHERE_USERNAME"),
"VSPHERE_PASSWORD": os.getenv("VSPHERE_PASSWORD"),
"VSPHERE_VERIFY_SSL": is_truthy(os.getenv("VSPHERE_VERIFY_SSL", False)),
"DEFAULT_USE_CLUSTERS": False,
"ENFORCE_CLUSTER_GROUP_TOP_LEVEL": False,
# "DEFAULT_USE_CLUSTERS": False,
# "ENFORCE_CLUSTER_GROUP_TOP_LEVEL": False,
},
}

Expand Down
17 changes: 11 additions & 6 deletions nautobot_ssot_vsphere/diffsync/diffsync_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
VirtualMachine,
VMInterface,
)

from netutils.mac import is_valid_mac
from nautobot_ssot_vsphere.diffsync import defaults
from nautobot_ssot_vsphere.utilities import tag_object

Expand Down Expand Up @@ -163,16 +163,21 @@ def create(cls, diffsync, ids, attrs):
def delete(self) -> Optional["DiffSyncModel"]:
"""Delete VMInterfaces from Virtual Machine."""
try:
self.ordered_delete(
VMInterface.objects.get(
if is_valid_mac(self.mac_address):
interface = VMInterface.objects.get(
name=self.name,
virtual_machine=VirtualMachine.objects.get(name=self.virtual_machine),
mac_address=self.mac_address,
)
)
else:
interface = VMInterface.objects.get(
name=self.name,
virtual_machine=VirtualMachine.objects.get(name=self.virtual_machine),
)
self.ordered_delete(interface)
return self
except VirtualMachine.DoesNotExist:
self.diffsync.job.log_warning(f"Unable to match VirtualMachine by name, {self.name}")
except VMInterface.DoesNotExist:
self.diffsync.job.log_warning(f"Unable to match VMInterface by name, {self.name}")

def update(self, attrs):
"""Update VMInterface on Virtual Machine."""
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ packages = [
python = "^3.7"
diffsync = "^1.4.3"
nautobot-ssot = "^1.1.0"
netutils = "^1.1.0"

[tool.poetry.dev-dependencies]
bandit = "*"
Expand Down

0 comments on commit 43a4b0b

Please sign in to comment.