Skip to content

Commit

Permalink
Merge pull request #15 from h4ndzdatm0ld/develop
Browse files Browse the repository at this point in the history
Release v0.1.2
  • Loading branch information
h4ndzdatm0ld authored Jul 21, 2022
2 parents 1983d7c + 0f9a152 commit 6e0c065
Show file tree
Hide file tree
Showing 6 changed files with 287 additions and 451 deletions.
16 changes: 14 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.2] - 2022-07-20

### Added

- fixed bug where VM with zero interfaces caused a key error from empty response
- Added several `debug` statements to show more verbose, optional logging

### Changed

- bumped local dependencies, mostly due to django vulnerability

### Removed

## [0.1.1] - 2022-05-18

Expand Down
20 changes: 9 additions & 11 deletions nautobot_ssot_vsphere/diffsync/adapters/adapter_vsphere.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@ def __init__(self, job, sync, client: VsphereClient, cluster_filter, *args, **kw
def load_cluster_groups(self):
"""Load Cluster Groups (DataCenters)."""
clustergroups = self.client.get_datacenters().json()["value"]
self.job.log_debug(message=f"Loading ClusterGroups {clustergroups}")
for clustergroup in clustergroups:
self.get_or_instantiate(self.diffsync_clustergroup, {"name": clustergroup["name"]})
return clustergroups

def load_virtualmachines(self, cluster, diffsync_cluster):
"""Load Virtual Machines."""
virtual_machines = self.client.get_vms_from_cluster(cluster["cluster"]).json()["value"]
self.job.log_debug(message=f"Loading VirtualMachines from Cluster {cluster}: {virtual_machines}")

for virtual_machine in virtual_machines:
virtual_machine_details = self.client.get_vm_details(virtual_machine["vm"]).json()["value"]
diffsync_virtualmachine, _ = self.get_or_instantiate(
Expand Down Expand Up @@ -78,17 +81,15 @@ def load_ip_addresses(self, vsphere_vm_interfaces, mac_address, diffsync_vminter
if not isinstance(interface, dict):
continue
current_mac = interface["mac_address"].lower() if interface.get("mac_address") else None
if not current_mac == mac_address:
if not current_mac == mac_address or not interface.get("ip"):
continue
# Capture all IP Addresses
for ip_address in interface["ip"]["ip_addresses"]:
self.job.log_debug(message=f"Loading IP Addresses {interface}")
# Convert to IP Object if IPV4 or IPV6 and add to list by version
addr = create_ipaddr(ip_address["ip_address"])
if addr.version == 4:
ipv4_addresses.append(addr)
else:
ipv6_addresses.append(addr)

_ = ipv4_addresses.append(addr) if addr.version == 4 else ipv6_addresses.append(addr)
# Update DiffsyncIpAddress
diffsync_ipaddress, _ = self.get_or_instantiate(
self.diffsync_ipaddress,
{"ip_address": ip_address["ip_address"], "prefix_length": ip_address["prefix_length"]},
Expand Down Expand Up @@ -121,17 +122,13 @@ def load_primary_ip(
else:
if ipv4_addresses:
diffsync_virtualmachine.primary_ip4 = str(ipv4_addresses[-1])

if ipv6_addresses:
diffsync_virtualmachine.primary_ip6 = str(ipv6_addresses[-1])

# self.job.log_debug(
# message=f"Assigning {diffsync_virtualmachine.primary_ip6} as primary to {diffsync_virtualmachine.name}"
# )

def load_vm_interfaces(self, vsphere_virtual_machine, vm_id, diffsync_virtualmachine):
"""Load VM Interfaces."""
nics = vsphere_virtual_machine["nics"]
self.job.log_debug(message=f"Loading NICs for VM-ID {vm_id}: {nics}")
# Get all IPAdders from ALL Nics on Virtual Machine
addrs4 = []
addrs6 = []
Expand Down Expand Up @@ -197,6 +194,7 @@ def load_standalone_vms(self):
virtual_machines = self.client.get_vms().json()["value"]
for virtual_machine in virtual_machines:
virtual_machine_details = self.client.get_vm_details(virtual_machine["vm"]).json()["value"]
self.job.log_debug(message=f"Virtual Machine Details: {virtual_machine_details}")
diffsync_virtualmachine, _ = self.get_or_instantiate(
self.diffsync_virtual_machine,
{"name": virtual_machine["name"]},
Expand Down
1 change: 1 addition & 0 deletions nautobot_ssot_vsphere/diffsync/diffsync_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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
Loading

0 comments on commit 6e0c065

Please sign in to comment.