@@ -685,7 +685,7 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
685
685
@click .command ("stop" , help = "prometheus | node_exporter | cadvisor | grafana | flask | container-name | "
686
686
"emulation-name | statsmanager | emulation_executions | pgadmin | all | nginx | postgresql "
687
687
"| docker | clustermanager | hostmanagers | hostmanager | clientmanager | snortmanagers "
688
- "| snortmanager | elkmanager" )
688
+ "| snortmanager | elkmanager | trafficmanagers | trafficmanager " )
689
689
def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
690
690
"""
691
691
Stops an entity
@@ -741,6 +741,10 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "", container_ip: str =
741
741
stop_snort_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
742
742
elif entity == "elkmanager" :
743
743
stop_elk_manager (ip = ip , emulation = name , ip_first_octet = id )
744
+ elif entity == "trafficmanagers" :
745
+ stop_traffic_managers (ip = ip , emulation = name , ip_first_octet = id )
746
+ elif entity == "trafficmanager" :
747
+ stop_traffic_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
744
748
else :
745
749
container_stopped = False
746
750
for node in config .cluster_config .cluster_nodes :
@@ -1059,6 +1063,58 @@ def stop_elk_manager(ip: str, emulation: str, ip_first_octet: int) -> None:
1059
1063
bold = False )
1060
1064
1061
1065
1066
+ def stop_traffic_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
1067
+ """
1068
+ Utility function for stopping the traffic managers
1069
+
1070
+ :param ip: the ip of the node to stop the traffic mangers
1071
+ :param emulation: the emulation of the execution
1072
+ :param ip_first_octet: the ID of the execution
1073
+ :return: None
1074
+ """
1075
+ import csle_common .constants .constants as constants
1076
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1077
+ config = MetastoreFacade .get_config (id = 1 )
1078
+ for node in config .cluster_config .cluster_nodes :
1079
+ if node .ip == ip or ip == "" :
1080
+ stopped = ClusterController .stop_traffic_managers (
1081
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1082
+ ip_first_octet = ip_first_octet )
1083
+ if stopped .outcome :
1084
+ click .secho (f"Stopping traffic managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1085
+ else :
1086
+ click .secho (f"Traffic managers are not stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1087
+ bold = False )
1088
+
1089
+
1090
+ def stop_traffic_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
1091
+ """
1092
+ Utility function for stopping the traffic manager
1093
+
1094
+ :param ip: the ip of the node to stop the traffic manager
1095
+ :param container_ip: the ip of the host that traffic is running on
1096
+ :param emulation: the emulation of the execution
1097
+ :param ip_first_octet: the ID of the execution
1098
+ :return: None
1099
+ """
1100
+ import csle_common .constants .constants as constants
1101
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1102
+ config = MetastoreFacade .get_config (id = 1 )
1103
+ for node in config .cluster_config .cluster_nodes :
1104
+ if node .ip == ip or ip == "" :
1105
+ stopped = ClusterController .stop_traffic_manager (
1106
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1107
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1108
+ if stopped .outcome :
1109
+ click .secho (
1110
+ f"Stopping traffic manager with ip { container_ip } on port:"
1111
+ f"{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1112
+ else :
1113
+ click .secho (f"Traffic manager with ip { container_ip } is not "
1114
+ f"stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1115
+ bold = False )
1116
+
1117
+
1062
1118
@click .argument ('max_workers' , default = 10 , type = int )
1063
1119
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
1064
1120
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1250,7 +1306,8 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1250
1306
@click .command ("start" , help = "prometheus | node_exporter | grafana | cadvisor | flask | pgadmin | "
1251
1307
"container-name | emulation-name | all | statsmanager | training_job "
1252
1308
"| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1253
- "| hostmanager | clientmanager | snortmanagers | snortmanager | elkmanager" )
1309
+ "| hostmanager | clientmanager | snortmanagers | snortmanager | elkmanager "
1310
+ "| trafficmanagers | trafficmanager" )
1254
1311
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1255
1312
container_ip : str , no_beats : bool ) -> None :
1256
1313
"""
@@ -1317,6 +1374,10 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1317
1374
start_snort_ids_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1318
1375
elif entity == "elkmanager" :
1319
1376
start_elk_manager (ip = ip , emulation = name , ip_first_octet = id )
1377
+ elif entity == "trafficmanagers" :
1378
+ start_traffic_managers (ip = ip , emulation = name , ip_first_octet = id )
1379
+ elif entity == "trafficmanager" :
1380
+ start_traffic_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1320
1381
else :
1321
1382
container_started = False
1322
1383
for node in config .cluster_config .cluster_nodes :
@@ -1515,6 +1576,34 @@ def start_host_managers(ip: str, emulation: str, ip_first_octet: int):
1515
1576
bold = False )
1516
1577
1517
1578
1579
+ def start_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1580
+ """
1581
+ Utility function for starting host manager
1582
+
1583
+ :param ip: the ip of the node to start host manager
1584
+ :param container_ip: the ip of the host to start
1585
+ :param emulation: the emulation of the execution
1586
+ :param ip_first_octet: the ID of the execution
1587
+ :return: None
1588
+ """
1589
+ import csle_common .constants .constants as constants
1590
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1591
+ config = MetastoreFacade .get_config (id = 1 )
1592
+ for node in config .cluster_config .cluster_nodes :
1593
+ if node .ip == ip or ip == "" :
1594
+ operation_outcome = ClusterController .start_host_manager (ip = ip ,
1595
+ port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1596
+ emulation = emulation , ip_first_octet = ip_first_octet ,
1597
+ container_ip = container_ip )
1598
+ if operation_outcome .outcome :
1599
+ click .secho (f"Started host manager with ip { container_ip } on "
1600
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1601
+ else :
1602
+ click .secho (f"Host manager with ip { container_ip } is not "
1603
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1604
+ bold = False )
1605
+
1606
+
1518
1607
def start_client_manager (ip : str , emulation : str , ip_first_octet : int ):
1519
1608
"""
1520
1609
Utility function for starting client manager
@@ -1558,34 +1647,6 @@ def start_client_manager(ip: str, emulation: str, ip_first_octet: int):
1558
1647
bold = False )
1559
1648
1560
1649
1561
- def start_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1562
- """
1563
- Utility function for starting host manager
1564
-
1565
- :param ip: the ip of the node to start host manager
1566
- :param container_ip: the ip of the host to start
1567
- :param emulation: the emulation of the execution
1568
- :param ip_first_octet: the ID of the execution
1569
- :return: None
1570
- """
1571
- import csle_common .constants .constants as constants
1572
- from csle_common .metastore .metastore_facade import MetastoreFacade
1573
- config = MetastoreFacade .get_config (id = 1 )
1574
- for node in config .cluster_config .cluster_nodes :
1575
- if node .ip == ip or ip == "" :
1576
- operation_outcome = ClusterController .start_host_manager (ip = ip ,
1577
- port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1578
- emulation = emulation , ip_first_octet = ip_first_octet ,
1579
- container_ip = container_ip )
1580
- if operation_outcome .outcome :
1581
- click .secho (f"Started host manager with ip { container_ip } on "
1582
- f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1583
- else :
1584
- click .secho (f"Host manager with ip { container_ip } is not "
1585
- f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1586
- bold = False )
1587
-
1588
-
1589
1650
def start_snort_ids_managers (ip : str , emulation : str , ip_first_octet : int ):
1590
1651
"""
1591
1652
Utility function for starting snort managers
@@ -1661,6 +1722,57 @@ def start_elk_manager(ip: str, emulation: str, ip_first_octet: int):
1661
1722
bold = False )
1662
1723
1663
1724
1725
+ def start_traffic_managers (ip : str , emulation : str , ip_first_octet : int ):
1726
+ """
1727
+ Utility function for starting traffic manager
1728
+
1729
+ :param ip: the ip of the node to start traffic manager
1730
+ :param emulation: the emulation of the execution
1731
+ :param ip_first_octet: the ID of the execution
1732
+ :return: None
1733
+ """
1734
+ import csle_common .constants .constants as constants
1735
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1736
+ config = MetastoreFacade .get_config (id = 1 )
1737
+ for node in config .cluster_config .cluster_nodes :
1738
+ if node .ip == ip or ip == "" :
1739
+ operation_outcome = ClusterController .start_traffic_managers (
1740
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1741
+ ip_first_octet = ip_first_octet )
1742
+ if operation_outcome .outcome :
1743
+ click .secho (f"Starting traffic managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1744
+ else :
1745
+ click .secho (f"Traffic managers are not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1746
+ bold = False )
1747
+
1748
+
1749
+ def start_traffic_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ):
1750
+ """
1751
+ Utility function for starting traffic manager
1752
+
1753
+ :param ip: the ip of the node to start traffic manager
1754
+ :param container_ip: the ip of the host to start
1755
+ :param emulation: the emulation of the execution
1756
+ :param ip_first_octet: the ID of the execution
1757
+ :return: None
1758
+ """
1759
+ import csle_common .constants .constants as constants
1760
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1761
+ config = MetastoreFacade .get_config (id = 1 )
1762
+ for node in config .cluster_config .cluster_nodes :
1763
+ if node .ip == ip or ip == "" :
1764
+ operation_outcome = ClusterController .start_traffic_manager (
1765
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
1766
+ ip_first_octet = ip_first_octet , container_ip = container_ip )
1767
+ if operation_outcome .outcome :
1768
+ click .secho (f"Started ttraffic manager with ip { container_ip } on "
1769
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1770
+ else :
1771
+ click .secho (f"Traffic manager with ip { container_ip } is not "
1772
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1773
+ bold = False )
1774
+
1775
+
1664
1776
def run_image (image : str , name : str , create_network : bool = True , version : str = "0.0.1" ) -> bool :
1665
1777
"""
1666
1778
Runs a container with a given image
@@ -1948,7 +2060,7 @@ def ls_shell_complete(ctx, param, incomplete) -> List[str]:
1948
2060
@click .command ("ls" , help = "containers | networks | images | emulations | all | environments | prometheus "
1949
2061
"| node_exporter | cadvisor | pgadmin | statsmanager | flask | "
1950
2062
"simulations | emulation_executions | cluster | nginx | postgresql | docker | hostmanagers | "
1951
- "clientmanager | snortmanagers | elkmanager" )
2063
+ "clientmanager | snortmanagers | elkmanager | trafficmanagers " )
1952
2064
@click .argument ('entity' , default = 'all' , type = str , shell_complete = ls_shell_complete )
1953
2065
@click .option ('--all' , is_flag = True , help = 'list all' )
1954
2066
@click .option ('--running' , is_flag = True , help = 'list running only (default)' )
@@ -2021,6 +2133,8 @@ def ls(entity: str, all: bool, running: bool, stopped: bool, ip: str, name: str,
2021
2133
list_snort_ids_managers (ip = ip , emulation = name , ip_first_octet = id )
2022
2134
elif entity == "elkmanager" :
2023
2135
list_elk_manager (ip = ip , emulation = name , ip_first_octet = id )
2136
+ elif entity == "trafficmanagers" :
2137
+ list_traffic_managers (ip = ip , emulation = name , ip_first_octet = id )
2024
2138
else :
2025
2139
container = get_running_container (name = entity )
2026
2140
if container is not None :
@@ -2091,6 +2205,40 @@ def list_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
2091
2205
click .secho ('+' + '-' * 50 + '+' , fg = 'white' )
2092
2206
2093
2207
2208
+ def list_traffic_managers (ip : str , emulation : str , ip_first_octet : int ) -> None :
2209
+ """
2210
+ Utility function for listing traffic managers
2211
+
2212
+ :param ip: the ip of the node to list host manager
2213
+ :param emulation: the emulation of the execution
2214
+ :param ip_first_octet: the ID of the execution
2215
+
2216
+ :return: None
2217
+ """
2218
+ import csle_common .constants .constants as constants
2219
+ from csle_common .metastore .metastore_facade import MetastoreFacade
2220
+ config = MetastoreFacade .get_config (id = 1 )
2221
+ for node in config .cluster_config .cluster_nodes :
2222
+ if node .ip == ip or ip == "" :
2223
+ traffic_manager_info = ClusterController .get_traffic_managers_info (
2224
+ ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT , emulation = emulation ,
2225
+ ip_first_octet = ip_first_octet )
2226
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2227
+ click .secho (f'|{ "Traffic manager IP" :^30} ' , nl = False , fg = 'white' )
2228
+ click .secho (f'|{ "Traffic manager status" :^29} ' , nl = False , fg = 'white' )
2229
+ click .secho ('|' , fg = 'white' )
2230
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2231
+ for i in range (len (traffic_manager_info .ips )):
2232
+ status_color = 'green' if traffic_manager_info .trafficManagersRunning [i ] else 'red'
2233
+ manager_status = 'Running' if traffic_manager_info .trafficManagersRunning [i ] else 'Stopped'
2234
+ click .secho ('|' , nl = False , fg = 'white' )
2235
+ click .secho (f'{ traffic_manager_info .ips [i ]:^30} ' , nl = False , fg = status_color )
2236
+ click .secho ('|' , nl = False , fg = 'white' )
2237
+ click .secho (f'{ manager_status :^29} ' , nl = False , fg = status_color )
2238
+ click .secho ('|' , fg = 'white' )
2239
+ click .secho ('+' + '-' * 60 + '+' , fg = 'white' )
2240
+
2241
+
2094
2242
def list_elk_manager (ip : str , emulation : str , ip_first_octet : int ) -> None :
2095
2243
"""
2096
2244
Utility function for listing elk manager
0 commit comments