@@ -180,13 +180,7 @@ def check(
180180 )
181181 return True
182182
183- def update_blueprint (
184- self ,
185- project_name : str = "" ,
186- launch_type : str = "test" ,
187- dry_run : bool = False ,
188- machine_list = None ,
189- ) -> bool :
183+ def update_blueprint (self , project_name : str = "" , dry_run : bool = False ) -> bool :
190184 """Update the blueprint associated with the specified machines."""
191185 print ("Updating the CloudEndure Blueprints..." )
192186
@@ -199,38 +193,54 @@ def update_blueprint(
199193 if not project_id :
200194 return False
201195
196+ machine_list = {}
197+ machines_response = self .api .api_call (f"projects/{ project_id } /machines" )
198+ for machine in json .loads (machines_response .text ).get ("items" , []):
199+ source_props : Dict [str , Any ] = machine .get ("sourceProperties" , {})
200+ machine_id : str = machine .get ("id" )
201+ machine_name : str = source_props .get ("name" )
202+ if machine_name in _machines or machine_name .upper () in _machines :
203+ machine_list [machine_id ] = machine_name
204+
205+ if not machine_list :
206+ print ("No Machines Found!" )
207+ return False
208+
202209 try :
203210 blueprints_response = self .api .api_call (f"projects/{ project_id } /blueprints" )
204211 for blueprint in json .loads (blueprints_response .text ).get ("items" , []):
205212 _machine_id = blueprint .get ("machineId" )
206- _machine_name = machine_list [_machine_id ]
213+ _machine_name = machine_list .get (_machine_id )
214+ if not _machine_name :
215+ continue
216+
207217 _blueprint_id = blueprint .get ("id" , "" )
208218 _endpoint = f"projects/{ project_id } /blueprints/{ _blueprint_id } "
219+ # Handle disk blueprints since we don't want provisioned IOPS $$$$
220+ for disk in blueprint ["disks" ]:
221+ blueprint ["disks" ] = [{"type" : "SSD" , "name" : disk .get ("name" , "" )}]
222+
223+ # Update machine tags
224+ blueprint ["tags" ] = [
225+ {"key" : "CloneStatus" , "value" : CLONE_STATUS },
226+ {"key" : "MigrationWave" , "value" : MIGRATION_WAVE },
227+ ]
209228
210- for _machine in _machines :
211- if _machine_name == _machine :
212- # Handle disk blueprints since we don't want provisioned IOPS $$$$
213- for disk in blueprint ["disks" ]:
214- blueprint ["disks" ] = [
215- {"type" : "SSD" , "name" : disk .get ("name" , "" )}
216- ]
217-
218- # Update machine tags
219- blueprint ["tags" ] = {
220- "CloneStatus" : CLONE_STATUS ,
221- "MigrationWave" : MIGRATION_WAVE ,
222- }
229+ if dry_run :
230+ print ("This is a dry run! Not launching any machines!" )
231+ return True
223232
224- result = self .api .api_call (
225- _endpoint , method = "patch" , data = json .dumps (blueprint )
226- )
233+ result = self .api .api_call (
234+ _endpoint , method = "patch" , data = json .dumps (blueprint )
235+ )
227236
228- if result .status_code != 200 :
229- print (
230- "Blueprint update failure encountered for machine:" ,
231- f"({ _machine_name } ) - fix blueprint settings!" ,
232- )
233- print ("Blueprint for machine: " + _machine_name + " updated!" )
237+ if result .status_code != 200 :
238+ print (
239+ "Blueprint update failure encountered for machine:" ,
240+ f"({ _machine_name } ) - { result .status_code } fix blueprint settings!" ,
241+ )
242+ else :
243+ print ("Blueprint for machine: " + _machine_name + " updated!" )
234244 except Exception as e :
235245 print (f"Updating blueprint task failed! { e } " )
236246 return False
@@ -588,7 +598,7 @@ def copy_image(self, image_id: str, kms_id: str):
588598 print (new_image )
589599 return new_image ["ImageId" ]
590600
591- def split_image (self , image_id : str ):
601+ def split_image (self , image_id : str , root_name : str = "root_image" ):
592602 """Split the image into a root drive only AMI and a collection of snapshots."""
593603 print ("Loading EC2 client for region: " , AWS_REGION )
594604 _ec2_res = boto3 .resource ("ec2" , AWS_REGION )
@@ -614,11 +624,11 @@ def split_image(self, image_id: str):
614624
615625 # create a new AMI with only the root
616626 response = _ec2_res .register_image (
617- Architecture = "x86_64" ,
627+ Architecture = image . architecture ,
618628 BlockDeviceMappings = [root_drive ],
619- Name = "test_split" ,
629+ Name = root_name ,
620630 RootDeviceName = image .root_device_name ,
621- VirtualizationType = "hvm" ,
631+ VirtualizationType = image . virtualization_type ,
622632 )
623633
624634 # return the AMI
0 commit comments