@@ -715,6 +715,38 @@ def execute(self) -> bool:
715715 print (str (e ))
716716 return False
717717
718+ def replication (self , action : str , machine_ids : str = "" ) -> bool :
719+ """Handle replication actions."""
720+ print (f"{ action .title ()} Machine Replication: ({ machine_ids } )" )
721+ action : str = action .lower ()
722+ _machines : List [str ] = machine_ids .split ("," )
723+
724+ if not _machines :
725+ _machines = self .target_machines
726+ print (
727+ f"No machines provided. Defaulting to project machines: ({ _machines } )"
728+ )
729+
730+ replication_data : Dict [str , Any ] = {"machineId" : _machines }
731+ if action not in ["pause" , "stop" , "start" ]:
732+ return False
733+
734+ replication_results : Response = self .api .api_call (
735+ f"projects/{ self .project_id } /{ action } Replication" ,
736+ method = "post" ,
737+ data = replication_data ,
738+ )
739+
740+ if replication_results .status_code != 200 :
741+ print (
742+ f"Failed to update the machine(s) replication status to: ({ action } ) for ({ machine_ids } ): "
743+ f"{ replication_results .status_code } { replication_results .content } "
744+ )
745+ print (replication_results .text )
746+ return False
747+ print ("Project was updated successfully" )
748+ return True
749+
718750 def share_image (self , image_id : str , image_name : str = "CloudEndureImage" ) -> bool :
719751 """Share the generated AMIs to the provided destination account."""
720752 print ("Loading EC2 client for region: " , AWS_REGION )
0 commit comments