daemon: fix for deleting an interface from rj45 node, better error messaging when trying to add an interface to a node that already exists
This commit is contained in:
parent
4a9d16c78c
commit
4b6afe4db7
2 changed files with 19 additions and 5 deletions
|
@ -837,7 +837,12 @@ class CoreNode(CoreNodeBase):
|
||||||
if net.has_custom_iface:
|
if net.has_custom_iface:
|
||||||
return net.custom_iface(self, iface_data)
|
return net.custom_iface(self, iface_data)
|
||||||
else:
|
else:
|
||||||
iface_id = self.newveth(iface_data.id, iface_data.name)
|
iface_id = iface_data.id
|
||||||
|
if iface_id is not None and iface_id in self.ifaces:
|
||||||
|
raise CoreError(
|
||||||
|
f"node({self.name}) already has interface({iface_id})"
|
||||||
|
)
|
||||||
|
iface_id = self.newveth(iface_id, iface_data.name)
|
||||||
self.attachnet(iface_id, net)
|
self.attachnet(iface_id, net)
|
||||||
if iface_data.mac:
|
if iface_data.mac:
|
||||||
self.set_mac(iface_id, iface_data.mac)
|
self.set_mac(iface_id, iface_data.mac)
|
||||||
|
|
|
@ -266,7 +266,9 @@ class Rj45Node(CoreNodeBase):
|
||||||
will run on, default is None for localhost
|
will run on, default is None for localhost
|
||||||
"""
|
"""
|
||||||
super().__init__(session, _id, name, server)
|
super().__init__(session, _id, name, server)
|
||||||
self.iface = CoreInterface(session, self, name, name, mtu, server)
|
self.iface: CoreInterface = CoreInterface(
|
||||||
|
session, self, name, name, mtu, server
|
||||||
|
)
|
||||||
self.iface.transport_type = TransportType.RAW
|
self.iface.transport_type = TransportType.RAW
|
||||||
self.lock: threading.RLock = threading.RLock()
|
self.lock: threading.RLock = threading.RLock()
|
||||||
self.iface_id: Optional[int] = None
|
self.iface_id: Optional[int] = None
|
||||||
|
@ -335,11 +337,12 @@ class Rj45Node(CoreNodeBase):
|
||||||
if iface_id is None:
|
if iface_id is None:
|
||||||
iface_id = 0
|
iface_id = 0
|
||||||
if self.iface.net is not None:
|
if self.iface.net is not None:
|
||||||
raise CoreError("RJ45 nodes support at most 1 network interface")
|
raise CoreError(
|
||||||
|
f"RJ45({self.name}) nodes support at most 1 network interface"
|
||||||
|
)
|
||||||
self.ifaces[iface_id] = self.iface
|
self.ifaces[iface_id] = self.iface
|
||||||
self.iface_id = iface_id
|
self.iface_id = iface_id
|
||||||
if net is not None:
|
self.iface.attachnet(net)
|
||||||
self.iface.attachnet(net)
|
|
||||||
for ip in iface_data.get_ips():
|
for ip in iface_data.get_ips():
|
||||||
self.add_ip(ip)
|
self.add_ip(ip)
|
||||||
return self.iface
|
return self.iface
|
||||||
|
@ -353,6 +356,12 @@ class Rj45Node(CoreNodeBase):
|
||||||
"""
|
"""
|
||||||
self.get_iface(iface_id)
|
self.get_iface(iface_id)
|
||||||
self.ifaces.pop(iface_id)
|
self.ifaces.pop(iface_id)
|
||||||
|
if self.iface.net is None:
|
||||||
|
raise CoreError(
|
||||||
|
f"RJ45({self.name}) is not currently connected to a network"
|
||||||
|
)
|
||||||
|
self.iface.detachnet()
|
||||||
|
self.iface.net = None
|
||||||
self.shutdown()
|
self.shutdown()
|
||||||
|
|
||||||
def get_iface(self, iface_id: int) -> CoreInterface:
|
def get_iface(self, iface_id: int) -> CoreInterface:
|
||||||
|
|
Loading…
Reference in a new issue