Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyschulman committed Aug 14, 2023
1 parent dedcfc5 commit 3513553
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 21 deletions.
3 changes: 2 additions & 1 deletion netcad/device/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
# GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)

from .device import Device, DeviceInterface, DeviceCatalog
from .device_attributed import HostDevice, DeviceNonExclusive, DeviceNotManaged
from .device_attributed import DeviceNonExclusive, DeviceNotManaged
from .device_host import HostDevice, attach_host_port
from .device_group import PseudoDevice, DeviceGroup, DeviceGroupMember
from .peer_interface_id import PeerInterfaceId
from .device_type import DeviceType, DeviceTypeRegistry
Expand Down
19 changes: 0 additions & 19 deletions netcad/device/device_attributed.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
from .device import Device


# noinspection PyUnresolvedReferences
class HostDevice(Device):
"""
Denotes a Host device that is connected to the network. This device is not
managemed by the NetCAD system. The Host device is used to represent
connectivity related design aspects.
Attributes
---------
is_host: bool, always True
is_not_managed: bool, always True
"""

is_host = True
is_pseudo = True
is_not_managed = True


# noinspection PyUnresolvedReferences
class DeviceNonExclusive(Device):
"""
Expand Down
38 changes: 38 additions & 0 deletions netcad/device/device_host.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from .device import Device
from ..helpers import StrEnum

# noinspection PyUnresolvedReferences
class _HostDevice(Device):
"""
Denotes a Host device that is connected to the network. This device is not
managemed by the NetCAD system. The Host device is used to represent
connectivity related design aspects.
Attributes
---------
is_host: bool, always True
is_not_managed: bool, always True
"""

is_host = True
is_pseudo = True
is_not_managed = True


class HostDevice(_HostDevice):
def __init__(self, name: str, **kwargs):
super().__init__(name, **kwargs)
self.port_connectivity = {}
if not kwargs.get('no_auto_cable'):
for iface in self.interfaces.values():
iface.cable_id = self.cable_id(iface.name)

def cable_id(self, port_id):
return f"{self.name}_{port_id}"


def attach_host_port(dev: Device, if_name: str, host_name: str | StrEnum, host_port: str):
host_dev = dev.design.devices[host_name]
with dev.interfaces[if_name] as iface:
iface.profile = host_dev.port_connectivity[host_port]
iface.cable_id = host_dev.cable_id(host_port)
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "netcad"
version = "0.9.2"
version = "0.10.0"
description = "NetCAD/CAM - Network Automation by Design"
authors = ["Jeremy Schulman"]
readme = "README.md"
Expand Down

0 comments on commit 3513553

Please sign in to comment.