2424headers : Dict [str , str ] = {"Content-Type" : "application/json" }
2525session : Dict [str , str ] = {}
2626AWS_REGION : str = os .environ .get ("AWS_REGION" , "" )
27- LAUNCH_TYPES : List [str ] = ["test" , "cutover" ]
2827
2928
3029class CloudEndure :
@@ -94,7 +93,7 @@ def get_project_id(self, project_name: str = "") -> str:
9493 return ""
9594
9695 def check (
97- self , project_name : str = "" , launch_type : str = "test" , dry_run : bool = False
96+ self , project_name : str = "" , dry_run : bool = False
9897 ) -> bool :
9998 """Check the status of machines in the provided project."""
10099 if not project_name :
@@ -107,7 +106,7 @@ def check(
107106 return False
108107
109108 print (
110- f"Checking Project - Name: ({ project_name } ) - Launch Type: ( { launch_type } ) - Dry Run: ({ dry_run } )"
109+ f"Checking Project - Name: ({ project_name } ) - Dry Run: ({ dry_run } )"
111110 )
112111 projects_response : Response = self .api .api_call ("projects" )
113112
@@ -137,48 +136,27 @@ def check(
137136 f"{ ref_name } replication into the migration account in progress!"
138137 )
139138 else :
140- if launch_type == "test" :
141- if machine .get ("replica" ):
142- machine_status += 1
143- print (
144- f"{ ref_name } has been launched in the migration account"
145- )
146- else :
147- print (
148- f"{ ref_name } has not completed launching in the migration account - Please wait..."
149- )
150- elif launch_type == "cutover" :
151- if machine .get ("replica" ):
152- machine_status += 1
153- print (
154- f"{ ref_name } has been cutover into the migration account"
155- )
156- else :
157- print (
158- f"{ ref_name } has NOT been cutover into the migration account"
159- )
139+ if machine .get ("replica" ):
140+ machine_status += 1
141+ print (
142+ f"{ ref_name } has been launched in the migration account"
143+ )
144+ else :
145+ print (
146+ f"{ ref_name } has not completed launching in the migration account - Please wait..."
147+ )
160148
161149 if not machine_exist :
162150 print (f"ERROR: Machine: { _machine } does not exist!" )
163151
164152 if machine_status == len (self .target_machines ):
165- if launch_type == "test" :
166- print (
167- "All machines specified in CLOUDENDURE_MACHINES have been launched in the migration account"
168- )
169- if launch_type == "cutover" :
170- print (
171- "All machines specified in CLOUDENDURE_MACHINES have been cutover to the target account"
172- )
153+ print (
154+ "All machines specified in CLOUDENDURE_MACHINES have been launched in the migration account"
155+ )
173156 else :
174- if launch_type == "test" :
175- print (
176- "Some machines have not yet completed launching in the migration account"
177- )
178- if launch_type == "cutover" :
179- print (
180- "Some machines have not yet completed cutting over into the migration account"
181- )
157+ print (
158+ "Some machines have not yet completed launching in the migration account"
159+ )
182160 return True
183161
184162 def update_encryption_key (
@@ -321,7 +299,7 @@ def update_blueprint(self, project_name: str = "", dry_run: bool = False) -> boo
321299 return True
322300
323301 def launch (
324- self , project_name = "" , launch_type = "test" , dry_run = False
302+ self , project_name = "" , dry_run = False
325303 ) -> Dict [str , Any ]:
326304 """Launch the test target instances."""
327305 response_dict : Dict [str , Any ] = {}
@@ -335,20 +313,12 @@ def launch(
335313 return response_dict
336314
337315 print (
338- f"Launching Project - Project ID: ({ project_id } ) - " ,
339- f"Launch Type: ({ launch_type } ) - Dry Run: ({ dry_run } )" ,
316+ f"Launching Project - Project ID: ({ project_id } ) - Dry Run: ({ dry_run } )" ,
340317 )
341318 if dry_run :
342319 print ("This is a dry run! Not launching any machines!" )
343320 return response_dict
344321
345- if launch_type not in LAUNCH_TYPES :
346- print (
347- "Invalid launch-type specified! Please specify a valid launch type: " ,
348- LAUNCH_TYPES ,
349- )
350- return response_dict
351-
352322 machines_response : Response = self .api .api_call (
353323 f"projects/{ project_id } /machines"
354324 )
@@ -363,16 +333,10 @@ def launch(
363333 Event .EVENT_ALREADY_LAUNCHED , machine_name = _machine
364334 )
365335 continue
366- if launch_type == "test" :
367- machine_data = {
368- "items" : [{"machineId" : machine ["id" ]}],
369- "launchType" : "TEST" ,
370- }
371- elif launch_type == "cutover" :
372- machine_data = {
373- "items" : [{"machineId" : machine ["id" ]}],
374- "launchType" : "CUTOVER" ,
375- }
336+ machine_data = {
337+ "items" : [{"machineId" : machine ["id" ]}],
338+ "launchType" : "TEST" ,
339+ }
376340
377341 if machine_data :
378342 result : Response = self .api .api_call (
@@ -385,16 +349,10 @@ def launch(
385349 "machineCloudId" , "NONE"
386350 )
387351 response_dict .update (json .loads (result .text ))
388- if launch_type == "test" :
389- print ("Test Job created for machine " , _machine )
390- self .event_handler .add_event (
391- Event .EVENT_SUCCESSFULLY_LAUNCHED , machine_name = _machine
392- )
393- elif launch_type == "cutover" :
394- print ("Cutover Job created for machine " , _machine )
395- self .event_handler .add_event (
396- Event .EVENT_SUCCESSFULLY_CUTOVER , machine_name = _machine
397- )
352+ print ("Test Job created for machine " , _machine )
353+ self .event_handler .add_event (
354+ Event .EVENT_SUCCESSFULLY_LAUNCHED , machine_name = _machine
355+ )
398356 elif result .status_code == 409 :
399357 print (f"ERROR: ({ _machine } ) is currently in progress!" )
400358 self .event_handler .add_event (
@@ -420,7 +378,7 @@ def launch(
420378 return response_dict
421379
422380 def status (
423- self , project_name : str = "" , launch_type : str = "test" , dry_run : bool = False
381+ self , project_name : str = "" , dry_run : bool = False
424382 ) -> bool :
425383 """Get the status of machines in the current wave."""
426384 if not project_name :
@@ -434,7 +392,7 @@ def status(
434392
435393 print (
436394 f"Getting Status of Project - Project ID: ({ project_id } ) -" ,
437- f"Launch Type: ( { launch_type } ) - Dry Run: ({ dry_run } )" ,
395+ f"Dry Run: ({ dry_run } )" ,
438396 )
439397 machine_status : int = 0
440398 machines_response : Response = self .api .api_call (
@@ -487,39 +445,16 @@ def status(
487445 _m_life_cycle : Dict [str , Any ] = machine .get (
488446 "lifeCycle" , {}
489447 )
490- if launch_type == "test" :
491- if (
492- "lastTestLaunchDateTime" not in _m_life_cycle
493- and "lastCutoverDateTime" not in _m_life_cycle
494- ):
495- machine_status += 1
496- else :
497- print (
498- f"{ ref_name } has already been tested - you can create AMIs now!"
499- )
500- return False
501- # Check if the target machine has been migrated to PROD already
502- elif launch_type == "cutover" :
503- if "lastTestLaunchDateTime" in machine ["lifeCycle" ]:
504- if (
505- "lastCutoverDateTime"
506- not in machine ["lifeCycle" ]
507- ):
508- machine_status += 1
509- else :
510- print (
511- "ERROR: Machine: "
512- + ref_name
513- + " has been migrated already"
514- )
515- return False
516- else :
517- print (
518- "ERROR: Machine: "
519- + ref_name
520- + " has not been tested"
521- )
522- return False
448+ if (
449+ "lastTestLaunchDateTime" not in _m_life_cycle
450+ and "lastCutoverDateTime" not in _m_life_cycle
451+ ):
452+ machine_status += 1
453+ else :
454+ print (
455+ f"{ ref_name } has already been tested - you can create AMIs now!"
456+ )
457+ return False
523458 if not machine_exist :
524459 print ("ERROR: Machine: " + _machine + " does not exist!" )
525460 return False
@@ -531,7 +466,7 @@ def status(
531466 return False
532467
533468 def execute (
534- self , project_name : str = "" , launch_type : str = "test" , dry_run : bool = False
469+ self , project_name : str = "" , dry_run : bool = False
535470 ) -> bool :
536471 """Start the migration project my checking and launching the migration wave."""
537472 if not project_name :
@@ -544,7 +479,7 @@ def execute(
544479 return False
545480
546481 print (
547- f"Executing Project - Name: ({ project_name } ) - Launch Type: ( { launch_type } ) - Dry Run: ({ dry_run } )"
482+ f"Executing Project - Name: ({ project_name } ) - Dry Run: ({ dry_run } )"
548483 )
549484
550485 projects_result : Response = self .api .api_call ("projects" )
@@ -582,7 +517,7 @@ def execute(
582517 # Launch Target machines
583518 if not dry_run :
584519 print ("Launching target machines..." )
585- self .launch (launch_type = launch_type , dry_run = dry_run )
520+ self .launch (dry_run = dry_run )
586521 except Exception as e :
587522 print (str (e ))
588523 return False
0 commit comments