daemon: renamed LinkData.link_type to LinkData.type and removed LinkOptions.type to remove redundant information, link_type param added to session.add_link, delete_link, and update_link functions

This commit is contained in:
Blake Harnden 2020-06-16 21:53:12 -07:00
parent a29a7a5582
commit 351b99aae0
10 changed files with 37 additions and 28 deletions

View file

@ -132,7 +132,6 @@ class LinkOptions:
Options for creating and updating links within core.
"""
type: LinkTypes = LinkTypes.WIRED
delay: int = None
bandwidth: int = None
loss: float = None
@ -155,7 +154,7 @@ class LinkData:
"""
message_type: MessageFlags = None
link_type: LinkTypes = None
type: LinkTypes = LinkTypes.WIRED
label: str = None
node1_id: int = None
node2_id: int = None

View file

@ -224,6 +224,7 @@ class Session:
iface1_data: InterfaceData = None,
iface2_data: InterfaceData = None,
options: LinkOptions = None,
link_type: LinkTypes = LinkTypes.WIRED,
) -> Tuple[CoreInterface, CoreInterface]:
"""
Add a link between nodes.
@ -236,6 +237,7 @@ class Session:
data, defaults to none
:param options: data for creating link,
defaults to no options
:param link_type: type of link to add
:return: tuple of created core interfaces, depending on link
"""
if not options:
@ -246,7 +248,7 @@ class Session:
iface2 = None
# wireless link
if options.type == LinkTypes.WIRELESS:
if link_type == LinkTypes.WIRELESS:
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):
self._link_wireless(node1, node2, connect=True)
else:
@ -371,6 +373,7 @@ class Session:
iface1_id: int = None,
iface2_id: int = None,
options: LinkOptions = None,
link_type: LinkTypes = LinkTypes.WIRED,
) -> None:
"""
Update link information between nodes.
@ -380,6 +383,7 @@ class Session:
:param iface1_id: interface id for node one
:param iface2_id: interface id for node two
:param options: data to update link with
:param link_type: type of link to update
:return: nothing
:raises core.CoreError: when updating a wireless type link, when there is a
unknown link between networks
@ -390,7 +394,7 @@ class Session:
node2 = self.get_node(node2_id, NodeBase)
logging.info(
"update link(%s) node(%s):interface(%s) node(%s):interface(%s)",
options.type.name,
link_type.name,
node1.name,
iface1_id,
node2.name,
@ -398,7 +402,7 @@ class Session:
)
# wireless link
if options.type == LinkTypes.WIRELESS:
if link_type == LinkTypes.WIRELESS:
raise CoreError("cannot update wireless link")
else:
if isinstance(node1, CoreNodeBase) and isinstance(node2, CoreNodeBase):