@@ -678,13 +678,14 @@ def stop_shell_complete(ctx, param, incomplete) -> List[str]:
678
678
679
679
680
680
@click .option ('--ip' , default = "" , type = str )
681
+ @click .option ('--container_ip' , default = "" , type = str )
681
682
@click .argument ('id' , default = - 1 )
682
683
@click .argument ('name' , default = "" , type = str )
683
684
@click .argument ('entity' , default = "" , shell_complete = stop_shell_complete )
684
685
@click .command ("stop" , help = "prometheus | node_exporter | cadvisor | grafana | flask | container-name | "
685
686
"emulation-name | statsmanager | emulation_executions | pgadmin | all | nginx | postgresql "
686
- "| docker | clustermanager | hostmanagers" )
687
- def stop (entity : str , name : str , id : int = - 1 , ip : str = "" ) -> None :
687
+ "| docker | clustermanager | hostmanagers | hostmanager " )
688
+ def stop (entity : str , name : str , id : int = - 1 , ip : str = "" , container_ip : str = "" ) -> None :
688
689
"""
689
690
Stops an entity
690
691
@@ -729,6 +730,8 @@ def stop(entity: str, name: str, id: int = -1, ip: str = "") -> None:
729
730
stop_emulation_executions ()
730
731
elif entity == "hostmanagers" :
731
732
stop_host_managers (ip = ip , emulation = name , ip_first_octet = id )
733
+ elif entity == "hostmanager" :
734
+ stop_host_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
732
735
else :
733
736
container_stopped = False
734
737
for node in config .cluster_config .cluster_nodes :
@@ -923,6 +926,32 @@ def stop_host_managers(ip: str, emulation: str, ip_first_octet: int) -> None:
923
926
bold = False )
924
927
925
928
929
+ def stop_host_manager (ip : str , container_ip : str , emulation : str , ip_first_octet : int ) -> None :
930
+ """
931
+ Utility function for stopping the Docker statsmanager
932
+
933
+ :param ip: the ip of the node to stop the Docker statsmanager
934
+ :param container_ip: the ip of the host to be stopped
935
+ :param emulation: the emulation of the execution
936
+ :param ip_first_octet: the ID of the execution
937
+ :return: None
938
+ """
939
+ import csle_common .constants .constants as constants
940
+ from csle_common .metastore .metastore_facade import MetastoreFacade
941
+ config = MetastoreFacade .get_config (id = 1 )
942
+ for node in config .cluster_config .cluster_nodes :
943
+ if node .ip == ip or ip == "" :
944
+ stopped = ClusterController .stop_host_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
945
+ emulation = emulation , ip_first_octet = ip_first_octet ,
946
+ container_ip = container_ip )
947
+ if stopped :
948
+ click .secho (f"Stopping host with ip { container_ip } on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
949
+ else :
950
+ click .secho (f"Host with ip { container_ip } is not "
951
+ f"stopped:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
952
+ bold = False )
953
+
954
+
926
955
@click .argument ('max_workers' , default = 10 , type = int )
927
956
@click .argument ('log_file' , default = "docker_statsmanager.log" , type = str )
928
957
@click .argument ('log_dir' , default = "/var/log/csle" , type = str )
@@ -1103,6 +1132,7 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1103
1132
1104
1133
1105
1134
@click .option ('--ip' , default = "" , type = str )
1135
+ @click .option ('--container_ip' , default = "" , type = str )
1106
1136
@click .option ('--id' , default = None , type = int )
1107
1137
@click .option ('--no_clients' , is_flag = True , help = 'skip starting the client population' )
1108
1138
@click .option ('--no_traffic' , is_flag = True , help = 'skip starting the traffic generators' )
@@ -1112,9 +1142,10 @@ def start_shell_complete(ctx, param, incomplete) -> List[str]:
1112
1142
@click .argument ('entity' , default = "" , type = str , shell_complete = start_shell_complete )
1113
1143
@click .command ("start" , help = "prometheus | node_exporter | grafana | cadvisor | flask | pgadmin | "
1114
1144
"container-name | emulation-name | all | statsmanager | training_job "
1115
- "| system_id_job | nginx | postgresql | docker | clustermanager | hostmanager" )
1145
+ "| system_id_job | nginx | postgresql | docker | clustermanager | hostmanagers "
1146
+ "| hostmanager" )
1116
1147
def start (entity : str , no_traffic : bool , name : str , id : int , no_clients : bool , no_network : bool , ip : str ,
1117
- no_beats : bool ) -> None :
1148
+ container_ip : str , no_beats : bool ) -> None :
1118
1149
"""
1119
1150
Starts an entity, e.g., a container or the management system
1120
1151
@@ -1126,6 +1157,7 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1126
1157
:param no_network: a boolean parameter that is True if the network should be skipped when creating a container
1127
1158
:param id: (optional) an id parameter to identify the entity to start
1128
1159
:param ip: ip when stopping a service on a specific physical server (empty ip means all servers)
1160
+ :param container_ip: ip of the host to be started
1129
1161
:return: None
1130
1162
"""
1131
1163
from csle_agents .job_controllers .training_job_manager import TrainingJobManager
@@ -1166,8 +1198,10 @@ def start(entity: str, no_traffic: bool, name: str, id: int, no_clients: bool, n
1166
1198
data_collection_job = system_id_job )
1167
1199
elif entity == "flask" :
1168
1200
start_flask (ip = ip )
1201
+ elif entity == "hostmanagers" :
1202
+ start_host_managers (ip = ip , emulation = name , ip_first_octet = id )
1169
1203
elif entity == "hostmanager" :
1170
- start_host_manager (ip = ip , emulation = name , ip_first_octet = id )
1204
+ start_host_manager (ip = ip , container_ip = container_ip , emulation = name , ip_first_octet = id )
1171
1205
else :
1172
1206
container_started = False
1173
1207
for node in config .cluster_config .cluster_nodes :
@@ -1341,7 +1375,7 @@ def start_statsmanager(ip: str) -> None:
1341
1375
ClusterController .start_docker_statsmanager (ip = node .ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT )
1342
1376
1343
1377
1344
- def start_host_manager (ip : str , emulation : str , ip_first_octet : int ):
1378
+ def start_host_managers (ip : str , emulation : str , ip_first_octet : int ):
1345
1379
"""
1346
1380
Utility function for starting host manager
1347
1381
@@ -1355,9 +1389,41 @@ def start_host_manager(ip: str, emulation: str, ip_first_octet: int):
1355
1389
config = MetastoreFacade .get_config (id = 1 )
1356
1390
for node in config .cluster_config .cluster_nodes :
1357
1391
if node .ip == ip or ip == "" :
1358
- ClusterController .start_host_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1392
+ started = ClusterController .start_host_managers (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1359
1393
emulation = emulation , ip_first_octet = ip_first_octet )
1360
1394
1395
+ if started :
1396
+ click .secho (f"Starting host managers on port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1397
+ else :
1398
+ click .secho (f"Host managers are not started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1399
+ bold = False )
1400
+
1401
+ def start_host_manager (ip : str , container_ip :str , emulation : str , ip_first_octet : int ):
1402
+ """
1403
+ Utility function for starting host manager
1404
+
1405
+ :param ip: the ip of the node to start host manager
1406
+ :param container_ip: the ip of the host to start
1407
+ :param emulation: the emulation of the execution
1408
+ :param ip_first_octet: the ID of the execution
1409
+ :return: None
1410
+ """
1411
+ import csle_common .constants .constants as constants
1412
+ from csle_common .metastore .metastore_facade import MetastoreFacade
1413
+ config = MetastoreFacade .get_config (id = 1 )
1414
+ for node in config .cluster_config .cluster_nodes :
1415
+ if node .ip == ip or ip == "" :
1416
+ started = ClusterController .start_host_manager (ip = ip , port = constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT ,
1417
+ emulation = emulation , ip_first_octet = ip_first_octet ,
1418
+ container_ip = container_ip )
1419
+ if started :
1420
+ click .secho (f"Starting host with ip { container_ip } on "
1421
+ f"port:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " )
1422
+ else :
1423
+ click .secho (f"Host with ip { container_ip } is not "
1424
+ f"started:{ constants .GRPC_SERVERS .CLUSTER_MANAGER_PORT } " ,
1425
+ bold = False )
1426
+
1361
1427
1362
1428
def run_image (image : str , name : str , create_network : bool = True , version : str = "0.0.1" ) -> bool :
1363
1429
"""
0 commit comments