Change describe_state to use names instead of uuids
This commit is contained in:
@@ -102,7 +102,7 @@ class DomainController(SimComponent):
|
|||||||
:rtype: Dict
|
:rtype: Dict
|
||||||
"""
|
"""
|
||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state.update({"accounts": {uuid: acct.describe_state() for uuid, acct in self.accounts.items()}})
|
state.update({"accounts": {acct.username: acct.describe_state() for acct in self.accounts.values()}})
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def _register_account(self, account: Account) -> None:
|
def _register_account(self, account: Account) -> None:
|
||||||
|
|||||||
@@ -199,10 +199,24 @@ class Network(SimComponent):
|
|||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state.update(
|
state.update(
|
||||||
{
|
{
|
||||||
"nodes": {uuid: node.describe_state() for uuid, node in self.nodes.items()},
|
"nodes": {node.hostname: node.describe_state() for node in self.nodes.values()},
|
||||||
"links": {uuid: link.describe_state() for uuid, link in self.links.items()},
|
"links": {},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
# Update the links one-by-one. The key is a 4-tuple of `hostname_a, port_a, hostname_b, port_b`
|
||||||
|
for uuid, link in self.links.items():
|
||||||
|
node_a = link.endpoint_a._connected_node
|
||||||
|
node_b = link.endpoint_b._connected_node
|
||||||
|
hostname_a = node_a.hostname if node_a else None
|
||||||
|
hostname_b = node_b.hostname if node_b else None
|
||||||
|
port_a = link.endpoint_a._port_num_on_node
|
||||||
|
port_b = link.endpoint_b._port_num_on_node
|
||||||
|
state["links"][uuid] = link.describe_state()
|
||||||
|
state["links"][uuid]["hostname_a"] = hostname_a
|
||||||
|
state["links"][uuid]["hostname_b"] = hostname_b
|
||||||
|
state["links"][uuid]["port_a"] = port_a
|
||||||
|
state["links"][uuid]["port_b"] = port_b
|
||||||
|
|
||||||
return state
|
return state
|
||||||
|
|
||||||
def add_node(self, node: Node) -> None:
|
def add_node(self, node: Node) -> None:
|
||||||
|
|||||||
@@ -91,6 +91,8 @@ class NIC(SimComponent):
|
|||||||
"Indicates if the NIC supports Wake-on-LAN functionality."
|
"Indicates if the NIC supports Wake-on-LAN functionality."
|
||||||
_connected_node: Optional[Node] = None
|
_connected_node: Optional[Node] = None
|
||||||
"The Node to which the NIC is connected."
|
"The Node to which the NIC is connected."
|
||||||
|
_port_num_on_node: Optional[int] = None
|
||||||
|
"Which port number is assigned on this NIC"
|
||||||
_connected_link: Optional[Link] = None
|
_connected_link: Optional[Link] = None
|
||||||
"The Link to which the NIC is connected."
|
"The Link to which the NIC is connected."
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
@@ -148,7 +150,7 @@ class NIC(SimComponent):
|
|||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state.update(
|
state.update(
|
||||||
{
|
{
|
||||||
"ip_adress": str(self.ip_address),
|
"ip_address": str(self.ip_address),
|
||||||
"subnet_mask": str(self.subnet_mask),
|
"subnet_mask": str(self.subnet_mask),
|
||||||
"mac_address": self.mac_address,
|
"mac_address": self.mac_address,
|
||||||
"speed": self.speed,
|
"speed": self.speed,
|
||||||
@@ -311,6 +313,8 @@ class SwitchPort(SimComponent):
|
|||||||
"The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B"
|
"The Maximum Transmission Unit (MTU) of the SwitchPort in Bytes. Default is 1500 B"
|
||||||
_connected_node: Optional[Node] = None
|
_connected_node: Optional[Node] = None
|
||||||
"The Node to which the SwitchPort is connected."
|
"The Node to which the SwitchPort is connected."
|
||||||
|
_port_num_on_node: Optional[int] = None
|
||||||
|
"The port num on the connected node."
|
||||||
_connected_link: Optional[Link] = None
|
_connected_link: Optional[Link] = None
|
||||||
"The Link to which the SwitchPort is connected."
|
"The Link to which the SwitchPort is connected."
|
||||||
enabled: bool = False
|
enabled: bool = False
|
||||||
@@ -497,8 +501,8 @@ class Link(SimComponent):
|
|||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state.update(
|
state.update(
|
||||||
{
|
{
|
||||||
"endpoint_a": self.endpoint_a.uuid,
|
"endpoint_a": self.endpoint_a.uuid, # TODO: consider if using UUID is the best way to do this
|
||||||
"endpoint_b": self.endpoint_b.uuid,
|
"endpoint_b": self.endpoint_b.uuid, # TODO: consider if using UUID is the best way to do this
|
||||||
"bandwidth": self.bandwidth,
|
"bandwidth": self.bandwidth,
|
||||||
"current_load": self.current_load,
|
"current_load": self.current_load,
|
||||||
}
|
}
|
||||||
@@ -1094,12 +1098,12 @@ class Node(SimComponent):
|
|||||||
{
|
{
|
||||||
"hostname": self.hostname,
|
"hostname": self.hostname,
|
||||||
"operating_state": self.operating_state.value,
|
"operating_state": self.operating_state.value,
|
||||||
"NICs": {uuid: nic.describe_state() for uuid, nic in self.nics.items()},
|
"NICs": {eth_num: nic.describe_state() for eth_num, nic in self.ethernet_port.items()},
|
||||||
# "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()},
|
# "switch_ports": {uuid, sp for uuid, sp in self.switch_ports.items()},
|
||||||
"file_system": self.file_system.describe_state(),
|
"file_system": self.file_system.describe_state(),
|
||||||
"applications": {uuid: app.describe_state() for uuid, app in self.applications.items()},
|
"applications": {app.name: app.describe_state() for app in self.applications.values()},
|
||||||
"services": {uuid: svc.describe_state() for uuid, svc in self.services.items()},
|
"services": {svc.name: svc.describe_state() for svc in self.services.values()},
|
||||||
"process": {uuid: proc.describe_state() for uuid, proc in self.processes.items()},
|
"process": {proc.name: proc.describe_state() for proc in self.processes.values()},
|
||||||
"revealed_to_red": self.revealed_to_red,
|
"revealed_to_red": self.revealed_to_red,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -1316,6 +1320,7 @@ class Node(SimComponent):
|
|||||||
self.nics[nic.uuid] = nic
|
self.nics[nic.uuid] = nic
|
||||||
self.ethernet_port[len(self.nics)] = nic
|
self.ethernet_port[len(self.nics)] = nic
|
||||||
nic._connected_node = self
|
nic._connected_node = self
|
||||||
|
nic._port_num_on_node = len(self.nics)
|
||||||
nic.parent = self
|
nic.parent = self
|
||||||
self.sys_log.info(f"Connected NIC {nic}")
|
self.sys_log.info(f"Connected NIC {nic}")
|
||||||
if self.operating_state == NodeOperatingState.ON:
|
if self.operating_state == NodeOperatingState.ON:
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class Switch(Node):
|
|||||||
self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)}
|
self.switch_ports = {i: SwitchPort() for i in range(1, self.num_ports + 1)}
|
||||||
for port_num, port in self.switch_ports.items():
|
for port_num, port in self.switch_ports.items():
|
||||||
port._connected_node = self
|
port._connected_node = self
|
||||||
|
port._port_num_on_node = port_num
|
||||||
port.parent = self
|
port.parent = self
|
||||||
port.port_num = port_num
|
port.port_num = port_num
|
||||||
|
|
||||||
|
|||||||
@@ -41,5 +41,5 @@ class Process(Software):
|
|||||||
:rtype: Dict
|
:rtype: Dict
|
||||||
"""
|
"""
|
||||||
state = super().describe_state()
|
state = super().describe_state()
|
||||||
state.update({"operating_state": self.operating_state.name})
|
state.update({"operating_state": self.operating_state.value})
|
||||||
return state
|
return state
|
||||||
|
|||||||
Reference in New Issue
Block a user