Skip to content

Commit

Permalink
replace VirtualInterface with VMInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
leoparente committed Aug 29, 2024
1 parent d0ef5ef commit 18e3faf
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ if __name__ == "__main__":
* [Cluster](./docs/entities.md#cluster)
* [Virtual Machine](./docs/entities.md#virtual-machine)
* [Virtual Disk](./docs/entities.md#virtual-disk)
* [Virtual Interface](./docs/entities.md#virtual-interface)
* [VM Interface](./docs/entities.md#vm-interface)

## Development notes

Expand Down
22 changes: 11 additions & 11 deletions docs/entities.md
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ if __name__ == "__main__":

```

## Virtual Interface
## VM Interface

Attributes:

Expand All @@ -1273,7 +1273,7 @@ Attributes:
from netboxlabs.diode.sdk import DiodeClient
from netboxlabs.diode.sdk.ingester import (
Entity,
VirtualInterface,
VMInterface,
VirtualMachine,
Cluster,
ClusterGroup,
Expand All @@ -1296,20 +1296,20 @@ def main():
entities = []

"""
VirtualInterface entity with only a name provided will attempt to create or update a name
VMInterface entity with only a name provided will attempt to create or update a name
with the given name and placeholders (i.e. "undefined") for other nested objects types (e.g.
VirtualMachine) required by NetBox.
"""

virtual_interface = VirtualInterface(name="Interface A")
vminterface = VMInterface(name="Interface A")

entities.append(Entity(virtual_interface=virtual_interface))
entities.append(Entity(vminterface=vminterface))

"""
VirtualInterface entity using flat data structure.
VMInterface entity using flat data structure.
"""

virtual_interface_flat = VirtualInterface(
vminterface_flat = VMInterface(
name="Interface A",
virtual_machine="VM A",
enabled=True,
Expand All @@ -1319,13 +1319,13 @@ def main():
tags=["tag 1", "tag 2"],
)

entities.append(Entity(virtual_interface=virtual_interface_flat))
entities.append(Entity(vminterface=vminterface_flat))

"""
VirtualInterface entity using explicit data structure.
VMInterface entity using explicit data structure.
"""

virtual_interface_explicit = VirtualInterface(
vminterface_explicit = VMInterface(
name="Interface A",
virtual_machine=VirtualMachine(
name="VM A",
Expand Down Expand Up @@ -1399,7 +1399,7 @@ def main():
tags=["tag 1", "tag 2"],
)

entities.append(Entity(virtual_interface=virtual_interface_explicit))
entities.append(Entity(vminterface=vminterface_explicit))

response = client.ingest(entities=entities)
if response.errors:
Expand Down
74 changes: 37 additions & 37 deletions netboxlabs/diode/sdk/diode/v1/ingester_pb2.py

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions netboxlabs/diode/sdk/diode/v1/ingester_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ class VirtualMachine(_message.Message):
tags: _containers.RepeatedCompositeFieldContainer[Tag]
def __init__(self, name: _Optional[str] = ..., status: _Optional[str] = ..., site: _Optional[_Union[Site, _Mapping]] = ..., cluster: _Optional[_Union[Cluster, _Mapping]] = ..., role: _Optional[_Union[Role, _Mapping]] = ..., device: _Optional[_Union[Device, _Mapping]] = ..., platform: _Optional[_Union[Platform, _Mapping]] = ..., primary_ip4: _Optional[_Union[IPAddress, _Mapping]] = ..., primary_ip6: _Optional[_Union[IPAddress, _Mapping]] = ..., vcpus: _Optional[int] = ..., memory: _Optional[int] = ..., disk: _Optional[int] = ..., description: _Optional[str] = ..., comments: _Optional[str] = ..., tags: _Optional[_Iterable[_Union[Tag, _Mapping]]] = ...) -> None: ...

class VirtualInterface(_message.Message):
class VMInterface(_message.Message):
__slots__ = ("virtual_machine", "name", "enabled", "mtu", "mac_address", "description", "tags")
VIRTUAL_MACHINE_FIELD_NUMBER: _ClassVar[int]
NAME_FIELD_NUMBER: _ClassVar[int]
Expand Down Expand Up @@ -308,7 +308,7 @@ class Tag(_message.Message):
def __init__(self, name: _Optional[str] = ..., slug: _Optional[str] = ..., color: _Optional[str] = ...) -> None: ...

class Entity(_message.Message):
__slots__ = ("site", "platform", "manufacturer", "device", "device_role", "device_type", "interface", "ip_address", "prefix", "cluster_group", "cluster_type", "cluster", "virtual_machine", "virtual_interface", "virtual_disk", "timestamp")
__slots__ = ("site", "platform", "manufacturer", "device", "device_role", "device_type", "interface", "ip_address", "prefix", "cluster_group", "cluster_type", "cluster", "virtual_machine", "vminterface", "virtual_disk", "timestamp")
SITE_FIELD_NUMBER: _ClassVar[int]
PLATFORM_FIELD_NUMBER: _ClassVar[int]
MANUFACTURER_FIELD_NUMBER: _ClassVar[int]
Expand All @@ -322,7 +322,7 @@ class Entity(_message.Message):
CLUSTER_TYPE_FIELD_NUMBER: _ClassVar[int]
CLUSTER_FIELD_NUMBER: _ClassVar[int]
VIRTUAL_MACHINE_FIELD_NUMBER: _ClassVar[int]
VIRTUAL_INTERFACE_FIELD_NUMBER: _ClassVar[int]
VMINTERFACE_FIELD_NUMBER: _ClassVar[int]
VIRTUAL_DISK_FIELD_NUMBER: _ClassVar[int]
TIMESTAMP_FIELD_NUMBER: _ClassVar[int]
site: Site
Expand All @@ -338,10 +338,10 @@ class Entity(_message.Message):
cluster_type: ClusterType
cluster: Cluster
virtual_machine: VirtualMachine
virtual_interface: VirtualInterface
vminterface: VMInterface
virtual_disk: VirtualDisk
timestamp: _timestamp_pb2.Timestamp
def __init__(self, site: _Optional[_Union[Site, _Mapping]] = ..., platform: _Optional[_Union[Platform, _Mapping]] = ..., manufacturer: _Optional[_Union[Manufacturer, _Mapping]] = ..., device: _Optional[_Union[Device, _Mapping]] = ..., device_role: _Optional[_Union[Role, _Mapping]] = ..., device_type: _Optional[_Union[DeviceType, _Mapping]] = ..., interface: _Optional[_Union[Interface, _Mapping]] = ..., ip_address: _Optional[_Union[IPAddress, _Mapping]] = ..., prefix: _Optional[_Union[Prefix, _Mapping]] = ..., cluster_group: _Optional[_Union[ClusterGroup, _Mapping]] = ..., cluster_type: _Optional[_Union[ClusterType, _Mapping]] = ..., cluster: _Optional[_Union[Cluster, _Mapping]] = ..., virtual_machine: _Optional[_Union[VirtualMachine, _Mapping]] = ..., virtual_interface: _Optional[_Union[VirtualInterface, _Mapping]] = ..., virtual_disk: _Optional[_Union[VirtualDisk, _Mapping]] = ..., timestamp: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ...) -> None: ...
def __init__(self, site: _Optional[_Union[Site, _Mapping]] = ..., platform: _Optional[_Union[Platform, _Mapping]] = ..., manufacturer: _Optional[_Union[Manufacturer, _Mapping]] = ..., device: _Optional[_Union[Device, _Mapping]] = ..., device_role: _Optional[_Union[Role, _Mapping]] = ..., device_type: _Optional[_Union[DeviceType, _Mapping]] = ..., interface: _Optional[_Union[Interface, _Mapping]] = ..., ip_address: _Optional[_Union[IPAddress, _Mapping]] = ..., prefix: _Optional[_Union[Prefix, _Mapping]] = ..., cluster_group: _Optional[_Union[ClusterGroup, _Mapping]] = ..., cluster_type: _Optional[_Union[ClusterType, _Mapping]] = ..., cluster: _Optional[_Union[Cluster, _Mapping]] = ..., virtual_machine: _Optional[_Union[VirtualMachine, _Mapping]] = ..., vminterface: _Optional[_Union[VMInterface, _Mapping]] = ..., virtual_disk: _Optional[_Union[VirtualDisk, _Mapping]] = ..., timestamp: _Optional[_Union[_timestamp_pb2.Timestamp, _Mapping]] = ...) -> None: ...

class IngestRequest(_message.Message):
__slots__ = ("stream", "entities", "id", "producer_app_name", "producer_app_version", "sdk_name", "sdk_version")
Expand Down
18 changes: 9 additions & 9 deletions netboxlabs/diode/sdk/ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Site as SitePb,
Tag as TagPb,
VirtualDisk as VirtualDiskPb,
VirtualInterface as VirtualInterfacePb,
VMInterface as VMInterfacePb,
VirtualMachine as VirtualMachinePb,
)

Expand Down Expand Up @@ -621,8 +621,8 @@ def __new__(
)


class VirtualInterface:
"""VirtualInterface message wrapper."""
class VMInterface:
"""VMInterface message wrapper."""

def __new__(
cls,
Expand All @@ -633,7 +633,7 @@ def __new__(
mac_address: str | None = None,
description: str | None = None,
tags: list[str | Tag | TagPb] | None = None,
) -> VirtualInterfacePb:
) -> VMInterfacePb:
"""Create a new virtual interface protobuf message."""
virtual_machine = convert_to_protobuf(
virtual_machine, VirtualMachinePb, name=virtual_machine
Expand All @@ -642,7 +642,7 @@ def __new__(
if isinstance(tags, list) and all(isinstance(t, str) for t in tags):
tags = [TagPb(name=tag) for tag in tags]

return VirtualInterfacePb(
return VMInterfacePb(
name=name,
virtual_machine=virtual_machine,
enabled=enabled,
Expand Down Expand Up @@ -671,7 +671,7 @@ def __new__(
cluster_type: str | ClusterType | ClusterTypePb | None = None,
cluster: str | Cluster | ClusterPb | None = None,
virtual_disk: str | VirtualDisk | VirtualDiskPb | None = None,
virtual_interface: str | VirtualInterface | VirtualInterfacePb | None = None,
vminterface: str | VMInterface | VMInterfacePb | None = None,
virtual_machine: str | VirtualMachine | VirtualMachinePb | None = None,
timestamp: _timestamp_pb2.Timestamp | None = None,
):
Expand All @@ -697,8 +697,8 @@ def __new__(
virtual_disk = convert_to_protobuf(
virtual_disk, VirtualDiskPb, name=virtual_disk
)
virtual_interface = convert_to_protobuf(
virtual_interface, VirtualInterfacePb, name=virtual_interface
vminterface = convert_to_protobuf(
vminterface, VMInterfacePb, name=vminterface
)
virtual_machine = convert_to_protobuf(
virtual_machine, VirtualMachinePb, name=virtual_machine
Expand All @@ -718,7 +718,7 @@ def __new__(
cluster_type=cluster_type,
cluster=cluster,
virtual_disk=virtual_disk,
virtual_interface=virtual_interface,
vminterface=vminterface,
virtual_machine=virtual_machine,
timestamp=timestamp,
)
36 changes: 18 additions & 18 deletions tests/test_ingester.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Site as SitePb,
Tag as TagPb,
VirtualDisk as VirtualDiskPb,
VirtualInterface as VirtualInterfacePb,
VMInterface as VMInterfacePb,
VirtualMachine as VirtualMachinePb,
)
from netboxlabs.diode.sdk.ingester import (
Expand All @@ -38,7 +38,7 @@
Site,
Tag,
VirtualDisk,
VirtualInterface,
VMInterface,
VirtualMachine,
convert_to_protobuf,
)
Expand Down Expand Up @@ -597,9 +597,9 @@ def test_virtual_disk_instantiation_with_all_fields():
assert isinstance(tag, TagPb)


def test_virtual_interface_instantiation_with_all_fields():
"""Check VirtualInterface instantiation with all fields."""
virtual_interface = VirtualInterface(
def test_vminterface_instantiation_with_all_fields():
"""Check VMInterface instantiation with all fields."""
vminterface = VMInterface(
name="eth01",
virtual_machine="vm1",
enabled=True,
Expand All @@ -608,15 +608,15 @@ def test_virtual_interface_instantiation_with_all_fields():
description="Virtual interface",
tags=["vm", "ifce"],
)
assert isinstance(virtual_interface, VirtualInterfacePb)
assert isinstance(virtual_interface.virtual_machine, VirtualMachinePb)
assert virtual_interface.name == "eth01"
assert virtual_interface.virtual_machine.name == "vm1"
assert virtual_interface.mtu == 1500
assert virtual_interface.mac_address == "00:00:00:00:00:00"
assert virtual_interface.description == "Virtual interface"
assert len(virtual_interface.tags) == 2
for tag in virtual_interface.tags:
assert isinstance(vminterface, VMInterfacePb)
assert isinstance(vminterface.virtual_machine, VirtualMachinePb)
assert vminterface.name == "eth01"
assert vminterface.virtual_machine.name == "vm1"
assert vminterface.mtu == 1500
assert vminterface.mac_address == "00:00:00:00:00:00"
assert vminterface.description == "Virtual interface"
assert len(vminterface.tags) == 2
for tag in vminterface.tags:
assert isinstance(tag, TagPb)


Expand Down Expand Up @@ -779,11 +779,11 @@ def test_entity_instantiation_with_virtual_disk():
assert entity.virtual_disk.name == "VirtualDisk1"


def test_entity_instantiation_with_virtual_interface():
def test_entity_instantiation_with_vminterface():
"""Check Entity instantiation with virtual interface."""
entity = Entity(
virtual_interface="VirtualInterface1",
vminterface="VMInterface1",
)
assert isinstance(entity, EntityPb)
assert isinstance(entity.virtual_interface, VirtualInterfacePb)
assert entity.virtual_interface.name == "VirtualInterface1"
assert isinstance(entity.vminterface, VMInterfacePb)
assert entity.vminterface.name == "VMInterface1"

0 comments on commit 18e3faf

Please sign in to comment.